for (final ElementValuePair elementValuePair : annotationDesc.elementValues()) { final NamedValueType namedValueType = new NamedValueType(); namedValueType.setName(elementValuePair.element().name()); namedValueType.setValue(elementValuePair.value().value().toString()); annotationDocType.getAttributeDocs().add(namedValueType);
AnnotationValue annotationValue = pairs[j].value(); List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>(); if (annotationValue.value() instanceof AnnotationValue[]) { (AnnotationValue[]) (pairs[0].value()).value(); List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>(); annotationTypeValues.addAll(Arrays.asList(annotationArray));
for ( ElementValuePair elementValuePair : annotationDesc.elementValues() ) { final NamedValueType namedValueType = new NamedValueType(); namedValueType.setName( elementValuePair.element().name() ); namedValueType.setValue( elementValuePair.value().value().toString() ); annotationDocType.getAttributeDocs().add( namedValueType );
annotationArgumentNode.setName(elementValuesPair.element().name()); Type annotationArgumentType = elementValuesPair.element().returnType(); annotationArgumentNode.setType(parseTypeInfo(annotationArgumentType)); annotationArgumentNode.setPrimitive(annotationArgumentType.isPrimitive()); annotationArgumentNode.setArray(annotationArgumentType.dimension().length() > 0); Object objValue = elementValuesPair.value().value(); if (objValue instanceof AnnotationValue[]) { for (AnnotationValue annotationValue : (AnnotationValue[]) objValue) {
/** * Check if the annotation contains an array of annotation as a value. This * check is to verify if a repeatable type annotation is present or not. * * @param pairs annotation type element and value pairs * * @return true if the annotation contains an array of annotation as a value. */ private boolean isAnnotationArray(AnnotationDesc.ElementValuePair[] pairs) { AnnotationValue annotationValue; for (int j = 0; j < pairs.length; j++) { annotationValue = pairs[j].value(); if (annotationValue.value() instanceof AnnotationValue[]) { AnnotationValue[] annotationArray = (AnnotationValue[]) annotationValue.value(); if (annotationArray.length > 1) { if (annotationArray[0].value() instanceof AnnotationDesc) { AnnotationTypeDoc annotationDoc = ((AnnotationDesc) annotationArray[0].value()).annotationType(); isContainerDocumented = true; if (Util.isDocumentedAnnotation(annotationDoc)) { isAnnotationDocumented = true; } return true; } } } } return false; }
/** * This gets the values of an annotation as class docs * * @param qualifiedAnnotationType The FQN of the annotation * @param key The field name of the annotation to get * * @return The values or null if none were found */ public ClassDoc[] getAnnotationClassDocValues(String qualifiedAnnotationType, String key) { AnnotationDesc annotation = getAnnotation(qualifiedAnnotationType, false); if (annotation == null) { return null; } for (AnnotationDesc.ElementValuePair evp : annotation.elementValues()) { if (evp.element().name().equals(key)) { Object val = evp.value().value(); AnnotationValue[] vals = (AnnotationValue[]) val; if (vals != null && vals.length > 0) { ClassDoc[] res = new ClassDoc[vals.length]; int i = 0; for (AnnotationValue annotationVal : vals) { ClassDoc classDoc = (ClassDoc) annotationVal.value(); res[i++] = classDoc; } return res; } } } return null; }
private static Map<String, String> getFieldDocOverrides(ClassDoc classDoc) { Map<String, String> overrides = new HashMap<String, String>(); AnnotationDesc annoDesc = getAnnotation(classDoc, ObjectSchemaAttributes.class); if (null != annoDesc) { for (AnnotationDesc.ElementValuePair pair : annoDesc.elementValues()) { if (pair.element().name().equals("docOverrides")) { AnnotationValue[] annoValues = (AnnotationValue[]) pair.value().value(); for (AnnotationValue annoValue : annoValues) { AnnotationDesc fieldOverrideAnno = (AnnotationDesc) annoValue.value(); String fieldName = (String) fieldOverrideAnno.elementValues()[0].value().value(); String desc = (String) fieldOverrideAnno.elementValues()[1].value().value(); overrides.put(fieldName, desc); } } } } return overrides; }
/** * Determines and returns the value of the named element. * <p> * This can be: * </p> * <ul> * <li>A wrapper for a primitive type</li> * <li>A string</li> * <li>A {@link Type} (representing a class literal)</li> * <li>A {@link FieldDoc} (representing an enum constant)</li> * <li>An {@link AnnotationDesc} (representing what??)</li> * <li>An array of any of these (including the case of nested arrays)</li> * </ul> */ @Nullable public static Object getAnnotationElementValue(AnnotationDesc annotationDesc, String elementName) { for (ElementValuePair evp : annotationDesc.elementValues()) { if (evp.element().name().equals(elementName)) { return Annotations.getAnnotationValue(evp.value()); } } return null; }
/** * Determines and returns the value of the named element. * <p> * This can be: * </p> * <ul> * <li>A wrapper for a primitive type</li> * <li>A string</li> * <li>A {@link Type} (representing a class literal)</li> * <li>A {@link FieldDoc} (representing an enum constant)</li> * <li>An {@link AnnotationDesc} (representing what??)</li> * <li>An array of any of these (including the case of nested arrays)</li> * </ul> */ @Nullable public static Object getAnnotationElementValue(AnnotationDesc annotationDesc, String elementName) { for (ElementValuePair evp : annotationDesc.elementValues()) { if (evp.element().name().equals(elementName)) { return Annotations.getAnnotationValue(evp.value()); } } return null; }
private static boolean isDeclarationTarget(AnnotationDesc targetAnno) { // The error recovery steps here are analogous to TypeAnnotations ElementValuePair[] elems = targetAnno.elementValues(); if (elems == null || elems.length != 1 || !"value".equals(elems[0].element().name()) || !(elems[0].value().value() instanceof AnnotationValue[])) return true; // error recovery AnnotationValue[] values = (AnnotationValue[])elems[0].value().value(); for (int i = 0; i < values.length; i++) { Object value = values[i].value(); if (!(value instanceof FieldDoc)) return true; // error recovery FieldDoc eValue = (FieldDoc)value; if (Util.isJava5DeclarationElementType(eValue)) { return true; } } return false; }
private void loadEvents() { AnnotationDesc eventsAnnotation = getAnnotation(classDoc, Events.class); if (eventsAnnotation == null) return; // Events has only a single attribute: value(), so we know its the first element // in the array. ElementValuePair pair = eventsAnnotation.elementValues()[0]; AnnotationValue annotationValue = pair.value(); AnnotationValue[] values = (AnnotationValue[]) annotationValue.value(); for (AnnotationValue eventValue : values) { String event = (String) eventValue.value(); int ws = event.indexOf(' '); String name = ws < 0 ? event : event.substring(0, ws); String description = ws < 0 ? "" : event.substring(ws + 1).trim(); events.put(name, description); } }
private void loadEvents() { AnnotationDesc eventsAnnotation = getAnnotation(classDoc, Events.class); if (eventsAnnotation == null) return; // Events has only a single attribute: value(), so we know its the first element // in the array. ElementValuePair pair = eventsAnnotation.elementValues()[0]; AnnotationValue annotationValue = pair.value(); AnnotationValue[] values = (AnnotationValue[]) annotationValue.value(); for (AnnotationValue eventValue : values) { String event = (String) eventValue.value(); int ws = event.indexOf(' '); String name = ws < 0 ? event : event.substring(0, ws); String description = ws < 0 ? "" : event.substring(ws + 1).trim(); events.put(name, description); } }
private static Map<String, String> getAnnotationValues(ProgramElementDoc source, Class annotationType) { AnnotationDesc annotation = getAnnotation(source, annotationType); if (annotation == null) return null; Map<String, String> result = CollectionFactory.newMap(); for (ElementValuePair pair : annotation.elementValues()) { result.put(pair.element().name(), pair.value().value().toString()); } return result; } }
private static Map<String, String> getAnnotationValues(ProgramElementDoc source, Class annotationType) { AnnotationDesc annotation = getAnnotation(source, annotationType); if (annotation == null) return null; Map<String, String> result = CollectionFactory.newMap(); for (ElementValuePair pair : annotation.elementValues()) { result.put(pair.element().name(), pair.value().value().toString()); } return result; } }
public Map<String, String> createElementValueMap(AnnotationDesc annotation) { AnnotationDesc.ElementValuePair[] elementValuePairs = annotation.elementValues(); Map<String, String> elementValueMap = new HashMap<>(); for (AnnotationDesc.ElementValuePair elementValuePair : elementValuePairs) { elementValueMap.put(elementValuePair.element().name(), elementValuePair.value().toString()); } return elementValueMap; }