@Override public int compare(final AnnotationInfo a1, final AnnotationInfo a2) { return a1.getAnnotationName().compareTo(a2.getAnnotationName()); } });
@Override public boolean equals(final Object obj) { if (!(obj instanceof AnnotationInfo)) { return false; } final AnnotationInfo o = (AnnotationInfo) obj; return this.compareTo(o) == 0; }
/** * Returns the names of unique annotations on the field. * * @return The names of unique annotations on the field, or the empty list if none. */ public List<String> getAnnotationNames() { return annotationInfo == null ? Collections.<String> emptyList() : Arrays.asList(AnnotationInfo.getUniqueAnnotationNamesSorted(annotationInfo)); }
/** Add field info. */ void addFieldInfo(final List<FieldInfo> fieldInfoList, final Map<String, ClassInfo> classNameToClassInfo) { for (final FieldInfo fieldInfo : fieldInfoList) { final List<AnnotationInfo> fieldAnnotationInfoList = fieldInfo.annotationInfo; if (fieldAnnotationInfoList != null) { for (final AnnotationInfo fieldAnnotationInfo : fieldAnnotationInfoList) { final ClassInfo classInfo = getOrCreateClassInfo(fieldAnnotationInfo.annotationName, ANNOTATION_CLASS_MODIFIER, scanSpec, classNameToClassInfo); fieldAnnotationInfo.addDefaultValues(classInfo.annotationDefaultParamValues); } } } if (this.fieldInfo == null) { this.fieldInfo = fieldInfoList; } else { this.fieldInfo.addAll(fieldInfoList); } }
/** Sets back-reference to scan result after scan is complete. */ @Override void setScanResult(final ScanResult scanResult) { this.scanResult = scanResult; if (this.annotationInfo != null) { for (final AnnotationInfo ai : this.annotationInfo) { ai.setScanResult(scanResult); } } }
@Override public String toString() { final StringBuilder buf = new StringBuilder(); toString(buf); return buf.toString(); }
@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; }
/** Read annotation entry from classfile. */ private AnnotationInfo readAnnotation() throws IOException, InterruptedException { // Lcom/xyz/Annotation; -> Lcom.xyz.Annotation; final String annotationClassName = getConstantPoolClassDescriptor(readUnsignedShort()); final int numElementValuePairs = readUnsignedShort(); List<AnnotationParamValue> paramVals = null; if (numElementValuePairs > 0) { paramVals = new ArrayList<>(numElementValuePairs); } for (int i = 0; i < numElementValuePairs; i++) { final String paramName = getConstantPoolString(readUnsignedShort()); // skip(2); // element_name_index final Object paramValue = readAnnotationElementValue(); paramVals.add(new AnnotationParamValue(paramName, paramValue)); } return new AnnotationInfo(annotationClassName, paramVals); }
if (methodAnnotationInfoList != null) { for (final AnnotationInfo methodAnnotationInfo : methodAnnotationInfoList) { methodAnnotationInfo.addDefaultValues( getOrCreateClassInfo(methodAnnotationInfo.annotationName, ANNOTATION_CLASS_MODIFIER, scanSpec, classNameToClassInfo).annotationDefaultParamValues); final AnnotationInfo paramAnnotationInfo = paramAnnotationInfoArr[j]; paramAnnotationInfo .addDefaultValues(getOrCreateClassInfo(paramAnnotationInfo.annotationName, ANNOTATION_CLASS_MODIFIER, scanSpec, classNameToClassInfo).annotationDefaultParamValues);
/** Sets back-reference to scan result after scan is complete. */ @Override void setScanResult(final ScanResult scanResult) { this.scanResult = scanResult; if (this.annotationInfo != null) { for (int i = 0; i < this.annotationInfo.size(); i++) { final AnnotationInfo ai = this.annotationInfo.get(i); ai.setScanResult(scanResult); } } if (this.parameterAnnotationInfo != null) { for (int i = 0; i < this.parameterAnnotationInfo.length; i++) { final AnnotationInfo[] pai = this.parameterAnnotationInfo[i]; if (pai != null) { for (final AnnotationInfo ai : pai) { ai.setScanResult(scanResult); } } } } }
buf.append(' '); buf.append(annotation.toString());
@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; }
private boolean isVisibleAnnotation(AnnotationInfo annotation) { return isVisibleAnnotation(annotation.getAnnotationName()); }
/** Add an annotation to this class. */ void addClassAnnotation(final AnnotationInfo classAnnotationInfo, final Map<String, ClassInfo> classNameToClassInfo) { final ClassInfo annotationClassInfo = getOrCreateClassInfo(classAnnotationInfo.annotationName, ANNOTATION_CLASS_MODIFIER, scanSpec, classNameToClassInfo); annotationClassInfo.isAnnotation = true; if (this.annotationInfo == null) { this.annotationInfo = new ArrayList<>(); } this.annotationInfo.add(classAnnotationInfo); annotationClassInfo.modifiers |= 0x2000; // Modifier.ANNOTATION classAnnotationInfo.addDefaultValues(annotationClassInfo.annotationDefaultParamValues); this.addRelatedClass(RelType.CLASS_ANNOTATIONS, annotationClassInfo); annotationClassInfo.addRelatedClass(RelType.CLASSES_WITH_CLASS_ANNOTATION, this); }
/** Sets back-reference to scan result after scan is complete. */ @Override void setScanResult(final ScanResult scanResult) { this.scanResult = scanResult; if (annotationInfo != null) { for (final AnnotationInfo ai : annotationInfo) { ai.setScanResult(scanResult); } } if (fieldInfo != null) { for (final FieldInfo fi : fieldInfo) { fi.setScanResult(scanResult); } } if (methodInfo != null) { for (final MethodInfo mi : methodInfo) { mi.setScanResult(scanResult); } } }
buf.append("<tr>"); buf.append("<td align='center' valign='top'>"); GraphvizUtils.htmlEncode(ai.toString(), buf); buf.append("</td></tr>"); buf.append(' '); GraphvizUtils.htmlEncode(ai.toString(), buf); buf.append(' '); GraphvizUtils.htmlEncode(ai.toString(), buf); if (paramAnnotationInfo != null) { for (final AnnotationInfo ai : paramAnnotationInfo) { final String ais = ai.toString(); if (!ais.isEmpty()) { if (buf.charAt(buf.length() - 1) != ' ') {
/** * Returns the names of annotations on the method. * * @return The names of annotations on this method, or the empty list if none. */ public List<String> getAnnotationNames() { return annotationInfo == null ? Collections.<String> emptyList() : Arrays.asList(AnnotationInfo.getUniqueAnnotationNamesSorted(annotationInfo)); }
for (AnnotationInfo[] oneParametersAnnotationInfo: parametersAnnotationInfo) { for (AnnotationInfo ai : oneParametersAnnotationInfo) { if (ai.getAnnotationType() == clazz) { methodIdentifiers.add(new MethodIdentifier(methodInfo.getClassName(), methodInfo.getMethodName(), methodInfo.getParameterTypeSignatures()));
/** Add a field annotation to this class. */ void addFieldAnnotation(final AnnotationInfo fieldAnnotationInfo, final Map<String, ClassInfo> classNameToClassInfo) { final ClassInfo annotationClassInfo = getOrCreateClassInfo(fieldAnnotationInfo.annotationName, ANNOTATION_CLASS_MODIFIER, scanSpec, classNameToClassInfo); annotationClassInfo.isAnnotation = true; annotationClassInfo.modifiers |= 0x2000; // Modifier.ANNOTATION fieldAnnotationInfo.addDefaultValues(annotationClassInfo.annotationDefaultParamValues); this.addRelatedClass(RelType.FIELD_ANNOTATIONS, annotationClassInfo); annotationClassInfo.addRelatedClass(RelType.CLASSES_WITH_FIELD_ANNOTATION, this); }
@Override void setScanResult(final ScanResult scanResult) { if (annotationValueArray != null) { for (int i = 0; i < annotationValueArray.length; i++) { if (annotationValueArray[i] != null) { annotationValueArray[i].setScanResult(scanResult); } } } else if (annotationEnumValue != null) { annotationEnumValue.setScanResult(scanResult); } else if (annotationClassRef != null) { annotationClassRef.setScanResult(scanResult); } else if (annotationInfo != null) { annotationInfo.setScanResult(scanResult); } } }