/** * Computes the string representation of this method * appropriate for the construction of a * java.rmi.server.Operation object. **/ private String computeOperationString() { /* * To be consistent with previous implementations, we use * the deprecated style of placing the "[]" for the return * type (if any) after the parameter list. */ Type returnType = methodDoc.returnType(); String op = returnType.qualifiedTypeName() + " " + methodDoc.name() + "("; Parameter[] parameters = methodDoc.parameters(); for (int i = 0; i < parameters.length; i++) { if (i > 0) { op += ", "; } op += parameters[i].type().toString(); } op += ")" + returnType.dimension(); return op; }
/** * Appends to the current document a link that is * built from the given ``element``. Such links is * usually leading to the internal corresponding * document section * * @param element Element to build link from. */ public void linkedName(final ProgramElementDoc element) { final StringBuffer anchorBuilder = new StringBuffer() .append('#') .append(element.name()); if (element instanceof ExecutableMemberDoc) { final ExecutableMemberDoc member = (ExecutableMemberDoc) element; final Parameter[] parameters = member.parameters(); if (parameters.length == 0) { // Empty constructor case. } for (int i = 0; i < parameters.length; i++) { anchorBuilder.append(parameters[i].type().simpleTypeName()); if (i < parameters.length - 1) { anchorBuilder.append('-'); } } } final String url = anchorBuilder.toString().toLowerCase(); link(element.name(), url); }
public static boolean start(RootDoc root) { ClassDoc[] classes = root.classes(); for (int i = 0; i < classes.length; i++) { System.out.println(classes[i]); ClassDoc classdoc = classes[i]; String x = classdoc.getRawCommentText(); System.out.println(x); MethodDoc[] methods = classes[i].methods(); for (int j = 0; j < methods.length; j++) { MethodDoc m = methods[j]; System.out.println(m.getRawCommentText()); if (m.isPublic()) { System.out.println("\t" + m.name()); Parameter[] parameters = m.parameters(); for (int k = 0; k < parameters.length; k++) { Parameter p = parameters[k]; System.out.println("\t\t" + p.name() + ": " + p.type().qualifiedTypeName()); } } } } return true; }
/** * * {@inheritDoc} */ public void write(List<Handler> handlers, Map<String, String> serializers) throws Exception { FileWriter fstream = new FileWriter(LIST_OUT); BufferedWriter out = new BufferedWriter(fstream); for (Handler handler : handlers) { for (ApiCall call : handler.getCalls()) { out.write(handler.getName() + "." + call.getName() + " " + call.getMethod().parameters().length + " "); for (Parameter param : call.getMethod().parameters()) { out.write(param.type().typeName() + " "); } out.write("\n"); } } out.close(); }
private String processParams(Parameter[] params) { String str = ""; for (int i = 0; i != params.length; i++) { if (str.length() > 1) { str += ", "; } if ((params[i].type().asParameterizedType() != null || params[i].type().asTypeVariable() != null)) { str += handleGenerics(params[i].type(), 0); } else if (params[i].type().asClassDoc() != null) { str += getTypeLink(params[i].type().asClassDoc()); } else { str += "<font class='type'>" + params[i].typeName() + "</font>"; } str += " " + params[i].name(); } return str; }
/** * Returns the XML for a parameter and its corresponding param tag. * * @return The corresponding XML. */ private static XMLNode toParameterNode(Parameter parameter, ParamTag tag, boolean isVarArgs) { if (parameter == null) return null; XMLNode node = new XMLNode("parameter"); node.attribute("name", parameter.name()); node.attribute("type", parameter.type().typeName()); node.attribute("fulltype", parameter.type().toString()); String dimension = parameter.type().dimension(); if (isVarArgs) { dimension = dimension.replaceAll("\\[\\]$", "") + "..."; } node.attribute("dimension", dimension); node.attribute("varargs", isVarArgs); if (tag!= null) { node.text(toComment(tag)); } return node; }
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); } } }
private PSOperatorDoc(ClassDoc classDoc, MethodDoc methodDoc) { this.declaringClassDoc = classDoc; this.methodDoc = methodDoc; this.description = methodDoc.commentText().replace('\n', ' '); this.paramDesc = ""; Tag[] paramTags = methodDoc.tags("param"); for (Tag paramTag : paramTags) { String paraStr = paramTag.text(); String paraName = paraStr.substring(0, paraStr.indexOf(' ')).replace('\n', ' ');; String paraDesc = paraStr.substring(paraStr.indexOf(' ') + 1).replace('\n', ' ');; this.paramDesc += "<br> - `" + paraName + "`: " + paraDesc; } this.returnType = methodDoc.returnType(); // ParameterizedType returnType = methodDoc.returnType().asParameterizedType(); // this.inputType = returnType.typeArguments()[0]; // this.outputType = returnType.typeArguments()[1]; // this.completeSignature = "Function<" + this.inputType + ", " + this.outputType + "> " + methodDoc.toString(); String shortSignature = classDoc.name() + "." + methodDoc.name() + "("; boolean firstParameter = true; for (Parameter parameter : methodDoc.parameters()) { if (firstParameter) { shortSignature += Utils.getSimpleTypeName(parameter.type()) + " " + parameter.name(); firstParameter = false; } else { shortSignature += ", " + Utils.getSimpleTypeName(parameter.type()) + " " + parameter.name(); } } shortSignature += ")"; this.shortSignature = shortSignature; }
/** * Returns the method descriptor for the specified method. * * See section 4.3.3 of The Java Virtual Machine Specification * Second Edition for the definition of a "method descriptor". **/ static String methodDescriptorOf(MethodDoc method) { String desc = "("; Parameter[] parameters = method.parameters(); for (int i = 0; i < parameters.length; i++) { desc += typeDescriptorOf(parameters[i].type()); } desc += ")" + typeDescriptorOf(method.returnType()); return desc; }
/** * Returns a reader-friendly string representation of the * specified method's signature. Names of reference types are not * package-qualified. **/ static String getFriendlyUnqualifiedSignature(MethodDoc method) { String sig = method.name() + "("; Parameter[] parameters = method.parameters(); for (int i = 0; i < parameters.length; i++) { if (i > 0) { sig += ", "; } Type paramType = parameters[i].type(); sig += paramType.typeName() + paramType.dimension(); } sig += ")"; return sig; }
/** * Returns the parameter types declared by this method. **/ Type[] parameterTypes() { Parameter[] parameters = methodDoc.parameters(); Type[] paramTypes = new Type[parameters.length]; for (int i = 0; i < paramTypes.length; i++) { paramTypes[i] = parameters[i].type(); } return paramTypes; }
/** * 获取指定方法的所有入参类型,便于反射 * * @param methodDoc * @return * @throws ClassNotFoundException */ private static Class[] paramTypes(MethodDoc methodDoc) throws ClassNotFoundException { Parameter[] parameters = methodDoc.parameters(); Class[] types = new Class[parameters.length]; for (int i = 0; i < parameters.length; i++) { String className = parameters[i].type().qualifiedTypeName(); types[i] = ClassUtils.toBae(className); if (types[i] == null) { types[i] = Class.forName(className); } } return types; }