private static String[] getOutputArgs(String[] args) { ArrayList<String> l = new ArrayList<String>(); for (String arg : args) { if (arg.startsWith("-a")) l.add(StringUtils.removeStart(arg, "-a")); } return l.toArray(new String[l.size()]); }
public String[] getDisplayHttpExamples() { ArrayList<String> l = new ArrayList<String>(); if (ArrayUtils.isNotEmpty(httpExamples)) { for (String example : httpExamples) { if (StringUtils.isNotBlank(example)) l.add(example); } } return l.toArray(new String[l.size()]); }
private static ApiDoc scanMethodDoc(ClassDoc classDoc, MethodDoc methodDoc) { String routePrefix = ""; // RoutePrefix for class for (AnnotationDesc annDesc : classDoc.annotations()) { if (RoutePrefix.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) { routePrefix = annotationToString(annDesc, "value", ""); break; } } AnnotationDesc[] annDescs = methodDoc.annotations(); if (ArrayUtils.isEmpty(annDescs)) return null; for (AnnotationDesc annDesc : annDescs) { if (IgnoreDocument.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) return null; } // RoutePrefix for method for (AnnotationDesc annDesc : annDescs) { if (RoutePrefix.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) { routePrefix = annotationToString(annDesc, "value", ""); break; } } Class httpExamplePackageClass = null; String[] routes = null; String[] httpMethods = {"GET", "POST"}; boolean deprecated = false; for (AnnotationDesc annDesc : annDescs) { if (Route.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) { for (AnnotationDesc.ElementValuePair annValue : annDesc.elementValues()) { String name = annValue.element().name(); if ("url".equals(name)) { routes = annotationToStringArray(annValue.value().value()); } else if ("method".equals(name)) { httpMethods = annotationToStringArray(annValue.value().value()); } } } if (Deprecated.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) deprecated = true; if (HttpExamplePackage.class.getName().equals(annDesc.annotationType().qualifiedTypeName())) { for (AnnotationDesc.ElementValuePair annValue : annDesc.elementValues()) { String name = annValue.element().name(); if ("value".equals(name)) { ClassDoc httpExamplePackageClassAnn = (ClassDoc) annValue.value().value(); httpExamplePackageClass = ClassHelper.forName(httpExamplePackageClassAnn.qualifiedTypeName()); } } } } if (routes == null) return null; if (httpExamplePackageClass == null) { annDescs = classDoc.annotations(); for (AnnotationDesc annDesc : annDescs) { if (HttpExamplePackage.class .getName() .equals(annDesc.annotationType().qualifiedTypeName())) { for (AnnotationDesc.ElementValuePair annValue : annDesc.elementValues()) { String name = annValue.element().name(); if ("value".equals(name)) { ClassDoc httpExamplePackageClassAnn = (ClassDoc) annValue.value().value(); httpExamplePackageClass = ClassHelper.forName(httpExamplePackageClassAnn.qualifiedTypeName()); } } } } } ApiDoc apiDoc = new ApiDoc(); apiDoc.group = getTag(methodDoc, GROUP_TAG, ""); apiDoc.routes = addRoutePrefix(routes, routePrefix); apiDoc.httpMethods = httpMethods; apiDoc.description = expandText(methodDoc.commentText()); apiDoc.login = parseBoolean(getTag(methodDoc, LOGIN_TAG, "y")); apiDoc.deprecated = deprecated; apiDoc.httpReturn = getTag(methodDoc, HTTP_RETURN, ""); apiDoc.remark = expandText(getTag(methodDoc, REMARK_TAG, "")); apiDoc.className = classDoc.qualifiedTypeName(); apiDoc.httpExamplePackageClass = httpExamplePackageClass; String[] httpExamples = expandTexts(getTags(methodDoc, HTTP_EXAMPLE_TAG)); for (int i = 0; i < httpExamples.length; i++) { String httpExample = httpExamples[i]; if (httpExample.startsWith("@")) { if (apiDoc.httpExamplePackageClass != null) { httpExamples[i] = VfsHelper.loadTextInClasspath( apiDoc.httpExamplePackageClass, StringUtils.removeStart(httpExample, "@")); } else { httpExamples[i] = ""; } } } apiDoc.httpExamples = httpExamples; ArrayList<ParamDoc> l = new ArrayList<ParamDoc>(); for (String httpParamTag : getTags(methodDoc, HTTP_PARAM_TAG)) { ParamDoc httpParamDoc = parseParamDoc(httpParamTag); if (httpParamDoc != null) l.add(httpParamDoc); } apiDoc.httpParams = l.toArray(new ParamDoc[l.size()]); return apiDoc; }