/** * Add a set of default values, stored in an annotation class' classfile, to a concrete instance of that * annotation. The defaults are overwritten by any annotation parameter values in the concrete annotation. * * @param defaultAnnotationParamValues * the default parameter values for the annotation. */ void addDefaultValues(final List<AnnotationParamValue> defaultAnnotationParamValues) { if (defaultAnnotationParamValues != null && !defaultAnnotationParamValues.isEmpty()) { if (this.annotationParamValues == null || this.annotationParamValues.isEmpty()) { this.annotationParamValues = new ArrayList<>(defaultAnnotationParamValues); } else { // Overwrite defaults with non-defaults final Map<String, Object> allParamValues = new HashMap<>(); for (final AnnotationParamValue annotationParamValue : defaultAnnotationParamValues) { allParamValues.put(annotationParamValue.paramName, annotationParamValue.paramValue.get()); } for (final AnnotationParamValue annotationParamValue : this.annotationParamValues) { allParamValues.put(annotationParamValue.paramName, annotationParamValue.paramValue.get()); } this.annotationParamValues.clear(); for (final Entry<String, Object> ent : allParamValues.entrySet()) { this.annotationParamValues.add(new AnnotationParamValue(ent.getKey(), ent.getValue())); } } } if (this.annotationParamValues != null) { Collections.sort(this.annotationParamValues); } }
/** 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); }
.add(new AnnotationParamValue(methodName, annotationParamDefaultValue)); } else { skip(attributeLength);