protected void processAnnotations(AnnotationDesc annotation, APIParameter apiParameter) { if (annotation.annotationType().qualifiedName().startsWith("org.springframework.web.bind.annotation.")) { for (ElementValuePair pair : annotation.elementValues()) { if (pair.element().name().equals("value") || pair.element().name().equals("name")) { if (pair.value() != null) { apiParameter.setName(pair.value().toString().replace("\"", "")); } } if (pair.element().name().equals("required")) { if (pair.value().value().equals(true)) { apiParameter.setParameterOccurs(ParameterOccurs.REQUIRED); } else { apiParameter.setParameterOccurs(ParameterOccurs.OPTIONAL); } } } } }
@Override protected RequestMapping parseRequestMapping(MethodDoc method) { RequestMapping mapping = new RequestMapping(); mapping.setContainerName(method.containingClass().simpleTypeName()); AnnotationDesc[] annotations = method.annotations(); String url = method.toString().replaceFirst( method.containingClass().qualifiedName() + ".", ""); for (int i = 0; i < annotations.length; i++) { if (annotations[i].annotationType().name().equals("WebMethod")) { for (ElementValuePair p : annotations[i].elementValues()) { if (p.element().name().equals("operationName")) { url = url.replace(method.name(), p.value().value() .toString().replace("\"", "")); } } } } mapping.setUrl(url); mapping.setTooltip(method.containingClass().simpleTypeName()); mapping.setContainerName(method.containingClass().simpleTypeName()); return mapping; }
protected String getFieldValidatorDesc(FieldDoc fieldDoc) { StringBuilder strBuilder = new StringBuilder(); for (AnnotationDesc annotationDesc : fieldDoc.annotations()) { if (annotationDesc.annotationType().qualifiedTypeName().startsWith("org.hibernate.validator.constraints") || annotationDesc.annotationType().qualifiedTypeName().startsWith("javax.validation.constraints") || annotationDesc.annotationType().qualifiedTypeName().startsWith("lombok.NonNull")) { strBuilder.append("@"); strBuilder.append(annotationDesc.annotationType().name()); if (annotationDesc.elementValues().length > 0) { strBuilder.append("("); boolean isFirstElement = true; for (AnnotationDesc.ElementValuePair elementValuePair : annotationDesc.elementValues()) { if (!isFirstElement) { strBuilder.append(","); } strBuilder.append(elementValuePair.element().name()); strBuilder.append("="); strBuilder.append( net.winroad.wrdoclet.utils.Util.decodeUnicode(elementValuePair.value().toString())); isFirstElement = false; } strBuilder.append(")"); } strBuilder.append(" "); } } return strBuilder.toString(); }
@Override protected APIParameter getOutputParam(MethodDoc method) { APIParameter apiParameter = null; if (method.returnType() != null) { apiParameter = new APIParameter(); AnnotationDesc[] annotations = method.annotations(); boolean isResNameCustomized = false; for (int i = 0; i < annotations.length; i++) { if (annotations[i].annotationType().name().equals("WebResult")) { for (ElementValuePair p : annotations[i].elementValues()) { if (p.element().name().equals("name")) { apiParameter.setName(p.value().value().toString()); isResNameCustomized = true; } } } } if (!isResNameCustomized) { apiParameter.setName("return"); } apiParameter.setParameterOccurs(ParameterOccurs.REQUIRED); apiParameter.setType(this.getTypeName(method.returnType(), false)); for (Tag tag : method.tags("return")) { apiParameter.setDescription(tag.text()); } HashSet<String> processingClasses = new HashSet<String>(); apiParameter.setFields(this.getFields(method.returnType(), ParameterType.Response, processingClasses)); apiParameter.setHistory(this.getModificationHistory(method .returnType())); } return apiParameter; }
public static Object getAnnotationValue(final AnnotationDesc annotation, final String name) { for (final ElementValuePair elementValuePair : annotation.elementValues()) { if (elementValuePair.element().name().equals(name)) { return elementValuePair.value().value(); } } return null; }
/** * * @return an "annotation" XML node for the annotation. */ private static XMLNode toAnnotationNode(AnnotationDesc annotation) { if (annotation == null) return null; XMLNode node = new XMLNode("annotation"); node.attribute("name", annotation.annotationType().name()); for (ElementValuePair pair : annotation.elementValues()) { node.child(toPairNode(pair)); } return node; }
/** * * @return an "element" XML node for the element value pair. */ private static XMLNode toPairNode(ElementValuePair pair) { if (pair == null) return null; XMLNode node = new XMLNode("element"); AnnotationTypeElementDoc element = pair.element(); node.attribute("name", element.name()); node.child(toComment(element)); node.child(toAnnotationValueNode(pair.value())); return node; }
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; }
/** * Get annotation value. * * @returns the value or <code>null</code> if key was not found. */ private String getValue(AnnotationDesc annotation, String key) { for (ElementValuePair pair : annotation.elementValues()) { if (pair.element().name().equals(key)) { // double call to value is correct as this returns the actual // value object. return pair.value().value().toString(); } } return null; }
/** * Method to return the String annotation value, that belongs to some key * * @param annotation * @param key * @return the value, that belongs to the key or null, if no such exists */ public static String getAnnotationValueString(AnnotationDesc annotation, String key) { ElementValuePair[] evp = annotation.elementValues(); for (ElementValuePair e : evp) { if (e.element().toString().equals(key)) { return e.value().toString().substring(1, e.value().toString().length() - 1); } } return null; }
/** * Method to return the Double annotation value, that belongs to some key * * @param annotation * @param key * @return the value, that belongs to the key or null, if no such exists */ public static double getAnnotationValueDouble(AnnotationDesc annotation, String key) throws NumberFormatException { ElementValuePair[] evp = annotation.elementValues(); for (ElementValuePair e : evp) { if (e.element().toString().equals(key)) { return Double.parseDouble(e.value().toString()); } } //to indicate, that nothing was found return Double.MIN_VALUE; }
/** * Method to return the boolean annotation value, that belongs to some key * * @param annotation * @param key * @return the value, that belongs to the key or null, if no such exists */ public static boolean getAnnotationValueBoolean(AnnotationDesc annotation, String key) throws NumberFormatException { ElementValuePair[] evp = annotation.elementValues(); for (ElementValuePair e : evp) { if (e.element().toString().equals(key)) { return Boolean.parseBoolean(e.value().toString()); } } //default value of axis is true return true; }
/** * * @return an "element" XML node for the element value pair. */ private static XMLNode toPairNode(ElementValuePair pair) { if (pair == null) return null; XMLNode node = new XMLNode("element"); AnnotationTypeElementDoc element = pair.element(); node.attribute("name", element.name()); node.child(toShortComment(element)); node.child(toComment(element)); node.child(toAnnotationValueNode(pair.value())); return node; }
void renderDocsFor(Crawl crawl, Configurable c, File outDir) throws IOException { Element e; { Element.Builder eb = Element.newBuilder(); eb.setClassName(c.configurableClass.qualifiedName()); String commentText = c.configurableClass.commentText(); if (!Strings.isNullOrEmpty(commentText)) { eb.setCommentHtml(commentToHtml(commentText)); } eb.setIsEnum(c.configurableClass.isEnum()); eb.setIsMojo(c.isMojo); if (c.isMojo) { String goal = null; Optional<AnnotationDesc> mojoAnnot = annotationNamed( c.configurableClass, MOJO_ANNOTATION_NAME); if (mojoAnnot.isPresent()) { for (ElementValuePair p : mojoAnnot.get().elementValues()) { if ("name".equals(p.element().name())) { goal = (String) p.value().value(); } } } if (goal != null) { eb.setGoal(goal); } } eb.addAllTagName(c.tagNames); // Present in lexicographic order. for (String paramName : Sets.newTreeSet(c.params.keySet())) { ParameterInfo pi = c.params.get(paramName); Parameter.Builder pb = Parameter.newBuilder(); pb.setName(pi.name); if (pi.field.isPresent()) { FieldDoc fd = pi.field.get(); pb.setField(fd.containingClass().qualifiedName() + "#" + fd.name()); } if (pi.setter.isPresent()) { MethodDoc s = pi.setter.get(); pb.setMethod( s.containingClass().qualifiedName() + "#" + s.name() + s.flatSignature()); } pb.setSourcePosition(pi.source().position().toString()); Type t = pi.getType(); pb.setType(t.simpleTypeName()); Optional<Configurable> tc = crawl.foundConfigurable(pi.source(), t); if (tc.isPresent()) { pb.setTypeUrl(urlFor(tc.get())); } String pCommentText = pi.getCommentText(); if (!Strings.isNullOrEmpty(pCommentText)) { pb.setCommentHtml(commentToHtml(pCommentText)); } eb.addParam(pb); } e = eb.build(); } ImmutableMap<String, Object> data = ImmutableMap.<String, Object>of("e", e); SoySauce.Renderer renderer = soySauce .renderTemplate("com.google.closure.doclet.soy.Configurable") .setData(data) ; Continuation<String> renderedHtml = renderer.render(); while (!renderedHtml.result().isDone()) { renderedHtml = renderedHtml.continueRender(); } File outFile = new File(outDir.toURI().resolve(urlFor(c))); CharSink dest = Files.asCharSink(outFile, Charsets.UTF_8); try (Writer out = dest.openBufferedStream()) { out.write(renderedHtml.get()); } }