final String typeName = annotationDesc.annotationType().qualifiedName(); annotationDocType.setAnnotationTypeName(typeName); for (final ElementValuePair elementValuePair : annotationDesc.elementValues()) { final NamedValueType namedValueType = new NamedValueType(); namedValueType.setName(elementValuePair.element().name());
ElementValuePair[] paramNames = annotationDesc.elementValues(); AnnotationValue[] statusCodes = (AnnotationValue[])paramNames[0].value().value(); if(statusCodes==null||statusCodes.length==0) { return statusCodeValue; } for(AnnotationValue statusCode:statusCodes) { AnnotationDesc anoDesc=(AnnotationDesc)statusCode.value(); if(anoDesc==null) { return statusCodeValue; } String key=(String)anoDesc.elementValues()[0].value().value(); String value=(String)anoDesc.elementValues()[1].value().value(); }
private static boolean isSupported( AnnotationDesc[] annotationDescs ) { for ( AnnotationDesc annotationDesc : annotationDescs ) { if ( annotationDesc.toString().contains( FACET_ANNOTATION ) ) { if ( annotationDesc.elementValues()[0].value().value().equals( UNSUPPORTED ) ) { return false; } } } return true; }
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()); }
static Set<String> getMethodGroups(MethodDoc m) { Set<String> result = getGroups(m); result.addAll(getGroups(m.containingClass())); return result; } static Set<String> getGroups(ProgramElementDoc m) { Set<String> result = new HashSet<String>(); for(AnnotationDesc a: m.annotations()) { if (a.annotationType().name().equals("Test")) { for(ElementValuePair ev : a.elementValues()) { if (ev.element().name().equals("groups")) { String value = ev.value().toString(); StringTokenizer tokenizer = new StringTokenizer(value, "{}\", "); while (tokenizer.hasMoreElements()) { result.add(tokenizer.nextToken()); } } } } } return result; }
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 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 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); } }
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; }
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 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; }
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; } }
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; }
for (AnnotationDesc.ElementValuePair evp : annotation.elementValues()) { if (evp.element().name().equals(key)) { Object val = evp.value().value();
/** * 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; }
return null; for (AnnotationDesc.ElementValuePair evp : annotation.elementValues()) { if (evp.element().name().equals(key)) { Object val = evp.value().value();
/** * 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 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; }