Java Code Examples for javax.lang.model.util.ElementFilter#methodsIn()
The following examples show how to use
javax.lang.model.util.ElementFilter#methodsIn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntroduceLocalExtensionTransformer.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean accept(CompilationInfo info, TypeMirror tm) { if (!super.accept(info, tm)) { return false; } TypeElement clazz = info.getElements().getTypeElement(fqn); if (clazz == null) { return false; } for (ExecutableElement m : ElementFilter.methodsIn(clazz.getEnclosedElements())) { if (m.getSimpleName().contentEquals(methodName)) { return true; } } return false; }
Example 2
Source File: WebServiceVisitor.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected boolean hasWebMethods(TypeElement element) { if (element.getQualifiedName().toString().equals(Object.class.getName())) return false; WebMethod webMethod; for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) { webMethod = method.getAnnotation(WebMethod.class); if (webMethod != null) { if (webMethod.exclude()) { if (webMethod.operationName().length() > 0) builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE( "operationName", element.getQualifiedName(), method.toString()), method); if (webMethod.action().length() > 0) builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE( "action", element.getQualifiedName(), method.toString()), method); } else { return true; } } } return false;//hasWebMethods(d.getSuperclass().getDeclaration()); }
Example 3
Source File: TypeModeler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static TypeElement getDeclaringClassMethod(TypeElement theClass, String methodName, TypeMirror[] args) { TypeElement retClass = null; if (theClass.getKind().equals(ElementKind.CLASS)) { TypeMirror superClass = theClass.getSuperclass(); if (!superClass.getKind().equals(TypeKind.NONE)) retClass = getDeclaringClassMethod(superClass, methodName, args); } if (retClass == null) { for (TypeMirror interfaceType : theClass.getInterfaces()) { retClass = getDeclaringClassMethod(interfaceType, methodName, args); } } if (retClass == null) { Collection<? extends ExecutableElement> methods = ElementFilter.methodsIn(theClass.getEnclosedElements()); for (ExecutableElement method : methods) { if (method.getSimpleName().toString().equals(methodName)) { retClass = theClass; break; } } } return retClass; }
Example 4
Source File: JUnit3TestGenerator.java From netbeans with Apache License 2.0 | 6 votes |
/** * Finds whether the given {@code TypeElement} or any of its type * ancestor contains an accessible static no-arg method * of the given name. * * @param typeElement {@code TypeElement} to search * @param methodName name of the method to be found * @param elements support instance to be used for the search * @return {@code true} if the given {@code TypeElement} contains, * whether inherited or declared directly, * a static no-argument method of the given name, * {@code false} otherwise */ private boolean containsSuiteMethod(TypeElement typeElement, Elements elements, Types types, TypeMirror testType) { List<ExecutableElement> allMethods = ElementFilter.methodsIn(elements.getAllMembers(typeElement)); for (ExecutableElement method : allMethods) { if (method.getSimpleName().contentEquals("suite") //NOI18N && method.getParameters().isEmpty()) { return method.getModifiers().contains(Modifier.STATIC) && types.isSameType(method.getReturnType(), testType); } } return false; }
Example 5
Source File: JavahTask.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void checkMethodParameters(Set<TypeElement> classes) { Types types = processingEnv.getTypeUtils(); for (TypeElement te: classes) { for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) { for (VariableElement ve: ee.getParameters()) { TypeMirror tm = ve.asType(); checkMethodParametersVisitor.visit(tm, types); } } } }
Example 6
Source File: WebServiceVisitor.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected void verifyImplAnnotations(TypeElement d) { for (ExecutableElement method : ElementFilter.methodsIn(d.getEnclosedElements())) { checkForInvalidImplAnnotation(method, WebMethod.class); checkForInvalidImplAnnotation(method, Oneway.class); checkForInvalidImplAnnotation(method, WebResult.class); for (VariableElement param : method.getParameters()) { checkForInvalidImplAnnotation(param, WebParam.class); } } }
Example 7
Source File: InterceptorBindingMembersAnalyzer.java From netbeans with Apache License 2.0 | 5 votes |
protected void checkMembers( TypeElement element, CdiAnalysisResult result , String localizedWarning ) { List<ExecutableElement> methods = ElementFilter.methodsIn( element.getEnclosedElements()); for (ExecutableElement executableElement : methods) { TypeMirror returnType = executableElement.getReturnType(); boolean warning = false; if ( returnType.getKind() == TypeKind.ARRAY ){ warning = true; } else if ( returnType.getKind() == TypeKind.DECLARED){ Element returnElement = result.getInfo().getTypes().asElement( returnType ); warning = returnElement.getKind() == ElementKind.ANNOTATION_TYPE; } if ( !warning ){ continue; } if (AnnotationUtil.hasAnnotation(executableElement, AnnotationUtil.NON_BINDING, result.getInfo()) ) { continue; } result.addNotification(Severity.WARNING, element, localizedWarning); } }
Example 8
Source File: HandlerMethodCompleter.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<? extends CompletionItem> complete() { // attempt to find methods in the controller TypeElement el = controller.resolve(ctx.getCompilationInfo()); TypeElement eventType = event.getEventType().resolve(ctx.getCompilationInfo()); if (el == null || eventType == null) { return null; } List<ExecutableElement> allMethods = ElementFilter.methodsIn(ctx.getCompilationInfo().getElements().getAllMembers(el)); List<CompletionItem> items = new ArrayList<CompletionItem>(); for (ExecutableElement em : allMethods) { if (!FxClassUtils.isFxmlAccessible(em)) { continue; } if (em.getParameters().size() > 1 || em.getReturnType().getKind() != TypeKind.VOID) { continue; } if (!em.getParameters().isEmpty()) { VariableElement v = em.getParameters().get(0); if (!ctx.getCompilationInfo().getTypes().isAssignable(v.asType(), eventType.asType())) { continue; } } else if (!FxClassUtils.isFxmlAnnotated(em)) { // require FXML annotation, there are many void no-arg methods. continue; } items.add(new ValueItem(ctx, em.getSimpleName().toString(), "#", ICON_RESOURCE)); } return items; }
Example 9
Source File: WebServiceVisitor.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static List<ExecutableElement> getClassMethods(TypeElement classElement) { if (classElement.getQualifiedName().toString().equals(Object.class.getName())) // we don't need Object's methods return null; TypeElement superclassElement = (TypeElement) ((DeclaredType) classElement.getSuperclass()).asElement(); List<ExecutableElement> superclassesMethods = getClassMethods(superclassElement); List<ExecutableElement> classMethods = ElementFilter.methodsIn(classElement.getEnclosedElements()); if (superclassesMethods == null) return classMethods; else superclassesMethods.addAll(classMethods); return superclassesMethods; }
Example 10
Source File: ElementTo.java From sundrio with Apache License 2.0 | 5 votes |
public Set<ExecutableElement> getInheritedMethods(TypeElement typeElement) { Set<ExecutableElement> result = new LinkedHashSet<ExecutableElement>(); if (typeElement != null) { for (ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { if (!method.getModifiers().contains(Modifier.PRIVATE)) { result.add(method); } } result.addAll(getInheritedMethods(typeElement.getSuperclass() != null ? CodegenContext.getContext().getElements().getTypeElement(typeElement.getSuperclass().toString()) : null)); } return result; }
Example 11
Source File: JavahTask.java From hottub with GNU General Public License v2.0 | 5 votes |
private void checkMethodParameters(Set<TypeElement> classes) { Types types = processingEnv.getTypeUtils(); for (TypeElement te: classes) { for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) { for (VariableElement ve: ee.getParameters()) { TypeMirror tm = ve.asType(); checkMethodParametersVisitor.visit(tm, types); } } } }
Example 12
Source File: JavaSourceParserUtil.java From jeddict with Apache License 2.0 | 5 votes |
public static List<String> getExceptionsThrown(WorkingCopy workingCopy, String fqClass, String methodName, List<String> formalParamFqTypes) { if (formalParamFqTypes == null) { formalParamFqTypes = Collections.<String>emptyList(); } ExecutableElement desiredMethodElement = null; TypeElement suppliedTypeElement = workingCopy.getElements().getTypeElement(fqClass); TypeElement typeElement = suppliedTypeElement; whileloop: while (typeElement != null) { for (ExecutableElement methodElement : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { if (methodElement.getSimpleName().contentEquals(methodName)) { List<? extends VariableElement> formalParamElements = methodElement.getParameters(); //for now, just check sizes if (formalParamElements.size() == formalParamFqTypes.size()) { desiredMethodElement = methodElement; break whileloop; } } } typeElement = getSuperclassTypeElement(typeElement); } if (desiredMethodElement == null) { throw new IllegalArgumentException("Could not find " + methodName + " in " + fqClass); } List<String> result = new ArrayList<>(); List<? extends TypeMirror> thrownTypes = desiredMethodElement.getThrownTypes(); for (TypeMirror thrownType : thrownTypes) { if (thrownType.getKind() == TypeKind.DECLARED) { DeclaredType thrownDeclaredType = (DeclaredType) thrownType; TypeElement thrownElement = (TypeElement) thrownDeclaredType.asElement(); String thrownFqClass = thrownElement.getQualifiedName().toString(); result.add(thrownFqClass); } else { result.add(null); } } return result; }
Example 13
Source File: LLNI.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected void write(OutputStream o, TypeElement clazz) throws Util.Exit { try { String cname = mangleClassName(clazz.getQualifiedName().toString()); PrintWriter pw = wrapWriter(o); fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); methods = ElementFilter.methodsIn(clazz.getEnclosedElements()); generateDeclsForClass(pw, clazz, cname); // FIXME check if errors occurred on the PrintWriter and throw exception if so } catch (TypeSignature.SignatureException e) { util.error("llni.sigerror", e.getMessage()); } }
Example 14
Source File: JavahTask.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void checkMethodParameters(Set<TypeElement> classes) { Types types = processingEnv.getTypeUtils(); for (TypeElement te: classes) { for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) { for (VariableElement ve: ee.getParameters()) { TypeMirror tm = ve.asType(); checkMethodParametersVisitor.visit(tm, types); } } } }
Example 15
Source File: EventInjectionPointLogic.java From netbeans with Apache License 2.0 | 5 votes |
private List<ObserverTriple> findObservesParameters() { List<ObserverTriple> result = new LinkedList<ObserverTriple>(); CompilationController compilationController = getModel().getHelper().getCompilationController(); TypeElement observesType = compilationController.getElements().getTypeElement( OBSERVES_ANNOTATION); if ( observesType == null ){ return result; } ElementHandle<TypeElement> observesHandle = ElementHandle.create(observesType); final Set<ElementHandle<TypeElement>> elementHandles = compilationController. getClasspathInfo().getClassIndex().getElements( observesHandle, EnumSet.of(SearchKind.TYPE_REFERENCES), EnumSet.of(SearchScope.SOURCE, SearchScope.DEPENDENCIES)); for (ElementHandle<TypeElement> elementHandle : elementHandles) { TypeElement resolvedType = elementHandle.resolve( compilationController); List<? extends Element> enclosedElements = resolvedType. getEnclosedElements(); List<ExecutableElement> methods = ElementFilter.methodsIn( enclosedElements); for (ExecutableElement method : methods) { List<? extends VariableElement> parameters = method.getParameters(); int index = 0; for (VariableElement parameter : parameters) { List<? extends AnnotationMirror> annotationMirrors = compilationController.getElements(). getAllAnnotationMirrors( parameter); if ( getModel().getHelper().hasAnnotation( annotationMirrors, OBSERVES_ANNOTATION) ){ result.add( new ObserverTriple( method, parameter, index) ); } index++; } } } return result; }
Example 16
Source File: InterceptedBeanAnalyzer.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void analyze( TypeElement element, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { if ( AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR, model.getCompilationController() )) { result.requireCdiEnabled(element, model); // rule should not be applied to interceptor return ; } boolean hasIBindings = hasInterceptorBindings(element, model); if ( hasIBindings ){ result.requireCdiEnabled(element, model); EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance(result); ElementHandle<TypeElement> handle = ElementHandle.create(element); if ( helper != null ){ helper.addInterceptedBean( result , handle.resolve( result.getInfo())); } } Set<Modifier> modifiers = element.getModifiers(); boolean isFinal = modifiers.contains(Modifier.FINAL); List<ExecutableElement> methods = ElementFilter.methodsIn( element.getEnclosedElements()); ExecutableElement badMethod = null; for (ExecutableElement method : methods) { if ( cancel.get() ){ return; } modifiers = method.getModifiers(); if ( !modifiers.contains( Modifier.FINAL )){ continue; } if ( modifiers.contains( Modifier.STATIC ) || modifiers.contains( Modifier.PRIVATE)) { continue; } badMethod = method; break; } if ( badMethod == null && !isFinal ){ return; } if ( cancel.get() ){ return; } if (hasIBindings && isFinal) { result.addError(element, model, NbBundle.getMessage( InterceptedBeanAnalyzer.class, "ERR_FinalInterceptedBean")); // NOI18N } if (hasIBindings && badMethod != null) { result.addError(element, model, NbBundle.getMessage( InterceptedBeanAnalyzer.class, "ERR_InterceptedBeanHasFinalMethod", badMethod .getSimpleName().toString())); // NOI18N } }
Example 17
Source File: JNIWriter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected void writeMethods(Writer out, ClassSymbol sym, String cname) throws IOException, TypeSignature.SignatureException { List<ExecutableElement> classmethods = ElementFilter.methodsIn(sym.getEnclosedElements()); for (ExecutableElement md: classmethods) { if(md.getModifiers().contains(Modifier.NATIVE)){ TypeMirror mtr = types.erasure(md.getReturnType()); String sig = signature(md); TypeSignature newtypesig = new TypeSignature(elements); CharSequence methodName = md.getSimpleName(); boolean longName = false; for (ExecutableElement md2: classmethods) { if ((md2 != md) && (methodName.equals(md2.getSimpleName())) && (md2.getModifiers().contains(Modifier.NATIVE))) longName = true; } println(out, "/*"); println(out, " * Class: " + cname); println(out, " * Method: " + mangler.mangle(methodName, Mangle.Type.FIELDSTUB)); println(out, " * Signature: " + newtypesig.getTypeSignature(sig, mtr)); println(out, " */"); println(out, "JNIEXPORT " + jniType(mtr) + " JNICALL " + mangler.mangleMethod(md, sym, (longName) ? Mangle.Type.METHOD_JNI_LONG : Mangle.Type.METHOD_JNI_SHORT)); print(out, " (JNIEnv *, "); List<? extends VariableElement> paramargs = md.getParameters(); List<TypeMirror> args = new ArrayList<TypeMirror>(); for (VariableElement p: paramargs) { args.add(types.erasure(p.asType())); } if (md.getModifiers().contains(Modifier.STATIC)) print(out, "jclass"); else print(out, "jobject"); for (TypeMirror arg: args) { print(out, ", "); print(out, jniType(arg)); } println(out, ");" + lineSep); } } }
Example 18
Source File: ChangeParametersPlugin.java From netbeans with Apache License 2.0 | 4 votes |
Problem duplicateSignature(Problem p, ParameterInfo[] paramTable, final ExecutableElement method, TypeElement enclosingTypeElement, List<? extends Element> allMembers) { List<ExecutableElement> methods = ElementFilter.methodsIn(allMembers); for (ExecutableElement exMethod : methods) { if(!exMethod.equals(method)) { if(exMethod.getSimpleName().equals(method.getSimpleName()) && exMethod.getParameters().size() == paramTable.length) { boolean sameParameters = true; boolean wideningConversion = true; for (int j = 0; j < exMethod.getParameters().size(); j++) { TypeMirror exType = ((VariableElement)exMethod.getParameters().get(j)).asType(); String type = paramTable[j].getType(); TypeMirror paramType = javac.getTreeUtilities().parseType(type, enclosingTypeElement); if(!javac.getTypes().isSameType(exType, paramType)) { sameParameters = false; if(exType.getKind().isPrimitive() && paramType.getKind().isPrimitive()) { /* * byte to short, int, long, float, or double * short to int, long, float, or double * char to int, long, float, or double * int to long, float, or double * long to float or double * float to double */ switch (exType.getKind()) { case DOUBLE: if(paramType.getKind().equals(TypeKind.FLOAT)) { break; } case FLOAT: if(paramType.getKind().equals(TypeKind.LONG)) { break; } case LONG: if(paramType.getKind().equals(TypeKind.INT)) { break; } case INT: if(paramType.getKind().equals(TypeKind.SHORT)) { break; } case SHORT: if(paramType.getKind().equals(TypeKind.BYTE)) { break; } case BYTE: wideningConversion = false; break; } } else { wideningConversion = false; } } } if(sameParameters) { p = createProblem(p, false, NbBundle.getMessage(ChangeParametersPlugin.class, "ERR_existingMethod", exMethod.toString(), enclosingTypeElement.getQualifiedName())); // NOI18N } else if(wideningConversion) { p = createProblem(p, false, NbBundle.getMessage(ChangeParametersPlugin.class, "WRN_wideningConversion", exMethod.toString(), enclosingTypeElement.getQualifiedName())); // NOI18N } } } } return p; }
Example 19
Source File: JavaElementHandler.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void run(CompilationController info) throws Exception { Elements elements = info.getElements(); ElementAcceptor acceptor = new ElementAcceptor() { public boolean accept(Element e, TypeMirror type) { if (e.getKind() != ElementKind.METHOD) { return false; } for (AccessLevel level : levels) { if (level.getJavaAcceptor().accept(e, type)) { return true; } } return false; } }; TypeElement te = elements.getTypeElement(className); if (te != null) { for (ExecutableElement element : ElementFilter.methodsIn(te.getEnclosedElements())) { if (!acceptor.accept(element, te.asType())) { continue; } String simpleName = element.getSimpleName().toString(); List<String> params = getParameterListForMethod(element); // FIXME this should be more accurate TypeMirror returnType = element.getReturnType(); if (simpleName.toUpperCase(Locale.ENGLISH).startsWith(prefix.toUpperCase(Locale.ENGLISH)) && !simpleName.contains("$")) { proposals.put(getSignature(te, element, typeParameters, info.getTypes()), CompletionItem.forJavaMethod( className, simpleName, params, returnType, element.getModifiers(), anchor, emphasise, nameOnly)); } } } cnt.countDown(); }
Example 20
Source File: JNI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void write(OutputStream o, TypeElement clazz) throws Util.Exit { try { String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS); PrintWriter pw = wrapWriter(o); pw.println(guardBegin(cname)); pw.println(cppGuardBegin()); /* Write statics. */ List<VariableElement> classfields = getAllFields(clazz); for (VariableElement v: classfields) { if (!v.getModifiers().contains(Modifier.STATIC)) continue; String s = null; s = defineForStatic(clazz, v); if (s != null) { pw.println(s); } } /* Write methods. */ List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements()); for (ExecutableElement md: classmethods) { if(md.getModifiers().contains(Modifier.NATIVE)){ TypeMirror mtr = types.erasure(md.getReturnType()); String sig = signature(md); TypeSignature newtypesig = new TypeSignature(elems); CharSequence methodName = md.getSimpleName(); boolean longName = false; for (ExecutableElement md2: classmethods) { if ((md2 != md) && (methodName.equals(md2.getSimpleName())) && (md2.getModifiers().contains(Modifier.NATIVE))) longName = true; } pw.println("/*"); pw.println(" * Class: " + cname); pw.println(" * Method: " + mangler.mangle(methodName, Mangle.Type.FIELDSTUB)); pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr)); pw.println(" */"); pw.println("JNIEXPORT " + jniType(mtr) + " JNICALL " + mangler.mangleMethod(md, clazz, (longName) ? Mangle.Type.METHOD_JNI_LONG : Mangle.Type.METHOD_JNI_SHORT)); pw.print(" (JNIEnv *, "); List<? extends VariableElement> paramargs = md.getParameters(); List<TypeMirror> args = new ArrayList<TypeMirror>(); for (VariableElement p: paramargs) { args.add(types.erasure(p.asType())); } if (md.getModifiers().contains(Modifier.STATIC)) pw.print("jclass"); else pw.print("jobject"); for (TypeMirror arg: args) { pw.print(", "); pw.print(jniType(arg)); } pw.println(");" + lineSep); } } pw.println(cppGuardEnd()); pw.println(guardEnd(cname)); } catch (TypeSignature.SignatureException e) { util.error("jni.sigerror", e.getMessage()); } }