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);
/** * Parse the elements of an annotation * * @param annotationTypeElementDoc * A AnnotationTypeElementDoc instance * @return the annotation element node */ protected AnnotationElement parseAnnotationTypeElementDoc(AnnotationTypeElementDoc annotationTypeElementDoc) { AnnotationElement annotationElementNode = objectFactory.createAnnotationElement(); annotationElementNode.setName(annotationTypeElementDoc.name()); annotationElementNode.setQualified(annotationTypeElementDoc.qualifiedName()); annotationElementNode.setType(parseTypeInfo(annotationTypeElementDoc.returnType())); AnnotationValue value = annotationTypeElementDoc.defaultValue(); if (value != null) { annotationElementNode.setDefault(value.toString()); } return annotationElementNode; }
public void writeAnnotationTable(AnnotationDesc annotation, StringBuilder sb) { AnnotationTypeElementDoc[] annotationElements = annotation.annotationType().elements(); if (annotationElements.length > 0) { Map<String, String> elementValueMap = createElementValueMap(annotation); sb.append(String.format("\t\t%1$20s %2$20s %3$20s\n", "NAME", "VALUE", "DEFAULT")); for (AnnotationTypeElementDoc annotationElement : annotationElements) { sb.append(String.format("\t\t%1$20s %2$20s %3$20s\n", annotationElement.name(), elementValueMap.get(annotationElement.name()), annotationElement.defaultValue())); } } }
annotationArgumentNode.setName(elementValuesPair.element().name()); Type annotationArgumentType = elementValuesPair.element().returnType(); annotationArgumentNode.setType(parseTypeInfo(annotationArgumentType)); annotationArgumentNode.setPrimitive(annotationArgumentType.isPrimitive());
/** * Filter the annotation type members and return either the required * members or the optional members, depending on the value of the * required parameter. * * @param doc The annotation type to process. * @param required * @return the annotation type members and return either the required * members or the optional members, depending on the value of the * required parameter. */ private AnnotationTypeElementDoc[] filter(AnnotationTypeDoc doc, boolean required) { AnnotationTypeElementDoc[] members = doc.elements(); List<AnnotationTypeElementDoc> targetMembers = new ArrayList<AnnotationTypeElementDoc>(); for (int i = 0; i < members.length; i++) { if ((required && members[i].defaultValue() == null) || ((!required) && members[i].defaultValue() != null)){ targetMembers.add(members[i]); } } return targetMembers.toArray(new AnnotationTypeElementDoc[]{}); }
/** * Filter the annotation type members and return either the required * members or the optional members, depending on the value of the * required parameter. * * @param doc The annotation type to process. * @param required * @return the annotation type members and return either the required * members or the optional members, depending on the value of the * required parameter. */ private AnnotationTypeElementDoc[] filter(AnnotationTypeDoc doc, boolean required) { AnnotationTypeElementDoc[] members = doc.elements(); List<AnnotationTypeElementDoc> targetMembers = new ArrayList<AnnotationTypeElementDoc>(); for (int i = 0; i < members.length; i++) { if ((required && members[i].defaultValue() == null) || ((!required) && members[i].defaultValue() != null)){ targetMembers.add(members[i]); } } return targetMembers.toArray(new AnnotationTypeElementDoc[]{}); }
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(); }
/** * {@inheritDoc} */ public void addDefaultValueInfo(MemberDoc member, Content annotationDocTree) { if (((AnnotationTypeElementDoc) member).defaultValue() != null) { Content dt = HtmlTree.DT(writer.getResource("doclet.Default")); Content dl = HtmlTree.DL(dt); Content dd = HtmlTree.DD(new StringContent( ((AnnotationTypeElementDoc) member).defaultValue().toString())); dl.addContent(dd); annotationDocTree.addContent(dl); } }
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()); }
/** * {@inheritDoc} */ public void writeDefaultValueInfo(MemberDoc member) { if (((AnnotationTypeElementDoc) member).defaultValue() != null) { writer.printMemberDetailsListStartTag(); writer.dd(); writer.dl(); writer.dt(); writer.strong(ConfigurationImpl.getInstance(). getText("doclet.Default")); writer.dtEnd(); writer.dd(); writer.print(((AnnotationTypeElementDoc) member).defaultValue()); writer.ddEnd(); writer.dlEnd(); writer.ddEnd(); } }
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; }
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; }
String name = val.element().name(); if (vals.length == 1 && name.equals("value")) { sb.append(val.value());
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; } }
LinkInfoImpl.CONTEXT_ANNOTATION, pairs[j].element(), pairs[j].element().name(), false ) );
if (evp.element().name().equals(key)) { Object val = evp.value().value(); AnnotationValue[] vals = (AnnotationValue[]) val;
/** * 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; }