private static boolean supportsOverride(CompilationInfo info) { return info.getElements().getTypeElement("java.lang.Override") != null; }
public static Collection<TypeMirror> getDecoratedTypes( TypeElement element , CompilationInfo info ) { TypeElement serializable = info.getElements().getTypeElement( Serializable.class.getCanonicalName()); Collection<TypeMirror> result = new LinkedList<TypeMirror>(); collectDecoratedTypes( element.asType() , result , serializable, info ); return result; }
private static ExecutableElement getMethod(ExecutableElement method, TypeElement type, CompilationInfo info) { for (ExecutableElement met: ElementFilter.methodsIn(type.getEnclosedElements())){ if (info.getElements().overrides(method, met, type)) { return met; } } return null; }
public Void visitMemberSelect(MemberSelectTree node, Void p) { TypeElement e = info.getElements().getTypeElement(node.toString()); if (e != null) { translateMap.put(node, make.QualIdent(e)); return null; } else { return super.visitMemberSelect(node, p); } }
private boolean hasUnrestrictedType( TypeElement overriden, List<TypeMirror> restrictedTypes,CompilationInfo compInfo ) { Set<TypeElement> specializedBeanTypes = getUnrestrictedBeanTypes( overriden, compInfo); Set<TypeElement> restrictedElements = getElements(restrictedTypes, compInfo); restrictedElements.add( compInfo.getElements().getTypeElement( Object.class.getCanonicalName())); return restrictedElements.containsAll(specializedBeanTypes); }
public Object run(CompilationInfo cinfo) { TypeElement typeElement = typeElementHandle.resolve(cinfo); TypeMirror superType = cinfo.getElements().getTypeElement(typeName).asType(); if(superType.getKind() == TypeKind.DECLARED && cinfo.getTypes().isSubtype(typeElement.asType(), superType)) { return Boolean.TRUE; } return Boolean.FALSE; } }, fObj);
private Collection<ColoringAttributes> getMethodColoring(ExecutableElement mdecl, boolean nct) { Collection<ColoringAttributes> c = new ArrayList<ColoringAttributes>(); addModifiers(mdecl, c); if (mdecl.getKind() == ElementKind.CONSTRUCTOR) { c.add(ColoringAttributes.CONSTRUCTOR); //#146820: if (nct && mdecl.getEnclosingElement() != null && info.getElements().isDeprecated(mdecl.getEnclosingElement())) { c.add(ColoringAttributes.DEPRECATED); } } else c.add(ColoringAttributes.METHOD); return c; }
if (info.getElements().isDeprecated(decl)) { c.add(ColoringAttributes.DEPRECATED);
private List<Fix> createQualifierFix( CompilationInfo compilationInfo, Element annotation, Element classElement ) { PackageElement packageElement = compilationInfo.getElements() .getPackageOf(classElement); FileObject targetFile = SourceUtils.getFile( ElementHandle.create(classElement), compilationInfo.getClasspathInfo()); return Collections.<Fix> singletonList(new CreateQualifierFix( compilationInfo, annotation.getSimpleName().toString(), packageElement.getQualifiedName().toString(), targetFile)); }
private List<Fix> createInterceptorFix( CompilationInfo compilationInfo, Element annotation, Element classElement ) { PackageElement packageElement = compilationInfo.getElements() .getPackageOf(classElement); FileObject targetFile = SourceUtils.getFile( ElementHandle.create(classElement), compilationInfo.getClasspathInfo()); return Collections.<Fix> singletonList(new CreateInterceptorBinding( compilationInfo, annotation.getSimpleName().toString(), packageElement.getQualifiedName().toString(), targetFile)); }
Elements els = info.getElements(); for( String annotation : annotationFqns){ TypeElement annotationElement = els.getTypeElement(
private List<Fix> analyzeField( CompilationInfo compilationInfo, Element var, Element annotation , TypeElement parent ) { List<? extends AnnotationMirror> allAnnotationMirrors = compilationInfo.getElements().getAllAnnotationMirrors(var); boolean isInjectionPoint = false; boolean hasRequiredAnnotation = false; for (AnnotationMirror annotationMirror : allAnnotationMirrors) { Element annotationElement = annotationMirror.getAnnotationType(). asElement(); TypeElement annotationTypeElement = (TypeElement)annotationElement; if ( annotationElement.equals( annotation)) { hasRequiredAnnotation = true; } else if ( annotationTypeElement!= null && annotationTypeElement.getQualifiedName().contentEquals( INJECT_ANNOTATION) || annotationTypeElement.getQualifiedName(). contentEquals(PRODUCER_ANNOTATION)) { isInjectionPoint = true; } } if ( hasRequiredAnnotation && isInjectionPoint ){ return createQualifierFix(compilationInfo, annotation, parent); } return Collections.<Fix>emptyList(); }
/** * Resolves all captured type variables to their respective wildcards in the given type. * @param info CompilationInfo over which the method should work * @param tm type to resolve * @return resolved type * * @since 0.136 */ public static TypeMirror resolveCapturedType(CompilationInfo info, TypeMirror tm) { TypeMirror type = resolveCapturedTypeInt(info, tm); if (type.getKind() == TypeKind.WILDCARD) { TypeMirror tmirr = ((WildcardType) type).getExtendsBound(); tmirr = tmirr != null ? tmirr : ((WildcardType) type).getSuperBound(); if (tmirr != null) { return tmirr; } else { //no extends, just '? TypeElement tel = info.getElements().getTypeElement("java.lang.Object"); // NOI18N return tel == null ? null : tel.asType(); } } return type; }
return true; Element serEl = info.getElements().getTypeElement("java.io.Serializable"); // NOI18N Element extEl = info.getElements().getTypeElement("java.io.Externalizable"); // NOI18N if (serEl == null || extEl == null) { return true;
Types types = JavacTypes.instance(ctx); Set<String> typeStrings = new HashSet<>(); for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(type))) {
private List<Fix> analyzeClass( CompilationInfo compilationInfo, TypeElement clazz, Element annotation ) { List<? extends AnnotationMirror> allAnnotationMirrors = compilationInfo.getElements().getAllAnnotationMirrors(clazz); boolean isInterceptor = false; boolean hasAnnotation = false; for (AnnotationMirror annotationMirror : allAnnotationMirrors) { Element annotationElement = annotationMirror.getAnnotationType().asElement(); if ( annotationElement!= null && annotationElement.equals( annotation)){ hasAnnotation = true; } if ( annotationElement instanceof TypeElement && ((TypeElement)annotationElement).getQualifiedName(). contentEquals(INTERCEPTOR_ANNOTATION)) { isInterceptor = true; } } if ( !hasAnnotation ){ return Collections.<Fix>emptyList(); } if ( isInterceptor ){ return createInterceptorFix(compilationInfo, annotation, clazz); } else { return createQualifierFix(compilationInfo, annotation, clazz); } }
private boolean hasRestrictedType( TypeMirror elementType, List<TypeMirror> restrictedTypes, CompilationInfo compInfo, List<TypeMirror> restrictedSuper ) { if ( elementType.getKind() == TypeKind.ARRAY ){ for( TypeMirror mirror : restrictedSuper ){ boolean found = false; for( TypeMirror restrictedType : restrictedTypes ){ if ( compInfo.getTypes().isSameType( restrictedType, mirror)){ found = true; break; } } if ( !found ){ return false; } } return true; } else { Set<TypeElement> specializedBeanTypes = getElements( restrictedSuper, compInfo); Set<TypeElement> restrictedElements = getElements(restrictedTypes, compInfo); restrictedElements.add( compInfo.getElements().getTypeElement( Object.class.getCanonicalName())); return restrictedElements.containsAll( specializedBeanTypes ); } }
static void transitiveVisitAnnotatedElements( Element element, Set<AnnotationMirror> result,AnnotationHelper helper, TransitiveAnnotationHandler handler ) { List<? extends AnnotationMirror> annotationMirrors = helper .getCompilationInfo().getElements().getAllAnnotationMirrors(element); for (AnnotationMirror annotationMirror : annotationMirrors) { if (result.contains(annotationMirror)) { continue; } Element annotationElement = annotationMirror.getAnnotationType().asElement(); if ( !( annotationElement instanceof TypeElement )){ continue; } boolean isTargetAnnotation = handler.isTargetAnotation( (TypeElement)annotationElement); if ( isTargetAnnotation ){ result.add(annotationMirror); } if (handler.proceed(element, (TypeElement)annotationElement, isTargetAnnotation)) { transitiveVisitAnnotatedElements((TypeElement)annotationElement, result,helper, handler ); } } }
private List<int[]> detectMethodsForClass(CompilationInfo info, Document document, TreePath clazz, List<TypeElement> superTypes, TypeElement thisType) { List<int[]> highlights = new ArrayList<int[]>(); ClassTree clazzTree = (ClassTree) clazz.getLeaf(); TypeElement jlObject = info.getElements().getTypeElement("java.lang.Object"); OUTER: for (Tree member: clazzTree.getMembers()) { if (isCancelled()) { return null; } if (member.getKind() == Kind.METHOD) { TreePath path = new TreePath(clazz, member); Element el = info.getTrees().getElement(path); if (el.getKind() == ElementKind.METHOD) { for (TypeElement superType : superTypes) { for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(superType))) { if (info.getElements().overrides((ExecutableElement) el, ee, thisType) && (superType.getKind().isClass() || !ee.getEnclosingElement().equals(jlObject))) { Token t = Utilities.getToken(info, document, path); if (t != null) { highlights.add(new int[] {t.offset(null), t.offset(null) + t.length()}); } continue OUTER; } } } } } } return highlights; }
for (Element e : info.getElements().getAllMembers((TypeElement) decl)) { if (!e.getModifiers().contains(Modifier.STATIC)) { continue;