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);
private static Optional<String> summaryFromAnnotation(MethodDoc methodDoc) { return Stream.of(methodDoc.annotations()) .filter(annotation -> io.swagger.v3.oas.annotations.Operation.class.getName().equals(annotation.annotationType().qualifiedName())) .findFirst() .flatMap(a -> Stream.of(a.elementValues()) .filter(elementValuePair -> "summary".equals(elementValuePair.element().name())) .map(elementValuePair -> elementValuePair.value().value().toString()) .findFirst()); }
String name = val.element().name(); if (vals.length == 1 && name.equals("value")) { sb.append(val.value());
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 );
if (evp.element().name().equals(key)) { Object val = evp.value().value(); AnnotationValue[] vals = (AnnotationValue[]) val;
/** * 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; }
if (evp.element().name().equals(key)) { Object val = evp.value().value(); AnnotationValue[] vals = (AnnotationValue[]) val;
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 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; }
private ClassDoc getAnnotationClassDocValue(AnnotationDesc annotation, String key) { for (AnnotationDesc.ElementValuePair evp : annotation.elementValues()) { if (evp.element().name().equals(key)) { return (ClassDoc) evp.value().value(); } } return null; }
public static Object getAnnotationDescValue(AnnotationDesc annotationDesc, String name) { for (ElementValuePair elementValuePair : annotationDesc.elementValues()) { if (elementValuePair.element().name().equals(name)) { return elementValuePair.value().value(); } }; return null; }
private String getAnnotationValue(AnnotationDesc annotation, String... keys) { for (AnnotationDesc.ElementValuePair evp : annotation.elementValues()) { for (String key : keys) { if (evp.element().name().equals(key)) { String val = evp.value().value().toString(); val = val.trim(); return this.options.replaceVars(val); } } } return null; }
private static Optional<Object> getAnnotationParamValue(ElementValuePair[] elementValuePairs, String paramName) { for (ElementValuePair pair : elementValuePairs) { if (pair.element().name().equals(paramName)) { return Optional.of(pair.value().value()); } } return Optional.absent(); }