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); } } } } }
protected boolean isDubboService(ClassDoc classDoc) { AnnotationDesc[] annotations = classDoc.annotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].annotationType().qualifiedTypeName().equals("com.alibaba.dubbo.config.annotation.Service")) { AnnotationDesc.ElementValuePair[] elementValuePairs = annotations[i].elementValues(); for (AnnotationDesc.ElementValuePair elementValuePair : elementValuePairs) { if("protocol".equals(elementValuePair.element().name()) && "http".equals(protocolMap.get(elementValuePair.value().toString().replace("\"", "")))) { return false; } } return true; } } return false; }
@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; }
private String getExportedPackage(ClassDoc clz) { if (clz == null) { return ""; } PackageDoc cpkg = clz.containingPackage(); String pkg = cpkg == null ? "" : (cpkg.name()); for (AnnotationDesc a : clz.annotations()) { if (a.annotationType().name().equals("ExportPackage")) { for (AnnotationDesc.ElementValuePair p : a.elementValues()) { pkg = p.value().toString(); break; } } } pkg = pkg.replaceAll("\"", ""); return pkg; }
/** * Utility to filter a set of classes based on annotations. This method * will filter the given list of classes based on whether any of the * annotations given in the types argument are present. This looks only * at the class name of the annotation, not the fully-qualified name. * @param orig the original set of classes to filter * @param types the types of annotations to accept * @return the filtered list of classes */ protected static ClassDoc[] filterClasses(ClassDoc[] orig, String... types) { if (types == null || types.length == 0) { return new ClassDoc[0]; } List<String> in = Arrays.asList(types); List<ClassDoc> out = new ArrayList<ClassDoc>(); for (ClassDoc classDoc : orig) { for (AnnotationDesc annotation : classDoc.annotations()) { if (in.contains(annotation.annotationType().name())) { out.add(classDoc); break; } } } return out.toArray(new ClassDoc[0]); }
public String getAnnotationString(AnnotationDesc annot) { String result = "<span class='annotation'>"; String link = getItemLink(annot.annotationType()); result += link == null ? "@" + annot.annotationType().qualifiedName() : "<a href='" + link + "'>@" + annot.annotationType().name() + "</a>"; AnnotationDesc.ElementValuePair[] pairs = annot.elementValues(); if (pairs.length > 0) { result += " ("; for (int i = 0; i != pairs.length; i++) { if (i > 0) { result += ", "; } AnnotationDesc.ElementValuePair pair = pairs[i]; String link2 = getItemLink(pair.element().containingClass()); result += link2 == null ? pair.element().qualifiedName() : "<a href='" + link2 + "#" + getSignature(pair.element()) + "'>" + pair.element().name() + "</a>"; result += "=" + formatValue(pair.value()); } result += ")"; } return result + "</span>"; }
private void extractQueryParams(MethodDoc method, RestMethod restMethod) { Parameter[] params = method.parameters(); for (Parameter param : params) { AnnotationDesc queryParamAnnotation = getAnnotation(param.annotations(), "QueryParam"); if (queryParamAnnotation != null) { RestDocItem di = new RestDocItem(); di.setName(stripQuotes(queryParamAnnotation.elementValues()[0].value().toString())); di.setComment(getParamComment(method.paramTags(), param.name())); restMethod.getQueryParams().add(di); } } }
private void extractPathParams(MethodDoc method, RestMethod restMethod) { Parameter[] params = method.parameters(); for (Parameter param : params) { AnnotationDesc queryParamAnnotation = getAnnotation(param.annotations(), "PathParam"); if (queryParamAnnotation != null) { RestDocItem di = new RestDocItem(); di.setName(stripQuotes(queryParamAnnotation.elementValues()[0].value().toString())); di.setComment(getParamComment(method.paramTags(), param.name())); restMethod.getPathParams().add(di); } } }
public static PSOperatorWrapperDoc build(ClassDoc classDoc) { AnnotationDesc[] annotations = classDoc.annotations(); for (AnnotationDesc annotation : annotations) { AnnotationTypeDoc annotationType = annotation.annotationType(); if (Consts.OPERATOR_WRAPPER_ANNOTATION.equals(annotationType.toString())) { return new PSOperatorWrapperDoc(classDoc); } } return null; }
public static PSPipelineDoc build(ClassDoc classDoc, MethodDoc methodDoc) { AnnotationDesc[] annotations = methodDoc.annotations(); for (AnnotationDesc annotation : annotations) { AnnotationTypeDoc annotationType = annotation.annotationType(); if (Consts.TRANSFORMATION_ANNOTATION.equals(annotationType.toString())) { return new PSPipelineDoc(classDoc, methodDoc, annotation, TYPE_TRANSFORMATION); } else if (Consts.ACTION_ANNOTATION.equals(annotationType.toString())) { return new PSPipelineDoc(classDoc, methodDoc, annotation, TYPE_ACTION); } } return null; }
private PSItemFieldDoc(PSItemDoc psItemDoc, FieldDoc fieldDoc, AnnotationDesc annotation) { this.psItemDoc = psItemDoc; this.reference = fieldDoc.name(); this.name = fieldDoc.constantValue().toString(); this.description = fieldDoc.commentText().replace('\n', ' '); for (AnnotationDesc.ElementValuePair elementValuePair : annotation.elementValues()) { if ("type".equals(elementValuePair.element().name())) { Object typeValue = elementValuePair.value().value(); this.type = (Type) typeValue; } } }
public static PSItemFieldDoc build(PSItemDoc psItemDoc, FieldDoc fieldDoc) { AnnotationDesc[] annotations = fieldDoc.annotations(); for (AnnotationDesc annotation : annotations) { AnnotationTypeDoc annotationType = annotation.annotationType(); if (Consts.ITEM_FIELD_ANNOTATION.equals(annotationType.toString())) { return new PSItemFieldDoc(psItemDoc, fieldDoc, annotation); } } return null; }
public static boolean isValidPSItem(ClassDoc classDoc) { AnnotationDesc[] annotations = classDoc.annotations(); for (AnnotationDesc annotation : annotations) { AnnotationTypeDoc annotationType = annotation.annotationType(); if (Consts.ITEM_ANNOTATION.equals(annotationType.toString())) { return true; } } return false; }
protected boolean isProgramElementDocAnnotatedWith(ProgramElementDoc elementDoc, String annotation) { AnnotationDesc[] annotations = elementDoc.annotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].annotationType().qualifiedTypeName().equals(annotation)) { return true; } } return false; }
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 boolean start(RootDoc root) { for (ClassDoc d : root.classes()) { for (AnnotationDesc a : d.annotations()) { System.out.println(a.annotationType()); } } return true; }
/** * Instantiates a new Domain model. * */ private SubDomain(final PackageDoc doc, final AnnotationDesc desc) { this.codeName = doc.name(); for (AnnotationDesc.ElementValuePair member : desc.elementValues()) { switch (member.element().name()) { case "name": this.title = getString(member); break; case "description": this.description = getString(member); break; default: } } this.links = Arrays.stream(doc.annotations()) .filter(ad -> isAnnotatedAsLink(ad.annotationType())) .map(LinkModel::makeByLink) .collect(Collectors.toList()); this.links.addAll(Arrays.stream(doc.annotations()) .filter(ad -> isAnnotatedAsLinks(ad.annotationType())) .map(LinkModel::makeByLinks) .flatMap(Collection::stream) .collect(Collectors.toList()) ); this.concepts = new ArrayList<>(); }
/** * Make by optional. * * @param aPackage the a package * @return the optional */ static Optional<SubDomain> makeBy(final PackageDoc aPackage) { final List<AnnotationDesc> types = Arrays.stream(aPackage.annotations()) .filter(ad -> isAnnotatedAsBoundedContext(ad.annotationType())) .collect(Collectors.toList()); switch (types.size()) { case 0: return Optional.empty(); case 1: return Optional.of(new SubDomain(aPackage, types.get(0))); default: throw new IllegalStateException("There are more than one BoundedContext annotations"); } }
private ConceptModel(final ClassDoc doc, final AnnotationDesc desk) { this.name = doc.simpleTypeName(); for (AnnotationDesc.ElementValuePair member : desk.elementValues()) { switch (member.element().name()) { case "name": this.title = getString(member); break; case "description": this.description = getString(member); break; default: } } }
/** * Make by optional. * * @param doc the doc * @return the optional */ static Optional<ConceptModel> makeBy(final ClassDoc doc) { final Optional<AnnotationDesc> desc = conceptAnnotation(doc); return desc.isPresent() ? Optional.of(new ConceptModel(doc, desc.get())) : Optional.empty(); }
private LinkModel(final AnnotationDesc desc) { for (AnnotationDesc.ElementValuePair member : desc.elementValues()) { switch (member.element().name()) { case "related": this.related = getString(member).toLowerCase(); break; case "label": this.label = getString(member); break; default: } } }
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; }
@Test public void testIssue37_packagePrivateClassesDefaultValue() { UMLDocletConfig config = new UMLDocletConfig(new String[0][], mock(DocErrorReporter.class)); ClassDoc packagePrivateClassDoc = mock(ClassDoc.class); when(packagePrivateClassDoc.isPackagePrivate()).thenReturn(true); when(packagePrivateClassDoc.tags(anyString())).thenReturn(new Tag[0]); when(packagePrivateClassDoc.annotations()).thenReturn(new AnnotationDesc[0]); assertThat(config.includeClass(packagePrivateClassDoc), is(false)); }
static Optional<AnnotationDesc> annotationNamed( ProgramElementDoc doc, String annotationName) { for (AnnotationDesc a : doc.annotations()) { if (annotationName.equals(a.annotationType().qualifiedTypeName())) { return Optional.of(a); } } return Optional.absent(); }
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; }
public static AnnotationDesc findAnnotation(final AnnotationDesc[] annotations, final Class<?>... classes) { if (null != annotations && null != classes) { for (final AnnotationDesc annotation : annotations) { AnnotationTypeDoc docAnnotation = annotation.annotationType(); for (final Class<?> clazz : classes) { if (docAnnotation.qualifiedName().equals(clazz.getName())) { return annotation; } } } } return null; }
private Set<String> getMethodsValue(final AnnotationDesc[] annotations) { Set<String> result = new HashSet<String>(); if (null != DocletUtility.findAnnotation(annotations, GET.class)) { result.add("GET"); } if (null != DocletUtility.findAnnotation(annotations, POST.class)) { result.add("POST"); } if (null != DocletUtility.findAnnotation(annotations, PUT.class)) { result.add("PUT"); } if (null != DocletUtility.findAnnotation(annotations, DELETE.class)) { result.add("DELETE"); } if (null != DocletUtility.findAnnotation(annotations, HEAD.class)) { result.add("HEAD"); } 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; }
private String getPathValue(final AnnotationDesc[] annotations) { AnnotationDesc annotation = DocletUtility.findAnnotation(annotations, Path.class); if (null != annotation) { String value = (String) DocletUtility.getAnnotationValue(annotation); if (null != value) { return value.toString(); } } return null; }
/** * Filters the included set of classes by checking whether the given class matches the '-annotated' option. * * @param doc the class documentation. * @param annotation the annotation to match. * @return <code>true</code> if the class should be included; <code>false</code> otherwise. */ private static boolean filterAnnotated(ClassDoc doc, String annotation) { AnnotationDesc[] annotations = doc.annotations(); for (AnnotationDesc i : annotations) { if (annotation.equals(i.annotationType().qualifiedName())) return true; } return false; }
/** * Returns the XML node corresponding to the specified ClassDoc. * * @param classDoc The class to transform. */ private static XMLNode toAnnotationsNode(AnnotationDesc[] annotations) { if (annotations.length < 1) return null; XMLNode node = new XMLNode("annotations"); for (AnnotationDesc annotation : annotations) { node.child(toAnnotationNode(annotation)); } return node; }
/** * * @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; }
private String getExportedName(MethodDoc cd) { String ename = cd.name(); for (AnnotationDesc a : cd.annotations()) { if (a.annotationType().name().equals("Export")) { for (AnnotationDesc.ElementValuePair p : a.elementValues()) { ename = p.value().toString(); break; } } } return ename.replaceAll("\"", ""); }
private boolean isExportable(ConstructorDoc cd) { boolean export = isExported(cd.containingClass()); for (AnnotationDesc a : cd.annotations()) { if (a.annotationType().name().equals("Export")) { export = true; } if (a.annotationType().name().equals("NoExport")) { export = false; } } return export; }
private boolean isExportable(MethodDoc cd) { boolean export = isExported(cd.containingClass()); for (AnnotationDesc a : cd.annotations()) { if (a.annotationType().name().equals("Export")) { export = true; } if (a.annotationType().name().equals("NoExport")) { export = false; } } return export; }