/** * Returns those annotations which have themselves been annotated as "Inherited". */ private List<ClassInfo> selectInheritedAnnotations(Collection<ClassInfo> classes) { return classes.stream() .flatMap(cls -> cls.getAnnotations().stream()) .filter(ann -> inheritedAnnotations.contains(ann.getClassName())) .collect(toList()); }
/** * Get the names of direct superclasses of this class. * * <p> * Typically the returned list will contain zero or one direct superclass name(s), but may contain more than one * direct superclass name in the case of Scala mixins. * * @return the direct superclasses of this class, or the empty set if none. */ public List<String> getNamesOfDirectSuperclasses() { return getClassNames(getDirectSuperclasses()); }
/** * Get the names of direct superinterfaces of this interface. * * @return the sorted list of names of direct superinterfaces of this interface, or the empty list if none. */ public List<String> getNamesOfDirectSuperinterfaces() { return getClassNames(getDirectSuperinterfaces()); }
/** * Get the interfaces implemented by this standard class, or by one of its superclasses. * * @return the set of interfaces implemented by this standard class, or by one of its superclasses. Returns the * empty list if none. */ public List<String> getNamesOfImplementedInterfaces() { return getClassNames(getImplementedInterfaces()); }
final Set<ClassInfo> standardClassNodes = ClassInfo.filterClassInfo(allClassInfo(), /* removeExternalClassesIfStrictWhitelist = */ true, scanSpec, ClassType.STANDARD_CLASS); final ClassInfo objectClass = classNameToClassInfo.get("java.lang.Object"); final Set<ClassInfo> interfaceNodes = ClassInfo.filterClassInfo(allClassInfo(), /* removeExternalClassesIfStrictWhitelist = */ true, scanSpec, ClassType.IMPLEMENTED_INTERFACE); final Set<ClassInfo> annotationNodes = ClassInfo.filterClassInfo(allClassInfo(), /* removeExternalClassesIfStrictWhitelist = */ true, scanSpec, ClassType.ANNOTATION); buf.append("\"").append(node.getClassName()).append("\""); labelClassNodeHTML(node, "box", "fff2b6", showFields, showMethods, buf); buf.append(";\n"); buf.append("\"").append(node.getClassName()).append("\""); labelClassNodeHTML(node, "diamond", "b6e7ff", showFields, showMethods, buf); buf.append(";\n"); buf.append("\"").append(node.getClassName()).append("\""); labelClassNodeHTML(node, "oval", "f3c9ff", showFields, showMethods, buf); buf.append(";\n"); final ClassInfo directSuperclassNode = classNode.getDirectSuperclass(); if (directSuperclassNode != null && allVisibleNodes.contains(directSuperclassNode)) { buf.append(" \"" + classNode.getClassName() + "\" -> \"" + directSuperclassNode.getClassName() + "\" [arrowsize=2.5]\n"); for (final ClassInfo implementedInterfaceNode : classNode.getDirectlyImplementedInterfaces()) { if (allVisibleNodes.contains(implementedInterfaceNode)) {
public void println(ClassInfo classInfo, int modifierMask, List<String> filteredAnnotations) { append(asAnnotations(filteredAnnotations, "")); append(Modifier.toString(classInfo.getClassRef().getModifiers() & modifierMask)); if (classInfo.isAnnotation()) { append(" @interface ").print(classInfo.getClassName()); } else if (classInfo.isStandardClass()) { append(" class ").print(classInfo.getClassName()); Set<ClassInfo> superclasses = classInfo.getDirectSuperclasses(); if (!superclasses.isEmpty()) { append(" extends ").print(stringOf(superclasses)); Set<ClassInfo> interfaces = classInfo.getDirectlyImplementedInterfaces(); if (!interfaces.isEmpty()) { append(" implements ").print(stringOf(interfaces)); append(" interface ").print(classInfo.getClassName()); Set<ClassInfo> superinterfaces = classInfo.getDirectSuperinterfaces(); if (!superinterfaces.isEmpty()) { append(" extends ").print(stringOf(superinterfaces));
if (classInfo.getClassLoaders() == null) { if (classInfo.isAnnotation() && !isVisibleAnnotation(className)) { if (classInfo.getFullyQualifiedContainingMethodName() != null) { writeMethods(writer, classInfo.getMethodAndConstructorInfo()); writeFields(writer, classInfo.getFieldInfo()); writer.println("##"); });
buf.append("<tr><td>" + ci.getModifiersStr() + " " + (ci.isEnum() ? "enum" : ci.isAnnotation() ? "@interface" : ci.isInterface() ? "interface" : "class") + "</td></tr>"); final String className = ci.getClassName(); final int dotIdx = className.lastIndexOf('.'); if (dotIdx > 0) {
private Set<ClassInfo> readClassAnnotationsFor(ClassInfo classInfo) { Set<ClassInfo> annotations = new HashSet<>(classInfo.getAnnotations()); annotations.addAll(selectInheritedAnnotations(classInfo.getSuperclasses())); annotations.addAll(selectInheritedAnnotations(classInfo.getImplementedInterfaces())); return annotations; }
classInfo == null ? Collections.emptyList() : classInfo.getNamesOfImplementedInterfaces(); Iterator<String> iterator = interfaces.iterator(); if (interfaces != null && interfaces.size() > 0) { String iName = iterator.next(); classInfo = EventuateClientStartupHookProvider.classNameToClassInfo.get(iName); if (classInfo.hasDirectAnnotation(annotationType.getName())) { try { Class c = Class.forName(iName); if (classInfo.hasDirectAnnotation(annotationType.getName())) { try { Class c = Class.forName(classInfo.getClassName()); result = (A) c.getAnnotation(annotationType); } catch (ClassNotFoundException e) {
private Set<ClassInfo> readInterfaceAnnotationsFor(ClassInfo classInfo) { Set<ClassInfo> annotations = new HashSet<>(classInfo.getAnnotations()); annotations.addAll(selectInheritedAnnotations(classInfo.getSuperinterfaces())); return annotations; }
/** Builds the class graph, and provides methods for querying it. */ ClassGraphBuilder(final ScanSpec scanSpec, final Map<String, ClassInfo> classNameToClassInfo) { this.scanSpec = scanSpec; this.classNameToClassInfo = classNameToClassInfo; for (final ClassInfo classInfo : classNameToClassInfo.values()) { if (classInfo.classLoaders != null) { classNameToClassLoaders.put(classInfo.getClassName(), classInfo.classLoaders); } } }
/** * Get the interfaces directly implemented by this standard class, or by one of its superclasses. * * @return the set of interfaces directly implemented by this standard class, or by one of its superclasses. * Returns the empty list if none. */ public List<String> getNamesOfDirectlyImplementedInterfaces() { return getClassNames(getDirectlyImplementedInterfaces()); }
/** * Get the names of all direct and indirect superclasses of this class (i.e. the direct superclass(es) of this * class, and their superclass(es), all the way up to the top of the class hierarchy). * * <p> * (Includes the union of all mixin superclass hierarchies in the case of Scala mixins.) * * @return the sorted list of names of all superclasses of this class, or the empty list if none. */ public List<String> getNamesOfSuperclasses() { return getClassNames(getSuperclasses()); }
/** * Get the names of annotations and meta-annotations on this class. This is equivalent to the reflection call * Class#getAnnotations(), except that it does not require calling the classloader, and it returns * meta-annotations as well as annotations. * * @return the sorted list of names of annotations and meta-annotations on this class or interface, or * meta-annotations if this is an annotation. Returns the empty list if none. */ public List<String> getNamesOfAnnotations() { return getClassNames(getAnnotations()); }
@Override public Set<Method> getMethodsWithAnyParamAnnotated(Class clazz) { Map<String, ClassInfo> classInfos = scanResult.getClassNameToClassInfo(); Set<MethodIdentifier> methodIdentifiers = new HashSet<>(); for (ClassInfo classInfo : classInfos.values()){ for (MethodInfo methodInfo : classInfo.getMethodAndConstructorInfo()) { AnnotationInfo[][] parametersAnnotationInfo = methodInfo.getParameterAnnotationInfo(); if (parametersAnnotationInfo != null) for (AnnotationInfo[] oneParametersAnnotationInfo: parametersAnnotationInfo) { for (AnnotationInfo ai : oneParametersAnnotationInfo) { if (ai.getAnnotationType() == clazz) { methodIdentifiers.add(new MethodIdentifier(methodInfo.getClassName(), methodInfo.getMethodName(), methodInfo.getParameterTypeSignatures())); } } } } } Set<Method> methods = new HashSet<>(methodIdentifiers.size()); for (MethodIdentifier methodIdentifier : methodIdentifiers) { Class<?> classe = scanResult.classNameToClassRef(methodIdentifier.getClassName()); for (Method method : classe.getDeclaredMethods()) { if (methodIdentifier.matchesMethod(classe, method, scanResult)){ methods.add(method); } } } return methods; }
/** * Test whether this standard class implements the named interface, or by one of its superclasses. * * @param interfaceName * The name of the interface. * @return true this class is a standard class, and it (or one of its superclasses) implements the named * interface. */ public boolean implementsInterface(final String interfaceName) { return getNamesOfImplementedInterfaces().contains(interfaceName); }
/** * Convenience method for getting the single direct superclass of this class. Returns null if the class does not * have a superclass (e.g. in the case of interfaces). Throws IllegalArgumentException if there are multiple * direct superclasses (e.g. in the case of Scala mixins) -- use getDirectSuperclasses() if you need to deal * with mixins. * * @return the direct superclass of this class, or null if the class does not have a superclass. * @throws IllegalArgumentException * if there are multiple direct superclasses of this class (in the case of Scala mixins). */ public ClassInfo getDirectSuperclass() { final Set<ClassInfo> directSuperclasses = getDirectSuperclasses(); final int numDirectSuperclasses = directSuperclasses.size(); if (numDirectSuperclasses == 0) { return null; } else if (numDirectSuperclasses > 1) { throw new IllegalArgumentException("Class has multiple direct superclasses: " + directSuperclasses.toString() + " -- need to call getDirectSuperclasses() instead"); } else { return directSuperclasses.iterator().next(); } }
@Override public Set<Field> getFieldsAnnotatedWith(Class clazz) { Map<String, ClassInfo> classInfos = scanResult.getClassNameToClassInfo(); Set<FieldIdentifier> fieldIdentifiers = new HashSet<>(); for (ClassInfo classInfo : classInfos.values()){ for (FieldInfo fieldInfo : classInfo.getFieldInfo()) { List<AnnotationInfo> fieldsAnnotationInfos = fieldInfo.getAnnotationInfo(); for (AnnotationInfo oneFieldAnnotation: fieldsAnnotationInfos) { if (oneFieldAnnotation.getAnnotationType() == clazz) { fieldIdentifiers.add(new FieldIdentifier(fieldInfo.getClassName(), fieldInfo.getFieldName(), fieldInfo.getType())); } } } } Set<Field> fields = new HashSet<>(fieldIdentifiers.size()); for (FieldIdentifier fieldIdentifier : fieldIdentifiers) { Class<?> classe = scanResult.classNameToClassRef(fieldIdentifier.getClassName()); for (Field field : classe.getDeclaredFields()) { if (fieldIdentifier.matchesField(classe, field)){ fields.add(field); } } } return fields; }
classNameToClassInfo.put(ci.getClassName(), ci);