javax.lang.model.element.ExecutableElement Java Examples
The following examples show how to use
javax.lang.model.element.ExecutableElement.
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: AnnotatedMixinElementHandler.java From Mixin with MIT License | 6 votes |
private void validateMethodVisibility(ExecutableElement method, AnnotationHandle annotation, String type, TypeHandle target, MethodHandle targetMethod) { Visibility visTarget = targetMethod.getVisibility(); if (visTarget == null) { return; } Visibility visMethod = TypeUtils.getVisibility(method); String visibility = "visibility of " + visTarget + " method in " + target; if (visTarget.ordinal() > visMethod.ordinal()) { this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation, SuppressedBy.VISIBILITY); } else if (visTarget == Visibility.PRIVATE && visMethod.ordinal() > visTarget.ordinal()) { this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation, SuppressedBy.VISIBILITY); } }
Example #2
Source File: ToStringMethod.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
static MethodSpec generate(TypeElement element) { ClassName.get(element).reflectionName(); Builder result = MethodSpec.methodBuilder("toString") .addModifiers(Modifier.PUBLIC) .returns(String.class) .addAnnotation(Override.class) .addCode( CodeBlock.builder() .add( "StringBuilder sb = new StringBuilder(\"@$L\");\n", ClassName.get(element).reflectionName().replace('$', '.')) .build()); List<ExecutableElement> methods = ElementFilter.methodsIn(element.getEnclosedElements()); if (!methods.isEmpty()) { result.addCode("sb.append('(');\n"); } for (ExecutableElement method : methods) { result.addCode("sb.append(\"$1L=\").append($1L);\n", method.getSimpleName()); } if (!methods.isEmpty()) { result.addCode("sb.append(')');\n"); } result.addCode("return sb.toString();\n"); return result.build(); }
Example #3
Source File: ResourceImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSimplyAnnotatedMethod() throws Exception { TestUtilities.copyStringToFileObject(srcFO, "MyClass.java", "public class MyClass {" + " @javax.annotation.Resource" + " private void setMyResource(javax.sql.DataSource dataSource) {" + " }" + "}"); IndexingManager.getDefault().refreshIndexAndWait(srcFO.getURL(), null); ClasspathInfo cpi = ClasspathInfo.create(srcFO); final AnnotationModelHelper annotationModelHelper = AnnotationModelHelper.create(cpi); annotationModelHelper.runJavaSourceTask(new Runnable() { public void run() { TypeElement myClass = annotationModelHelper.getCompilationController().getElements().getTypeElement("MyClass"); List<ExecutableElement> methods = ElementFilter.methodsIn(myClass.getEnclosedElements()); ExecutableElement annotatedMethod = methods.get(0); ResourceImpl resource = new ResourceImpl(annotatedMethod, myClass, annotationModelHelper); assertEquals("myResource", resource.getName()); assertEquals("javax.sql.DataSource", resource.getType()); assertEquals(ResourceImpl.DEFAULT_AUTHENTICATION_TYPE, resource.getAuthenticationType()); assertEquals(ResourceImpl.DEFAULT_SHAREABLE, resource.getShareable()); assertEquals(ResourceImpl.DEFAULT_MAPPED_NAME, resource.getMappedName()); assertEquals(ResourceImpl.DEFAULT_DESCRIPTION, resource.getDescription()); } }); }
Example #4
Source File: ExportNonAccessibleElement.java From netbeans with Apache License 2.0 | 6 votes |
public Boolean visitExecutable(ExecutableElement method, Void nothing) { if (!isVisible(method)) { // ok return false; } for (VariableElement v : method.getParameters()) { if (stop) { return false; } if (v.asType().accept(this, nothing)) { return true; } } return method.getReturnType().accept(this, nothing); }
Example #5
Source File: ExpressionValidatorTest.java From doma with Apache License 2.0 | 6 votes |
@Test void testMethod_notFound() throws Exception { Class<?> target = ExpressionValidationDao.class; addCompilationUnit(target); addProcessor( new TestProcessor() { @Override protected void run() { ExecutableElement methodElement = createMethodElement(target, "testEmp", Emp.class); Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement); ExpressionValidator validator = new ExpressionValidator(ctx, methodElement, parameterTypeMap); ExpressionNode node = new ExpressionParser("emp.notFound(1, \"aaa\".length())").parse(); try { validator.validate(node); fail(); } catch (AptException expected) { System.out.println(expected); assertEquals(Message.DOMA4071, expected.getMessageResource()); } } }); compile(); assertTrue(getCompiledResult()); }
Example #6
Source File: WebServiceVisitor.java From openjdk-jdk8u 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 #7
Source File: TreeBackedAnnotationMirrorTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void testSingleElementArrayAnnotationMirrorValueWithSingleEntry() throws IOException { compile( Joiner.on('\n') .join( "@FooHelper(42)", "public class Foo {", "}", "@interface FooHelper {", " int[] value();", "}")); AnnotationMirror a = elements.getTypeElement("Foo").getAnnotationMirrors().get(0); ExecutableElement keyElement = findMethod("value", elements.getTypeElement("FooHelper")); @SuppressWarnings("unchecked") List<AnnotationValue> values = (List<AnnotationValue>) a.getElementValues().get(keyElement).getValue(); assertEquals(42, values.get(0).getValue()); assertEquals(1, a.getElementValues().size()); assertEquals(1, values.size()); }
Example #8
Source File: RetroFacebookProcessor.java From RetroFacebook with Apache License 2.0 | 6 votes |
private static String formalArgsString(ExecutableElement method) { List<? extends VariableElement> parameters = method.getParameters(); if (parameters.isEmpty()) { return ""; } else { return "" + Joiner.on(", ").join( FluentIterable.from(parameters).transform(new Function<VariableElement, String>() { @Override public String apply(VariableElement element) { return "" + element.getSimpleName(); } })) + ""; } }
Example #9
Source File: Analyser.java From FreeBuilder with Apache License 2.0 | 6 votes |
/** Find a toBuilder method, if the user has provided one. */ private boolean hasToBuilderMethod( DeclaredType builder, boolean isExtensible, Iterable<ExecutableElement> methods) { for (ExecutableElement method : methods) { if (isToBuilderMethod(builder, method)) { if (!isExtensible) { messager.printMessage(ERROR, "No accessible no-args Builder constructor available to implement toBuilder", method); } return true; } } return false; }
Example #10
Source File: AutoAnnotationProcessor.java From auto with Apache License 2.0 | 6 votes |
private void validateParameters( TypeElement annotationElement, ExecutableElement method, ImmutableMap<String, Member> members, ImmutableMap<String, Parameter> parameters, ImmutableMap<String, AnnotationValue> defaultValues) { boolean error = false; for (String memberName : members.keySet()) { if (!parameters.containsKey(memberName) && !defaultValues.containsKey(memberName)) { reportError( method, "@AutoAnnotation method needs a parameter with name '%s' and type %s" + " corresponding to %s.%s, which has no default value", memberName, members.get(memberName).getType(), annotationElement, memberName); error = true; } } if (error) { throw new AbortProcessingException(); } }
Example #11
Source File: MoreTypes.java From auto with Apache License 2.0 | 6 votes |
/** * Resolves a {@link VariableElement} parameter to a method or constructor based on the given * container, or a member of a class. For parameters to a method or constructor, the variable's * enclosing element must be a supertype of the container type. For example, given a * {@code container} of type {@code Set<String>}, and a variable corresponding to the {@code E e} * parameter in the {@code Set.add(E e)} method, this will return a TypeMirror for {@code String}. */ public static TypeMirror asMemberOf(Types types, DeclaredType container, VariableElement variable) { if (variable.getKind().equals(ElementKind.PARAMETER)) { ExecutableElement methodOrConstructor = MoreElements.asExecutable(variable.getEnclosingElement()); ExecutableType resolvedMethodOrConstructor = MoreTypes.asExecutable(types.asMemberOf(container, methodOrConstructor)); List<? extends VariableElement> parameters = methodOrConstructor.getParameters(); List<? extends TypeMirror> parameterTypes = resolvedMethodOrConstructor.getParameterTypes(); checkState(parameters.size() == parameterTypes.size()); for (int i = 0; i < parameters.size(); i++) { // We need to capture the parameter type of the variable we're concerned about, // for later printing. This is the only way to do it since we can't use // types.asMemberOf on variables of methods. if (parameters.get(i).equals(variable)) { return parameterTypes.get(i); } } throw new IllegalStateException("Could not find variable: " + variable); } else { return types.asMemberOf(container, variable); } }
Example #12
Source File: MethodSpec.java From JReFrameworker with MIT License | 6 votes |
/** * Returns a new method spec builder that overrides {@code method} as a member of {@code * enclosing}. This will resolve type parameters: for example overriding {@link * Comparable#compareTo} in a type that implements {@code Comparable<Movie>}, the {@code T} * parameter will be resolved to {@code Movie}. * * <p>This will copy its visibility modifiers, type parameters, return type, name, parameters, and * throws declarations. An {@link Override} annotation will be added. * * <p>Note that in JavaPoet 1.2 through 1.7 this method retained annotations from the method and * parameters of the overridden method. Since JavaPoet 1.8 annotations must be added separately. */ public static Builder overriding( ExecutableElement method, DeclaredType enclosing, Types types) { ExecutableType executableType = (ExecutableType) types.asMemberOf(enclosing, method); List<? extends TypeMirror> resolvedParameterTypes = executableType.getParameterTypes(); TypeMirror resolvedReturnType = executableType.getReturnType(); Builder builder = overriding(method); builder.returns(TypeName.get(resolvedReturnType)); for (int i = 0, size = builder.parameters.size(); i < size; i++) { ParameterSpec parameter = builder.parameters.get(i); TypeName type = TypeName.get(resolvedParameterTypes.get(i)); builder.parameters.set(i, parameter.toBuilder(type, parameter.name).build()); } return builder; }
Example #13
Source File: AutoValueOrOneOfProcessor.java From auto with Apache License 2.0 | 6 votes |
/** Returns a bi-map between property names and the corresponding abstract property methods. */ final ImmutableBiMap<String, ExecutableElement> propertyNameToMethodMap( Set<ExecutableElement> propertyMethods) { Map<String, ExecutableElement> map = new LinkedHashMap<>(); Set<String> reportedDups = new HashSet<>(); boolean allPrefixed = gettersAllPrefixed(propertyMethods); for (ExecutableElement method : propertyMethods) { String methodName = method.getSimpleName().toString(); String name = allPrefixed ? nameWithoutPrefix(methodName) : methodName; ExecutableElement old = map.put(name, method); if (old != null) { List<ExecutableElement> contexts = new ArrayList<>(Arrays.asList(method)); if (reportedDups.add(name)) { contexts.add(old); } // Report the error for both of the methods. If this is a third or further occurrence, // reportedDups prevents us from reporting more than one error for the same method. for (ExecutableElement context : contexts) { errorReporter.reportError( context, "More than one @%s property called %s", simpleAnnotationName, name); } } } return ImmutableBiMap.copyOf(map); }
Example #14
Source File: WebServiceVisitor.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
protected int getModeParameterCount(ExecutableElement method, WebParam.Mode mode) { WebParam webParam; int cnt = 0; for (VariableElement param : method.getParameters()) { webParam = param.getAnnotation(WebParam.class); if (webParam != null) { if (webParam.header()) continue; if (isEquivalentModes(mode, webParam.mode())) cnt++; } else { if (isEquivalentModes(mode, WebParam.Mode.IN)) { cnt++; } } } return cnt; }
Example #15
Source File: MethodTranslator.java From j2objc with Apache License 2.0 | 5 votes |
private ExecutableElement findMethod(String name, TypeMirror type, MethodReference methodDef) { TypeElement typeElement = (TypeElement) parserEnv.typeUtilities().asElement(type); String signature = methodDef.getSignature(); String erasedSignature = methodDef.getErasedSignature(); for (Element e : typeElement.getEnclosedElements()) { if (e.getKind() == ElementKind.METHOD && e.getSimpleName().contentEquals(name)) { String sig = typeUtil.getReferenceSignature((ExecutableElement) e); if (sig.equals(signature) || sig.equals(erasedSignature)) { return (ExecutableElement) e; } } } throw new AssertionError("failed method lookup: " + type + " " + name + signature); }
Example #16
Source File: ApNavigator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public boolean hasDefaultConstructor(TypeElement t) { if (t == null || !t.getKind().equals(ElementKind.CLASS)) return false; for (ExecutableElement init : ElementFilter.constructorsIn(env.getElementUtils().getAllMembers(t))) { if (init.getParameters().isEmpty()) return true; } return false; }
Example #17
Source File: CreateElementUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { NewClassTree nct = (NewClassTree) parent.getLeaf(); boolean errorInRealArguments = false; for (Tree param : nct.getArguments()) { errorInRealArguments |= param == error; } if (errorInRealArguments) { List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>(); int[] proposedIndex = new int[1]; List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex); if (ee.isEmpty()) { //cannot be resolved return null; } types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); return proposedTypes; } Tree id = nct.getIdentifier(); if (id.getKind() == Kind.PARAMETERIZED_TYPE) { id = ((ParameterizedTypeTree) id).getType(); } if (id == error) { return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null); } return null; }
Example #18
Source File: AbstractTestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** */ private static boolean throwsNonRuntimeExceptions(CompilationInfo compInfo, ExecutableElement method) { List<? extends TypeMirror> thrownTypes = method.getThrownTypes(); if (thrownTypes.isEmpty()) { return false; } String runtimeExcName = "java.lang.RuntimeException"; //NOI18N TypeElement runtimeExcElement = compInfo.getElements() .getTypeElement(runtimeExcName); if (runtimeExcElement == null) { Logger.getLogger("junit").log( //NOI18N Level.WARNING, "Could not find TypeElement for " //NOI18N + runtimeExcName); return true; } Types types = compInfo.getTypes(); TypeMirror runtimeExcType = runtimeExcElement.asType(); for (TypeMirror exceptionType : thrownTypes) { if (!types.isSubtype(exceptionType, runtimeExcType)) { return true; } } return false; }
Example #19
Source File: ColumnProperty.java From auto-value-cursor with Apache License 2.0 | 5 votes |
public static ImmutableList<ColumnProperty> from(AutoValueExtension.Context context) { ImmutableList.Builder<ColumnProperty> values = ImmutableList.builder(); for (Map.Entry<String, ExecutableElement> entry : context.properties().entrySet()) { values.add(new ColumnProperty(entry.getKey(), entry.getValue())); } return values.build(); }
Example #20
Source File: FieldInjectionPointLogic.java From netbeans with Apache License 2.0 | 5 votes |
private boolean collectSpecializes( Element productionElement, ExecutableElement element, WebBeansModelImplementation model, Set<Element> probableSpecializes, Set<Element> specializeElements ) { ElementUtilities elementUtilities = model.getHelper().getCompilationController().getElementUtilities(); if ( !elementUtilities.overridesMethod(element)){ return false; } ExecutableElement overriddenMethod = elementUtilities. getOverriddenMethod( element); if ( overriddenMethod == null ){ return false; } if (!AnnotationObjectProvider.hasSpecializes(element, model.getHelper())){ return false; } probableSpecializes.add( element); if( overriddenMethod.equals( productionElement ) || specializeElements.contains( productionElement)) { return true; } else { return collectSpecializes(productionElement, overriddenMethod, model, probableSpecializes, specializeElements); } }
Example #21
Source File: NbBundleProcessor.java From netbeans with Apache License 2.0 | 5 votes |
private void warnUndocumented(int i, Element e, String key) { AnnotationMirror mirror = null; AnnotationValue value = null; if (e != null) { for (AnnotationMirror _mirror : e.getAnnotationMirrors()) { if (_mirror.getAnnotationType().toString().equals(NbBundle.Messages.class.getCanonicalName())) { mirror = _mirror; for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals("value")) { // SimpleAnnotationValueVisitor6 unusable here since we need to determine the AnnotationValue in scope when visitString is called: Object v = entry.getValue().getValue(); if (v instanceof String) { if (((String) v).startsWith(key + "=")) { value = entry.getValue(); } } else { for (AnnotationValue subentry : NbCollections.checkedListByCopy((List<?>) v, AnnotationValue.class, true)) { v = subentry.getValue(); if (v instanceof String) { if (((String) v).startsWith(key + "=")) { value = subentry; break; } } } } break; } } break; } } } processingEnv.getMessager().printMessage(Kind.WARNING, "Undocumented format parameter {" + i + "}", e, mirror, value); }
Example #22
Source File: ListenerGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private ClassTree generateInterfaces(WorkingCopy wc, TypeElement te, ClassTree ct, GenerationUtils gu) { ClassTree newClassTree = ct; List<String> ifList = new ArrayList<String>(); List<ExecutableElement> methods = new ArrayList<ExecutableElement>(); if (isContext) { ifList.add("javax.servlet.ServletContextListener"); } if (isContextAttr) { ifList.add("javax.servlet.ServletContextAttributeListener"); } if (isSession) { ifList.add("javax.servlet.http.HttpSessionListener"); } if (isSessionAttr) { ifList.add("javax.servlet.http.HttpSessionAttributeListener"); } if (isRequest) { ifList.add("javax.servlet.ServletRequestListener"); } if (isRequestAttr) { ifList.add("javax.servlet.ServletRequestAttributeListener"); } for (String ifName : ifList) { newClassTree = gu.addImplementsClause(newClassTree, ifName); TypeElement typeElement = wc.getElements().getTypeElement(ifName); methods.addAll(ElementFilter.methodsIn(typeElement.getEnclosedElements())); } for (MethodTree t : GeneratorUtilities.get(wc).createAbstractMethodImplementations(te, methods)) { newClassTree = GeneratorUtilities.get(wc).insertClassMember(newClassTree, t); } return newClassTree; }
Example #23
Source File: DelegateMethodGeneratorTest.java From netbeans with Apache License 2.0 | 5 votes |
private String dump(ExecutableElement ee) { StringBuilder result = new StringBuilder(); for (Modifier m : ee.getModifiers()) { result.append(m.toString()); result.append(' '); } result.append(ee.getReturnType().toString() + " " + ee.toString()); return result.toString(); }
Example #24
Source File: TreeBackedAnnotationValueTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void testMultiElementAnnotationMirrorValue() throws IOException { compile( Joiner.on('\n') .join( "public @interface Foo {", " FooHelper value() default @FooHelper(number=42, string=\"42\");", "}", "@interface FooHelper {", " int number();", " String string();", "}")); ExecutableElement method = findMethod("value", elements.getTypeElement("Foo")); AnnotationValue defaultValue = method.getDefaultValue(); defaultValue.accept( new TestVisitor() { @Override public Void visitAnnotation(AnnotationMirror a, Void aVoid) { AnnotationMirror annotationMirrorValue = (AnnotationMirror) defaultValue.getValue(); ExecutableElement numberKeyElement = findMethod("number", elements.getTypeElement("FooHelper")); ExecutableElement stringKeyElement = findMethod("string", elements.getTypeElement("FooHelper")); assertEquals(2, annotationMirrorValue.getElementValues().size()); assertEquals( 42, annotationMirrorValue.getElementValues().get(numberKeyElement).getValue()); assertEquals( "42", annotationMirrorValue.getElementValues().get(stringKeyElement).getValue()); return null; } }, null); assertEquals("@FooHelper(number=42, string=\"42\")", defaultValue.toString()); }
Example #25
Source File: VisitorAnnotationProcessor.java From jlibs with Apache License 2.0 | 5 votes |
private void printVisitMethod(String prefix, Map<TypeMirror, ExecutableElement> classes, Printer printer){ printer.println("@Override"); printer.println("public Object visit(Object obj){"); printer.indent++; List<TypeMirror> list = new ArrayList<TypeMirror>(classes.keySet()); Collections.reverse(list); boolean addElse = false; for(TypeMirror mirror: sort(list)){ String type = ModelUtil.toString(mirror, true); if(addElse) printer.print("else "); else addElse = true; printer.println("if(obj instanceof "+type+")"); printer.indent++; if(classes.get(mirror).getReturnType().getKind()!=TypeKind.VOID) printer.print("return "); printer.println(prefix+METHOD_NAME+"(("+type+")obj);"); printer.indent--; } printer.println(); printer.println("return null;"); printer.indent--; printer.println("}"); }
Example #26
Source File: WSITRefactoringPlugin.java From netbeans with Apache License 2.0 | 5 votes |
protected static boolean isWebSvcFromWsdl(Element element){ for (AnnotationMirror ann : element.getAnnotationMirrors()) { if (WS_ANNOTATION.equals(((TypeElement) ann.getAnnotationType().asElement()).getQualifiedName())) { for (ExecutableElement annVal : ann.getElementValues().keySet()) { if (WSDL_LOCATION_ELEMENT.equals(annVal.getSimpleName().toString())){ return true; } } } } return false; }
Example #27
Source File: WebServiceVisitor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected boolean processedMethod(ExecutableElement method) { String id = method.toString(); if (processedMethods.contains(id)) return true; processedMethods.add(id); return false; }
Example #28
Source File: Processor.java From reflection-no-reflection with Apache License 2.0 | 5 votes |
private void addMethodOrConstructorToAnnotationDatabase(ExecutableElement methodOrConstructorElement, int level) { String methodOrConstructorName = methodOrConstructorElement.getSimpleName().toString(); //System.out.printf("Type: %s, injection: %s \n",typeElementName, methodOrConstructorName); if (methodOrConstructorName.startsWith("<init>")) { addConstructor(methodOrConstructorElement, level); } else { addMethod(methodOrConstructorElement, level); } }
Example #29
Source File: ThrowForInvalidImmutableState.java From immutables with Apache License 2.0 | 5 votes |
private static boolean hasStringArrayConstructor(TypeElement element) { for (ExecutableElement e : ElementFilter.constructorsIn(element.getEnclosedElements())) { if (e.getModifiers().contains(Modifier.PUBLIC) && e.getParameters().size() == 1) { if (isArrayOfStrings(e.getParameters().get(0).asType())) { return true; } } } return false; }
Example #30
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean allTypeVarsAccessible(Collection<TypeVariable> typeVars, Element target) { if (target == null) { return typeVars.isEmpty(); } Set<TypeVariable> targetTypeVars = new HashSet<TypeVariable>(); OUTER: while (target.getKind() != ElementKind.PACKAGE) { Iterable<? extends TypeParameterElement> tpes; switch (target.getKind()) { case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: tpes = ((TypeElement) target).getTypeParameters(); break; case METHOD: case CONSTRUCTOR: tpes = ((ExecutableElement) target).getTypeParameters(); break; default: break OUTER; } for (TypeParameterElement tpe : tpes) { targetTypeVars.add((TypeVariable) tpe.asType()); } if (target.getModifiers().contains(Modifier.STATIC)) { break; } target = target.getEnclosingElement(); } return targetTypeVars.containsAll(typeVars); }