/** * * @return an "value" or "array" XML node for the annotation value. */ private static XMLNode toAnnotationValueNode(AnnotationValue value) { if (value == null) return null; XMLNode node = null; Object o = value.value(); Class<?> c = o.getClass(); if (c.isArray()) { node = new XMLNode("array"); Object[]a = (Object[])o; for (Object i : a) { if (i instanceof AnnotationValue) { node.child(toAnnotationValueNode((AnnotationValue)i)); } else { System.err.println("Unexpected annotation value type"+i); } } } else { node = new XMLNode("value"); node.attribute("type", getAnnotationValueType(o)); node.attribute("value", o.toString()); } return node; }
private static List<LinkModel> makeByLinks(final AnnotationDesc desc) { final ArrayList<LinkModel> result = new ArrayList<>(); for (AnnotationDesc.ElementValuePair member : desc.elementValues()) if ("value".equals(member.element().name())) { Arrays.stream((AnnotationValue[]) member.value().value()) .map(AnnotationValue::value) .map(AnnotationDesc.class::cast) .forEach(ad -> result.add(new LinkModel(ad))); } return result; }
private Set<String> getProducesValue(final AnnotationDesc[] annotations) { Set<String> result = new HashSet<String>(); AnnotationDesc annotation = DocletUtility.findAnnotation(annotations, Produces.class); if (null != annotation) { AnnotationValue[] values = (AnnotationValue[]) DocletUtility.getAnnotationValue(annotation); if (null != values) { for (AnnotationValue value : values) { result.add(value.value().toString()); } } } return result; }
private Set<String> getConsumesValue(final AnnotationDesc[] annotations) { Set<String> result = new HashSet<String>(); AnnotationDesc annotation = DocletUtility.findAnnotation(annotations, Consumes.class); if (null != annotation) { AnnotationValue[] values = (AnnotationValue[]) DocletUtility.getAnnotationValue(annotation); if (null != values) { for (AnnotationValue value : values) { result.add(value.value().toString()); } } } return result; }
/** * @return the full JSON for the given annotation type */ protected JSONObject processAnnotationValue(AnnotationValue annoValue) { if (annoValue == null) { return null; } JSONObject retMe = new JSONObject(); retMe.put( "toString", annoValue.toString() ); return retMe; }
private static List<String> resolveAnnotationValue(AnnotationValue value) { List<String> retVal = new ArrayList<String>(); /** * TODO using recursion here is probably flawed. */ if (value.value() instanceof AnnotationValue[]) for (AnnotationValue annotationValue : (AnnotationValue[])value.value()) retVal.addAll(resolveAnnotationValue(annotationValue)); else { retVal.add(value.value().toString()); } return retVal; }
/** * Parse the elements of an annotation * * @param element * A AnnotationTypeElementDoc instance * @return the annotation element node */ protected AnnotationElement parseAnnotationTypeElementDoc(AnnotationTypeElementDoc annotationTypeElementDoc) { AnnotationElement annotationElementNode = objectFactory.createAnnotationElement(); annotationElementNode.setName(annotationTypeElementDoc.name()); annotationElementNode.setIdentifier(parseIdentifier((Doc) annotationTypeElementDoc)); annotationElementNode.setId(annotationTypeElementDoc.name()); annotationElementNode.setFull(annotationTypeElementDoc.qualifiedName()); annotationElementNode.setComment(parseComment(annotationTypeElementDoc)); AnnotationValue value = annotationTypeElementDoc.defaultValue(); if (value != null) { annotationElementNode.setDefault(value.toString()); } Tag[] tags; SeeTag[] seeTags; tags = annotationTypeElementDoc.tags("@deprecated"); if (tags.length > 0) { annotationElementNode.setDeprecated(parseComment(tags[0])); } tags = annotationTypeElementDoc.tags("@since"); if (tags.length > 0) { annotationElementNode.setSince(tags[0].text()); } tags = annotationTypeElementDoc.tags("@version"); if (tags.length > 0) { annotationElementNode.setVersion(tags[0].text()); } Return returnNode = objectFactory.createReturn(); tags = annotationTypeElementDoc.tags("@return"); if (tags.length > 0) { returnNode.setComment(parseComment(tags[0])); } returnNode.setType(parseTypeInfo(annotationTypeElementDoc.returnType())); annotationElementNode.setReturn(returnNode); seeTags = annotationTypeElementDoc.seeTags(); for (int i = 0; i < seeTags.length; i++) { annotationElementNode.getLink().add(parseLink(seeTags[i])); } return annotationElementNode; }