/** Add annotations found in a module descriptor classfile. */ void addAnnotations(final AnnotationInfoList moduleAnnotations) { // Currently only class annotations are used in the module-info.class file if (moduleAnnotations != null && !moduleAnnotations.isEmpty()) { if (this.annotationInfo == null) { this.annotationInfo = new AnnotationInfoList(moduleAnnotations); } else { this.annotationInfo.addAll(moduleAnnotations); } } }
void addClassAnnotation(final AnnotationInfo classAnnotation) { if (classAnnotations == null) { classAnnotations = new AnnotationInfoList(); } classAnnotations.add(classAnnotation); }
/** * Method parameter annotation info (or null if no annotations). * * @return {@link AnnotationInfo} for any annotations on this method parameter. */ public AnnotationInfoList getAnnotationInfo() { if (!scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableAnnotationInfo() before #scan()"); } if (annotationInfo == null || annotationInfo.length == 0) { return AnnotationInfoList.EMPTY_LIST; } else { final AnnotationInfoList annotationInfoList = new AnnotationInfoList(annotationInfo.length); Collections.addAll(annotationInfoList, annotationInfo); return AnnotationInfoList.getIndirectAnnotations(annotationInfoList, /* annotatedClass = */ null); } }
final AnnotationInfoList reachableAnnotationInfo = new AnnotationInfoList( directAnnotationInfo == null ? 2 : directAnnotationInfo.size()); if (directAnnotationInfo != null) { for (final AnnotationInfo dai : directAnnotationInfo) { directOrInheritedAnnotationClasses.add(dai.getClassInfo()); reachableAnnotationInfo.add(dai); findMetaAnnotations(dai, reachableAnnotationInfo, reachedAnnotationClasses); reachableAnnotationInfo.add(sai); final AnnotationInfoList reachableMetaAnnotationInfo = new AnnotationInfoList(2); findMetaAnnotations(sai, reachableMetaAnnotationInfo, reachedAnnotationClasses); reachableAnnotationInfo.add(rmai); : new AnnotationInfoList(directAnnotationInfo); Collections.sort(directAnnotationInfoSorted); final AnnotationInfoList annotationInfoList = new AnnotationInfoList(reachableAnnotationInfo, directAnnotationInfoSorted); Collections.sort(annotationInfoList);
/** * Get a the named annotation on this module, or null if the module does not have the named annotation. * * @param annotationName * The annotation name. * @return An {@link AnnotationInfo} object representing the named annotation on this module, or null if the * module does not have the named annotation. */ public AnnotationInfo getAnnotationInfo(final String annotationName) { return getAnnotationInfo().get(annotationName); }
/** Find the transitive closure of meta-annotations. */ private static void findMetaAnnotations(final AnnotationInfo ai, final AnnotationInfoList allAnnotationsOut, final Set<ClassInfo> visited) { final ClassInfo annotationClassInfo = ai.getClassInfo(); if (annotationClassInfo != null && annotationClassInfo.annotationInfo != null) { // Don't get in a cycle if (visited.add(annotationClassInfo)) { for (final AnnotationInfo metaAnnotationInfo : annotationClassInfo.annotationInfo) { final ClassInfo metaAnnotationClassInfo = metaAnnotationInfo.getClassInfo(); final String metaAnnotationClassName = metaAnnotationClassInfo.getName(); // Don't treat java.lang.annotation annotations as meta-annotations if (!metaAnnotationClassName.startsWith("java.lang.annotation.")) { // Add the meta-annotation to the transitive closure allAnnotationsOut.add(metaAnnotationInfo); // Recurse to meta-meta-annotation findMetaAnnotations(metaAnnotationInfo, allAnnotationsOut, visited); } } } } }
/** * @param annotationName * The name of an annotation. * @return true if this field has the named annotation. */ public boolean hasAnnotation(final String annotationName) { return getAnnotationInfo().containsName(annotationName); }
if (annotationInfo != null && annotationInfo.size() > 0) { buf.append("<tr><td colspan='3' bgcolor='").append(darkerColor) .append("'><font point-size='12'><b>ANNOTATIONS</b></font></td></tr>"); final AnnotationInfoList annotationInfoSorted = new AnnotationInfoList(annotationInfo); Collections.sort(annotationInfoSorted); for (final AnnotationInfo ai : annotationInfoSorted) {
/** * Get a list of annotations on this method, along with any annotation parameter values. * * @return a list of annotations on this method, along with any annotation parameter values, wrapped in * {@link AnnotationInfo} objects, or the empty list if none. */ public AnnotationInfoList getAnnotationInfo() { if (!scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableAnnotationInfo() before #scan()"); } return annotationInfo == null ? AnnotationInfoList.EMPTY_LIST : AnnotationInfoList.getIndirectAnnotations(annotationInfo, /* annotatedClass = */ null); }
this.parameterModifiers = parameterModifiers; this.parameterAnnotationInfo = parameterAnnotationInfo; this.annotationInfo = methodAnnotationInfo == null || methodAnnotationInfo.isEmpty() ? null : methodAnnotationInfo; this.hasBody = hasBody;
/** * returns the list of direct annotations, excluding meta-annotations. If this {@link AnnotationInfoList} * consists of class annotations, i.e. if it was produced using `ClassInfo#getAnnotationInfo()`, then the * returned list also excludes annotations inherited from a superclass or implemented interface that was * meta-annotated with {@link java.lang.annotation.Inherited @Inherited}. * * @return The list of directly-related annotations. */ public AnnotationInfoList directOnly() { // If directlyRelatedAnnotations == null, this is already a list of direct annotations (the list of // AnnotationInfo objects created when the classfile is read). Otherwise return a new list consisting // of only the direct annotations. return this.directlyRelatedAnnotations == null ? this // Make .directOnly() idempotent : new AnnotationInfoList(directlyRelatedAnnotations, /* directlyRelatedAnnotations = */ null); } }
/** Get the names of all classes refernenced by this class. */ Set<String> getReferencedClassNames() { // refdClassNames came from class refs and type signatures in the constant pool of the classfile, // but there are other sources of class refs and type signatures that are coded as CONSTANT_Utf8_info // (such as enum classes and class references in annotation parameter values), so these need to be // added to the set of referenced classes. if (referencedClassNames == null) { referencedClassNames = new HashSet<>(); } getAnnotationInfo().getReferencedClassNames(referencedClassNames); getMethodInfo().getReferencedClassNames(referencedClassNames); getFieldInfo().getReferencedClassNames(referencedClassNames); // Get rid of self-references and references to java.lang.Object referencedClassNames.remove(name); referencedClassNames.remove("java.lang.Object"); return referencedClassNames; }
/** * Get a the named annotation on this package, or null if the package does not have the named annotation. * * @param annotationName * The annotation name. * @return An {@link AnnotationInfo} object representing the named annotation on this package, or null if the * package does not have the named annotation. */ public AnnotationInfo getAnnotationInfo(final String annotationName) { return getAnnotationInfo().get(annotationName); }
/** * @param annotationName * The name of an annotation. * @return true if this method has the named annotation. */ public boolean hasAnnotation(final String annotationName) { return getAnnotationInfo().containsName(annotationName); }
/** * Get a list of annotations on this field, along with any annotation parameter values, wrapped in * {@link AnnotationInfo} objects. * * @return A list of annotations on this field, along with any annotation parameter values, wrapped in * {@link AnnotationInfo} objects, or the empty list if none. */ public AnnotationInfoList getAnnotationInfo() { if (!scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableAnnotationInfo() before #scan()"); } return annotationInfo == null ? AnnotationInfoList.EMPTY_LIST : AnnotationInfoList.getIndirectAnnotations(annotationInfo, /* annotatedClass = */ null); }
this.annotationInfo = annotationInfo == null || annotationInfo.isEmpty() ? null : annotationInfo;
/** Add annotations found in a package descriptor classfile. */ void addAnnotations(final AnnotationInfoList packageAnnotations) { // Currently only class annotations are used in the package-info.class file if (packageAnnotations != null && !packageAnnotations.isEmpty()) { if (this.annotationInfo == null) { this.annotationInfo = new AnnotationInfoList(packageAnnotations); } else { this.annotationInfo.addAll(packageAnnotations); } } }
/** * Find the subset of the {@link AnnotationInfo} objects in this list for which the given filter predicate is * true. * * @param filter * The {@link AnnotationInfoFilter} to apply. * @return The subset of the {@link AnnotationInfo} objects in this list for which the given filter predicate is * true. */ public AnnotationInfoList filter(final AnnotationInfoFilter filter) { final AnnotationInfoList annotationInfoFiltered = new AnnotationInfoList(); for (final AnnotationInfo resource : this) { if (filter.accept(resource)) { annotationInfoFiltered.add(resource); } } return annotationInfoFiltered; }
/** * Get a the named annotation on this method parameter, or null if the method parameter does not have the named * annotation. * * @param annotationName * The annotation name. * @return An {@link AnnotationInfo} object representing the named annotation on this method parameter, or null * if the method parameter does not have the named annotation. */ public AnnotationInfo getAnnotationInfo(final String annotationName) { return getAnnotationInfo().get(annotationName); }
/** * @param annotationName * The name of an annotation. * @return true if this method parameter has the named annotation. */ public boolean hasAnnotation(final String annotationName) { return getAnnotationInfo().containsName(annotationName); }