final NamedValueType namedValueType = new NamedValueType(); namedValueType.setName(elementValuePair.element().name()); namedValueType.setValue(elementValuePair.value().value().toString()); annotationDocType.getAttributeDocs().add(namedValueType);
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; }
/** * 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; }
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 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(); }
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 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()); }
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 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; }
/** * Determines and returns the value of an {@link AnnotationValue}. * * @return See {@link #getAnnotationElementValue(AnnotationDesc, String)} */ @Nullable public static Object getAnnotationValue(AnnotationValue value) { Object o = value.value(); if (o instanceof AnnotationValue[]) { AnnotationValue[] avs = (AnnotationValue[]) o; Object[] oa = new Object[avs.length]; for (int i = 0; i < avs.length; i++) { oa[i] = Annotations.getAnnotationValue(avs[i]); } return oa; } return o; } }
/** * Determines and returns the value of an {@link AnnotationValue}. * * @return See {@link #getAnnotationElementValue(AnnotationDesc, String)} */ @Nullable public static Object getAnnotationValue(AnnotationValue value) { Object o = value.value(); if (o instanceof AnnotationValue[]) { AnnotationValue[] avs = (AnnotationValue[]) o; Object[] oa = new Object[avs.length]; for (int i = 0; i < avs.length; i++) { oa[i] = Annotations.getAnnotationValue(avs[i]); } return oa; } return o; } }
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; }
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; }
Object val = evp.value().value(); AnnotationValue[] vals = (AnnotationValue[]) val; List<ClassDoc> res = new ArrayList<>(); for (AnnotationValue annotationVal : vals) { AnnotationDesc subAnnotation = (AnnotationDesc) annotationVal.value(); ClassDoc classDoc = getAnnotationClassDocValue(subAnnotation, "value"); if (classDoc != null) {
/** * 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> 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 Content annotationValueToContent(AnnotationValue annotationValue) { if (annotationValue.value() instanceof Type) { Type type = (Type) annotationValue.value(); if (type.asClassDoc() != null) { LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, LinkInfoImpl.Kind.ANNOTATION, type); linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ? type.typeName() : type.qualifiedTypeName()) + type.dimension() + ".class"); return getLink(linkInfo); } else { return new StringContent(type.typeName() + type.dimension() + ".class"); } } else if (annotationValue.value() instanceof AnnotationDesc) { List<Content> list = getAnnotations(0, new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()}, false); ContentBuilder buf = new ContentBuilder(); for (Content c: list) { buf.addContent(c); } return buf; } else if (annotationValue.value() instanceof MemberDoc) { return getDocLink(LinkInfoImpl.Kind.ANNOTATION, (MemberDoc) annotationValue.value(), ((MemberDoc) annotationValue.value()).name(), false); } else { return new StringContent(annotationValue.toString()); } }