@Override public boolean equals(final Object obj) { if (!(obj instanceof AnnotationParameterValue)) { return false; } final AnnotationParameterValue o = (AnnotationParameterValue) obj; return this.compareTo(o) == 0 && (value == null) == (o.value == null) && (value == null || value.equals(o.value)); }
/** * For primitive array type params, replace Object[] arrays containing boxed types with primitive arrays (need * to check the type of each method of the annotation class to determine if it is a primitive array type). */ void convertWrapperArraysToPrimitiveArrays(final ClassInfo annotationClassInfo) { for (final AnnotationParameterValue annotationParamValue : this) { annotationParamValue.convertWrapperArraysToPrimitiveArrays(annotationClassInfo); } }
allParamValues.put(defaultParamValue.getName(), defaultParamValue.getValue()); allParamValues.put(annotationParamValue.getName(), annotationParamValue.getValue()); annotationParamValuesWithDefaults.add(new AnnotationParameterValue(ent.getKey(), ent.getValue()));
/** * Render as a string, into a StringBuilder buffer. * * @param buf * The buffer. */ void toString(final StringBuilder buf) { buf.append("@").append(getName()); if (annotationParamValues != null && !annotationParamValues.isEmpty()) { buf.append('('); for (int i = 0; i < annotationParamValues.size(); i++) { if (i > 0) { buf.append(", "); } final AnnotationParameterValue annotationParamValue = annotationParamValues.get(i); if (annotationParamValues.size() > 1 || !"value".equals(annotationParamValue.getName())) { annotationParamValue.toString(buf); } else { annotationParamValue.toStringParamValueOnly(buf); } } buf.append(')'); } }
AnnotationInvocationHandler(final Class<? extends Annotation> annotationClass, final AnnotationInfo annotationInfo) { this.annotationClass = annotationClass; this.toString = annotationInfo.toString(); // Instantiate the annotation parameter values (this loads and gets references for class literals, // enum constants, etc.) for (final AnnotationParameterValue apv : annotationInfo.getParameterValues()) { final Object instantiatedValue = apv.instantiate(annotationInfo.getClassInfo()); if (instantiatedValue == null) { // Annotations cannot contain null values throw new IllegalArgumentException("Got null value for annotation parameter " + apv.getName() + " of annotation " + annotationInfo.getName()); } this.annotationParameterValuesInstantiated.put(apv.getName(), instantiatedValue); } }
/** * @param parameterName * The name of an annotation parameter. * @return true if this list contains an annotation parameter with the given name. */ public boolean containsName(final String parameterName) { for (final AnnotationParameterValue apv : this) { if (apv.getName().equals(parameterName)) { return true; } } return false; }
/** Get the names of any classes referenced in the type descriptors of annotation parameters. */ @Override void getReferencedClassNames(final Set<String> classNames) { classNames.add(name); if (annotationParamValues != null) { for (final AnnotationParameterValue annotationParamValue : annotationParamValues) { annotationParamValue.getReferencedClassNames(classNames); } } }
@Override public String toString() { final StringBuilder buf = new StringBuilder(); toString(buf); return buf.toString(); }
@Override void setScanResult(final ScanResult scanResult) { super.setScanResult(scanResult); if (annotationParamValues != null) { for (final AnnotationParameterValue a : annotationParamValues) { a.setScanResult(scanResult); } } }
/** Read annotation entry from classfile. */ private AnnotationInfo readAnnotation() throws IOException, IllegalArgumentException { // Lcom/xyz/Annotation; -> Lcom.xyz.Annotation; final String annotationClassName = getConstantPoolClassDescriptor( inputStreamOrByteBuffer.readUnsignedShort()); final int numElementValuePairs = inputStreamOrByteBuffer.readUnsignedShort(); AnnotationParameterValueList paramVals = null; if (numElementValuePairs > 0) { paramVals = new AnnotationParameterValueList(numElementValuePairs); for (int i = 0; i < numElementValuePairs; i++) { final String paramName = getConstantPoolString(inputStreamOrByteBuffer.readUnsignedShort()); final Object paramValue = readAnnotationElementValue(); paramVals.add(new AnnotationParameterValue(paramName, paramValue)); } } return new AnnotationInfo(annotationClassName, paramVals); }
void toString(final StringBuilder buf) { buf.append(name); buf.append(" = "); toStringParamValueOnly(buf); }
/** * @return This {@link AnnotationParameterValueList} as a map from annotation parameter name to * {@link AnnotationParameterValue} object. */ public Map<String, AnnotationParameterValue> asMap() { final Map<String, AnnotationParameterValue> annotationNameToAnnotationParameterValue = new HashMap<>(); for (final AnnotationParameterValue apv : this) { annotationNameToAnnotationParameterValue.put(apv.getName(), apv); } return annotationNameToAnnotationParameterValue; }
paramValue.getReferencedClassNames(referencedClassNames);
/** * @return The string representations of all annotation parameter values in this list, by calling * {@link AnnotationParameterValue#toString()} for each item in the list. */ public List<String> getAsStrings() { if (this.isEmpty()) { return Collections.emptyList(); } else { final List<String> toStringVals = new ArrayList<>(this.size()); for (final AnnotationParameterValue apv : this) { toStringVals.add(apv.toString()); } return toStringVals; } }
@Override void setScanResult(final ScanResult scanResult) { super.setScanResult(scanResult); if (this.typeSignature != null) { this.typeSignature.setScanResult(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); } } if (annotationDefaultParamValues != null) { for (final AnnotationParameterValue apv : annotationDefaultParamValues) { apv.setScanResult(scanResult); } } }
new AnnotationParameterValue(methodName, annotationParamDefaultValue)); } else if (constantPoolStringEquals(attributeNameCpIdx, "Code")) { methodHasBody = true;
/** * @return The names of all {@link AnnotationParameterValue} objects in this list, by calling * {@link AnnotationParameterValue#getName()} for each item in the list. */ public List<String> getNames() { if (this.isEmpty()) { return Collections.emptyList(); } else { final List<String> classNames = new ArrayList<>(this.size()); for (final AnnotationParameterValue apv : this) { classNames.add(apv.getName()); } return classNames; } }
@Override public int compareTo(final AnnotationInfo o) { final int diff = getName().compareTo(o.getName()); if (diff != 0) { return diff; } if (annotationParamValues == null && o.annotationParamValues == null) { return 0; } else if (annotationParamValues == null) { return -1; } else if (o.annotationParamValues == null) { return 1; } else { for (int i = 0, max = Math.max(annotationParamValues.size(), o.annotationParamValues.size()); i < max; i++) { if (i >= annotationParamValues.size()) { return -1; } else if (i >= o.annotationParamValues.size()) { return 1; } else { final int diff2 = annotationParamValues.get(i).compareTo(o.annotationParamValues.get(i)); if (diff2 != 0) { return diff2; } } } } return 0; }