annotationValueArray = new AnnotationParamValueWrapper[n]; for (int i = 0; i < n; i++) { annotationValueArray[i] = new AnnotationParamValueWrapper( Array.get(annotationParamValue, i));
/** * 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); } }
for (int i = 0; i < annotationValueArray.length; i++) { if (annotationValueArray[i] != null) { annotationValueObjects[i] = annotationValueArray[i].get();
void toStringParamValueOnly(final StringBuilder buf) { if (paramValue == null) { buf.append("null"); } else { final Object paramVal = paramValue.get(); final Class<? extends Object> valClass = paramVal.getClass(); if (valClass.isArray()) { buf.append('{'); for (int j = 0, n = Array.getLength(paramVal); j < n; j++) { if (j > 0) { buf.append(", "); } final Object elt = Array.get(paramVal, j); buf.append(elt == null ? "null" : elt.toString()); } buf.append('}'); } else if (paramVal instanceof String) { buf.append('"'); buf.append(paramVal.toString().replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r")); buf.append('"'); } else if (paramVal instanceof Character) { buf.append('\''); buf.append(paramVal.toString().replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r")); buf.append('\''); } else { buf.append(paramVal.toString()); } } }
/** * Get the annotation parameter value. * * @return The annotation parameter value. May be one of the following types: * <ul> * <li>String for string constants * <li>A wrapper type, e.g. Integer or Character, for primitive-typed constants * <li>{@link Object}[] for array types (and then the array element type may be one of the types in * this list) * <li>{@link AnnotationEnumValue}, for enum constants (this wraps the enum class and the string * name of the constant) * <li>{@link AnnotationClassRef}, for Class references within annotations (this wraps the name of * the referenced class) * <li>{@link AnnotationInfo}, for nested annotations * </ul> */ public Object getParamValue() { return paramValue == null ? null : paramValue.get(); }
@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); } } }
@Override void setScanResult(final ScanResult scanResult) { if (paramValue != null) { paramValue.setScanResult(scanResult); } }
/** * @param paramName * The annotation paramater name. * @param paramValue * The annotation parameter value. */ public AnnotationParamValue(final String paramName, final Object paramValue) { this.paramName = paramName; this.paramValue = new AnnotationParamValueWrapper(paramValue); }