Java Examples for com.sun.javadoc.MethodDoc
The following java examples will help you to understand the usage of com.sun.javadoc.MethodDoc. These source code samples are taken from different open source projects.
Example 1
Project: swagger-jaxrs-doclet-master File: ApiClassParser.java View source code |
public Collection<Api> parse() {
List<Api> apis = new ArrayList<Api>();
Map<String, Collection<Method>> apiMethods = new HashMap<String, Collection<Method>>();
for (MethodDoc method : classDoc.methods()) {
ApiMethodParser methodParser = parentMethod == null ? new ApiMethodParser(options, rootPath, method) : new ApiMethodParser(options, parentMethod, method);
Method parsedMethod = methodParser.parse();
if (parsedMethod == null) {
continue;
}
if (parsedMethod.isSubResource()) {
ClassDoc subResourceClassDoc = lookUpClassDoc(method.returnType());
if (subResourceClassDoc != null) {
// delete class from the dictionary to handle recursive sub-resources
Collection<ClassDoc> shrunkClasses = new ArrayList<ClassDoc>(classes);
shrunkClasses.remove(classDoc);
// recursively parse the sub-resource class
ApiClassParser subResourceParser = new ApiClassParser(options, subResourceClassDoc, shrunkClasses, parsedMethod);
apis.addAll(subResourceParser.parse());
models.addAll(subResourceParser.models());
}
continue;
}
models.addAll(methodParser.models());
String realPath = parsedMethod.getPath();
Collection<Method> matchingMethods = apiMethods.get(realPath);
if (matchingMethods == null) {
matchingMethods = new ArrayList<Method>();
apiMethods.put(realPath, matchingMethods);
}
matchingMethods.add(parsedMethod);
}
for (Map.Entry<String, Collection<Method>> apiEntries : apiMethods.entrySet()) {
Collection<Operation> operations = new ArrayList<Operation>(transform(apiEntries.getValue(), new Function<Method, Operation>() {
@Override
public Operation apply(Method method) {
return new Operation(method);
}
}));
apis.add(new Api(apiEntries.getKey(), "", operations));
}
Collections.sort(apis, new Comparator<Api>() {
@Override
public int compare(Api o1, Api o2) {
return o1.getPath().compareTo(o2.getPath());
}
});
return apis;
}
Example 2
Project: myrobotlab-master File: ListMethodsDoclet.java View source code |
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; }
Example 3
Project: tldgen-master File: Tag.java View source code |
private static void recollectTagData(ClassDoc doc, Tag tag, Set<String> excludeProperties) {
if (!Object.class.getName().equals(doc.qualifiedName())) {
recollectTagData(doc.superclass(), tag, excludeProperties);
}
// process any @Tag annotation
AnnotationDesc annotation = getAnnotation(doc, org.tldgen.annotations.Tag.class);
if (annotation != null) {
tag.postProcessElement(doc, annotation);
}
// add annotated attributes
for (FieldDoc fieldDoc : doc.fields()) {
Attribute attribute = addMember(fieldDoc, tag, excludeProperties);
if (attribute != null) {
AnnotationDesc variableAnnotation = getAnnotation(fieldDoc, org.tldgen.annotations.Variable.class);
if (variableAnnotation != null) {
tag.addVariable(attribute.getName(), variableAnnotation);
}
}
}
// add annotated setter methods
for (MethodDoc methodDoc : doc.methods()) {
addMember(methodDoc, tag, excludeProperties);
}
}
Example 4
Project: cdk-build-util-master File: IncorrectBugNumberTagletTest.java View source code |
/** * {@inheritDoc} */ public List<ITestReport> test(ClassDoc classDoc) { List<ITestReport> reports = new ArrayList<ITestReport>(); Tag[] tags = classDoc.tags("cdk.bug"); for (Tag tag : tags) { try { Integer.valueOf(tag.text()); } catch (NumberFormatException exception) { reports.add(new TestReport(this, classDoc, "Invalid integer given as bug number in @cdk.bug tag.", tag.position().line(), null)); } } MethodDoc[] methodDocs = classDoc.methods(); for (MethodDoc methodDoc : methodDocs) { tags = methodDoc.tags("cdk.bug"); for (Tag tag : tags) { try { Integer.valueOf(tag.text()); } catch (NumberFormatException exception) { reports.add(new TestReport(this, classDoc, "Invalid integer given as bug number in @cdk.bug tag.", tag.position().line(), null)); } } } return reports; }
Example 5
Project: cxf-master File: DumpJavaDoc.java View source code |
public static boolean start(RootDoc root) throws IOException {
String dumpFileName = readOptions(root.options());
OutputStream os = Files.newOutputStream(Paths.get(dumpFileName));
Properties javaDocMap = new Properties();
for (ClassDoc classDoc : root.classes()) {
javaDocMap.put(classDoc.toString(), classDoc.commentText());
for (MethodDoc method : classDoc.methods()) {
javaDocMap.put(method.qualifiedName(), method.commentText());
for (ParamTag paramTag : method.paramTags()) {
Parameter[] parameters = method.parameters();
for (int i = 0; i < parameters.length; ++i) {
if (parameters[i].name().equals(paramTag.parameterName())) {
javaDocMap.put(method.qualifiedName() + ".paramCommentTag." + i, paramTag.parameterComment());
}
}
}
Tag retTags[] = method.tags("return");
if (retTags != null && retTags.length == 1) {
Tag retTag = method.tags("return")[0];
javaDocMap.put(method.qualifiedName() + "." + "returnCommentTag", retTag.text());
}
}
}
javaDocMap.store(os, "");
os.flush();
os.close();
return true;
}
Example 6
Project: google-web-toolkit-svnmirror-master File: Booklet.java View source code |
private void emitModifiers(ProgramElementDoc doc) { if (doc.isPrivate()) { beginEndln("isPrivate"); } else if (doc.isProtected()) { beginEndln("isProtected"); } else if (doc.isPublic()) { beginEndln("isPublic"); } else if (doc.isPackagePrivate()) { beginEndln("isPackagePrivate"); } if (doc.isStatic()) { beginEndln("isStatic"); } if (doc.isFinal()) { beginEndln("isFinal"); } if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; if (methodDoc.isAbstract()) { beginEndln("isAbstract"); } if (methodDoc.isSynchronized()) { beginEndln("isSynchronized"); } } }
Example 7
Project: gwt-master File: Booklet.java View source code |
private void emitModifiers(ProgramElementDoc doc) { if (doc.isPrivate()) { beginEndln("isPrivate"); } else if (doc.isProtected()) { beginEndln("isProtected"); } else if (doc.isPublic()) { beginEndln("isPublic"); } else if (doc.isPackagePrivate()) { beginEndln("isPackagePrivate"); } if (doc.isStatic()) { beginEndln("isStatic"); } if (doc.isFinal()) { beginEndln("isFinal"); } if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; if (methodDoc.isAbstract()) { beginEndln("isAbstract"); } if (methodDoc.isSynchronized()) { beginEndln("isSynchronized"); } } }
Example 8
Project: gwt-sandbox-master File: Booklet.java View source code |
private void emitModifiers(ProgramElementDoc doc) { if (doc.isPrivate()) { beginEndln("isPrivate"); } else if (doc.isProtected()) { beginEndln("isProtected"); } else if (doc.isPublic()) { beginEndln("isPublic"); } else if (doc.isPackagePrivate()) { beginEndln("isPackagePrivate"); } if (doc.isStatic()) { beginEndln("isStatic"); } if (doc.isFinal()) { beginEndln("isFinal"); } if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; if (methodDoc.isAbstract()) { beginEndln("isAbstract"); } if (methodDoc.isSynchronized()) { beginEndln("isSynchronized"); } } }
Example 9
Project: gwt.svn-master File: Booklet.java View source code |
private void emitModifiers(ProgramElementDoc doc) { if (doc.isPrivate()) { beginEndln("isPrivate"); } else if (doc.isProtected()) { beginEndln("isProtected"); } else if (doc.isPublic()) { beginEndln("isPublic"); } else if (doc.isPackagePrivate()) { beginEndln("isPackagePrivate"); } if (doc.isStatic()) { beginEndln("isStatic"); } if (doc.isFinal()) { beginEndln("isFinal"); } if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; if (methodDoc.isAbstract()) { beginEndln("isAbstract"); } if (methodDoc.isSynchronized()) { beginEndln("isSynchronized"); } } }
Example 10
Project: h2-bitmap-master File: Doclet.java View source code |
private void processClass(ClassDoc clazz) throws IOException { String packageName = clazz.containingPackage().name(); String dir = destDir + "/" + packageName.replace('.', '/'); (new File(dir)).mkdirs(); String fileName = dir + "/" + clazz.name() + ".html"; String className = getClass(clazz); FileWriter out = new FileWriter(fileName); PrintWriter writer = new PrintWriter(new BufferedWriter(out)); writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); String language = "en"; writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" " + "lang=\"" + language + "\" xml:lang=\"" + language + "\">"); writer.println("<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /><title>"); writer.println(className); writer.println("</title><link rel=\"stylesheet\" type=\"text/css\" href=\"../../../stylesheet.css\" />"); writer.println("<script type=\"text/javascript\" src=\"../../../animate.js\"></script>"); writer.println("</head><body onload=\"openLink();\">"); writer.println("<table class=\"content\"><tr class=\"content\"><td class=\"content\"><div class=\"contentDiv\">"); writer.println("<h1>" + className + "</h1>"); writer.println(formatText(clazz.commentText()) + "<br /><br />"); // methods ConstructorDoc[] constructors = clazz.constructors(); MethodDoc[] methods = clazz.methods(); ExecutableMemberDoc[] constructorsMethods = new ExecutableMemberDoc[constructors.length + methods.length]; System.arraycopy(constructors, 0, constructorsMethods, 0, constructors.length); System.arraycopy(methods, 0, constructorsMethods, constructors.length, methods.length); Arrays.sort(constructorsMethods, new Comparator<ExecutableMemberDoc>() { public int compare(ExecutableMemberDoc a, ExecutableMemberDoc b) { // sort static method before non-static methods if (a.isStatic() != b.isStatic()) { return a.isStatic() ? -1 : 1; } return a.name().compareTo(b.name()); } }); // // // Arrays.sort(methods, new Comparator<MethodDoc>() { // public int compare(MethodDoc a, MethodDoc b) { // // sort static method before non-static methods // if (a.isStatic() != b.isStatic()) { // return a.isStatic() ? -1 : 1; // } // return a.name().compareTo(b.name()); // } // }); ArrayList<String> signatures = new ArrayList<String>(); boolean hasMethods = false; int id = 0; for (int i = 0; i < constructorsMethods.length; i++) { ExecutableMemberDoc method = constructorsMethods[i]; String name = method.name(); if (skipMethod(method)) { continue; } if (!hasMethods) { writer.println("<table class=\"block\"><tr onclick=\"return allDetails()\"><th colspan=\"2\">Methods</th></tr>"); hasMethods = true; } String type = getTypeName(method.isStatic(), false, getReturnType(method)); writer.println("<tr id=\"__" + id + "\" onclick=\"return on(" + id + ")\">"); writer.println("<td class=\"return\">" + type + "</td><td class=\"method\">"); Parameter[] params = method.parameters(); StringBuilder buff = new StringBuilder(); StringBuilder buffSignature = new StringBuilder(name); buff.append('('); for (int j = 0; j < params.length; j++) { if (j > 0) { buff.append(", "); } buffSignature.append('_'); Parameter param = params[j]; boolean isVarArgs = method.isVarArgs() && j == params.length - 1; String typeName = getTypeName(false, isVarArgs, param.type()); buff.append(typeName); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-")); buff.append(' '); buff.append(param.name()); } buff.append(')'); if (isDeprecated(method)) { name = "<span class=\"deprecated\">" + name + "</span>"; } String signature = buffSignature.toString(); while (signatures.size() < i) { signatures.add(null); } signatures.add(i, signature); writer.println("<a id=\"" + signature + "\" href=\"#" + signature + "\">" + name + "</a>" + buff.toString()); String firstSentence = getFirstSentence(method.firstSentenceTags()); if (firstSentence != null) { writer.println("<div class=\"methodText\">" + formatText(firstSentence) + "</div>"); } writer.println("</td></tr>"); writer.println("<tr onclick=\"return off(" + id + ")\" class=\"detail\" id=\"_" + id + "\">"); writer.println("<td class=\"return\">" + type + "</td><td>"); writeMethodDetails(writer, clazz, method, signature); writer.println("</td></tr>"); id++; } if (hasMethods) { writer.println("</table>"); } // field overview FieldDoc[] fields = clazz.fields(); if (clazz.interfaces().length > 0) { fields = clazz.interfaces()[0].fields(); } Arrays.sort(fields, new Comparator<FieldDoc>() { public int compare(FieldDoc a, FieldDoc b) { return a.name().compareTo(b.name()); } }); int fieldId = 0; for (FieldDoc field : fields) { if (skipField(clazz, field)) { continue; } String name = field.name(); String text = field.commentText(); if (text == null || text.trim().length() == 0) { addError("Undocumented field (" + clazz.name() + ".java:" + field.position().line() + ") " + name); } if (text != null && text.startsWith("INTERNAL")) { continue; } if (fieldId == 0) { writer.println("<br /><table><tr><th colspan=\"2\">Fields</th></tr>"); } String type = getTypeName(true, false, field.type()); writer.println("<tr><td class=\"return\">" + type + "</td><td class=\"method\">"); String constant = field.constantValueExpression(); // add a link (a name) if there is a <code> tag String link = getFieldLink(text, constant, clazz, name); writer.print("<a href=\"#" + link + "\">" + name + "</a>"); if (constant == null) { writer.println(); } else { writer.println(" = " + constant); } writer.println("</td></tr>"); fieldId++; } if (fieldId > 0) { writer.println("</table>"); } // field details Arrays.sort(fields, new Comparator<FieldDoc>() { public int compare(FieldDoc a, FieldDoc b) { String ca = a.constantValueExpression(); if (ca == null) { ca = a.name(); } String cb = b.constantValueExpression(); if (cb == null) { cb = b.name(); } return ca.compareTo(cb); } }); for (FieldDoc field : fields) { writeFieldDetails(writer, clazz, field); } writer.println("</div></td></tr></table></body></html>"); writer.close(); out.close(); }
Example 11
Project: H2-Mirror-master File: Doclet.java View source code |
private void processClass(ClassDoc clazz) throws IOException { String packageName = clazz.containingPackage().name(); String dir = destDir + "/" + packageName.replace('.', '/'); (new File(dir)).mkdirs(); String fileName = dir + "/" + clazz.name() + ".html"; String className = getClass(clazz); FileWriter out = new FileWriter(fileName); PrintWriter writer = new PrintWriter(new BufferedWriter(out)); writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + "XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); String language = "en"; writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" " + "lang=\"" + language + "\" xml:lang=\"" + language + "\">"); writer.println("<head>" + "<meta http-equiv=\"Content-Type\" " + "content=\"text/html;charset=utf-8\" /><title>"); writer.println(className); writer.println("</title>" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"../../../stylesheet.css\" />"); writer.println("<script type=\"text/javascript\" " + "src=\"../../../animate.js\"></script>"); writer.println("</head><body onload=\"openLink();\">"); writer.println("<table class=\"content\">" + "<tr class=\"content\">" + "<td class=\"content\">" + "<div class=\"contentDiv\">"); writer.println("<h1>" + className + "</h1>"); writer.println(formatText(clazz.commentText()) + "<br /><br />"); // methods ConstructorDoc[] constructors = clazz.constructors(); MethodDoc[] methods = clazz.methods(); ExecutableMemberDoc[] constructorsMethods = new ExecutableMemberDoc[constructors.length + methods.length]; System.arraycopy(constructors, 0, constructorsMethods, 0, constructors.length); System.arraycopy(methods, 0, constructorsMethods, constructors.length, methods.length); Arrays.sort(constructorsMethods, new Comparator<ExecutableMemberDoc>() { @Override public int compare(ExecutableMemberDoc a, ExecutableMemberDoc b) { // sort static method before non-static methods if (a.isStatic() != b.isStatic()) { return a.isStatic() ? -1 : 1; } return a.name().compareTo(b.name()); } }); // // // Arrays.sort(methods, new Comparator<MethodDoc>() { // public int compare(MethodDoc a, MethodDoc b) { // // sort static method before non-static methods // if (a.isStatic() != b.isStatic()) { // return a.isStatic() ? -1 : 1; // } // return a.name().compareTo(b.name()); // } // }); ArrayList<String> signatures = new ArrayList<String>(); boolean hasMethods = false; int id = 0; for (int i = 0; i < constructorsMethods.length; i++) { ExecutableMemberDoc method = constructorsMethods[i]; String name = method.name(); if (skipMethod(method)) { continue; } if (!hasMethods) { writer.println("<table class=\"block\">" + "<tr onclick=\"return allDetails()\">" + "<th colspan=\"2\">Methods</th></tr>"); hasMethods = true; } String type = getTypeName(method.isStatic(), false, getReturnType(method)); writer.println("<tr id=\"__" + id + "\" onclick=\"return on(" + id + ")\">"); writer.println("<td class=\"return\">" + type + "</td><td class=\"method\">"); Parameter[] params = method.parameters(); StringBuilder buff = new StringBuilder(); StringBuilder buffSignature = new StringBuilder(name); buff.append('('); for (int j = 0; j < params.length; j++) { if (j > 0) { buff.append(", "); } buffSignature.append('_'); Parameter param = params[j]; boolean isVarArgs = method.isVarArgs() && j == params.length - 1; String typeName = getTypeName(false, isVarArgs, param.type()); buff.append(typeName); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-")); buff.append(' '); buff.append(param.name()); } buff.append(')'); if (isDeprecated(method)) { name = "<span class=\"deprecated\">" + name + "</span>"; } String signature = buffSignature.toString(); while (signatures.size() < i) { signatures.add(null); } signatures.add(i, signature); writer.println("<a id=\"" + signature + "\" href=\"#" + signature + "\">" + name + "</a>" + buff.toString()); String firstSentence = getFirstSentence(method.firstSentenceTags()); if (firstSentence != null) { writer.println("<div class=\"methodText\">" + formatText(firstSentence) + "</div>"); } writer.println("</td></tr>"); writer.println("<tr onclick=\"return off(" + id + ")\" class=\"detail\" id=\"_" + id + "\">"); writer.println("<td class=\"return\">" + type + "</td><td>"); writeMethodDetails(writer, clazz, method, signature); writer.println("</td></tr>"); id++; } if (hasMethods) { writer.println("</table>"); } // field overview FieldDoc[] fields = clazz.fields(); if (clazz.interfaces().length > 0) { fields = clazz.interfaces()[0].fields(); } Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { return a.name().compareTo(b.name()); } }); int fieldId = 0; for (FieldDoc field : fields) { if (skipField(clazz, field)) { continue; } String name = field.name(); String text = field.commentText(); if (text == null || text.trim().length() == 0) { addError("Undocumented field (" + getLink(clazz, field.position().line()) + ") " + name); } if (text != null && text.startsWith("INTERNAL")) { continue; } if (fieldId == 0) { writer.println("<br /><table><tr><th colspan=\"2\">Fields</th></tr>"); } String type = getTypeName(true, false, field.type()); writer.println("<tr><td class=\"return\">" + type + "</td><td class=\"method\">"); String constant = field.constantValueExpression(); // add a link (a name) if there is a <code> tag String link = getFieldLink(text, constant, clazz, name); writer.print("<a href=\"#" + link + "\">" + name + "</a>"); if (constant == null) { writer.println(); } else { writer.println(" = " + constant); } writer.println("</td></tr>"); fieldId++; } if (fieldId > 0) { writer.println("</table>"); } // field details Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { String ca = a.constantValueExpression(); if (ca == null) { ca = a.name(); } String cb = b.constantValueExpression(); if (cb == null) { cb = b.name(); } return ca.compareTo(cb); } }); for (FieldDoc field : fields) { writeFieldDetails(writer, clazz, field); } writer.println("</div></td></tr></table></body></html>"); writer.close(); out.close(); }
Example 12
Project: H2-Research-master File: Doclet.java View source code |
private void processClass(ClassDoc clazz) throws IOException { String packageName = clazz.containingPackage().name(); String dir = destDir + "/" + packageName.replace('.', '/'); (new File(dir)).mkdirs(); String fileName = dir + "/" + clazz.name() + ".html"; String className = getClass(clazz); FileWriter out = new FileWriter(fileName); PrintWriter writer = new PrintWriter(new BufferedWriter(out)); writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + "XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); String language = "en"; writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" " + "lang=\"" + language + "\" xml:lang=\"" + language + "\">"); writer.println("<head>" + "<meta http-equiv=\"Content-Type\" " + "content=\"text/html;charset=utf-8\" /><title>"); writer.println(className); writer.println("</title>" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"../../../stylesheet.css\" />"); writer.println("<script type=\"text/javascript\" " + "src=\"../../../animate.js\"></script>"); writer.println("</head><body onload=\"openLink();\">"); writer.println("<table class=\"content\">" + "<tr class=\"content\">" + "<td class=\"content\">" + "<div class=\"contentDiv\">"); writer.println("<h1>" + className + "</h1>"); writer.println(formatText(clazz.commentText()) + "<br /><br />"); // methods ConstructorDoc[] constructors = clazz.constructors(); MethodDoc[] methods = clazz.methods(); ExecutableMemberDoc[] constructorsMethods = new ExecutableMemberDoc[constructors.length + methods.length]; System.arraycopy(constructors, 0, constructorsMethods, 0, constructors.length); System.arraycopy(methods, 0, constructorsMethods, constructors.length, methods.length); Arrays.sort(constructorsMethods, new Comparator<ExecutableMemberDoc>() { @Override public int compare(ExecutableMemberDoc a, ExecutableMemberDoc b) { // sort static method before non-static methods if (a.isStatic() != b.isStatic()) { return a.isStatic() ? -1 : 1; } return a.name().compareTo(b.name()); } }); // // // Arrays.sort(methods, new Comparator<MethodDoc>() { // public int compare(MethodDoc a, MethodDoc b) { // // sort static method before non-static methods // if (a.isStatic() != b.isStatic()) { // return a.isStatic() ? -1 : 1; // } // return a.name().compareTo(b.name()); // } // }); ArrayList<String> signatures = new ArrayList<String>(); boolean hasMethods = false; int id = 0; for (int i = 0; i < constructorsMethods.length; i++) { ExecutableMemberDoc method = constructorsMethods[i]; String name = method.name(); if (skipMethod(method)) { continue; } if (!hasMethods) { writer.println("<table class=\"block\">" + "<tr onclick=\"return allDetails()\">" + "<th colspan=\"2\">Methods</th></tr>"); hasMethods = true; } String type = getTypeName(method.isStatic(), false, getReturnType(method)); writer.println("<tr id=\"__" + id + "\" onclick=\"return on(" + id + ")\">"); writer.println("<td class=\"return\">" + type + "</td><td class=\"method\">"); Parameter[] params = method.parameters(); StringBuilder buff = new StringBuilder(); StringBuilder buffSignature = new StringBuilder(name); buff.append('('); for (int j = 0; j < params.length; j++) { if (j > 0) { buff.append(", "); } buffSignature.append('_'); Parameter param = params[j]; boolean isVarArgs = method.isVarArgs() && j == params.length - 1; String typeName = getTypeName(false, isVarArgs, param.type()); buff.append(typeName); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-")); buff.append(' '); buff.append(param.name()); } buff.append(')'); if (isDeprecated(method)) { name = "<span class=\"deprecated\">" + name + "</span>"; } String signature = buffSignature.toString(); while (signatures.size() < i) { signatures.add(null); } signatures.add(i, signature); writer.println("<a id=\"" + signature + "\" href=\"#" + signature + "\">" + name + "</a>" + buff.toString()); String firstSentence = getFirstSentence(method.firstSentenceTags()); if (firstSentence != null) { writer.println("<div class=\"methodText\">" + formatText(firstSentence) + "</div>"); } writer.println("</td></tr>"); writer.println("<tr onclick=\"return off(" + id + ")\" class=\"detail\" id=\"_" + id + "\">"); writer.println("<td class=\"return\">" + type + "</td><td>"); writeMethodDetails(writer, clazz, method, signature); writer.println("</td></tr>"); id++; } if (hasMethods) { writer.println("</table>"); } // field overview FieldDoc[] fields = clazz.fields(); if (clazz.interfaces().length > 0) { fields = clazz.interfaces()[0].fields(); } Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { return a.name().compareTo(b.name()); } }); int fieldId = 0; for (FieldDoc field : fields) { if (skipField(clazz, field)) { continue; } String name = field.name(); String text = field.commentText(); if (text == null || text.trim().length() == 0) { addError("Undocumented field (" + getLink(clazz, field.position().line()) + ") " + name); } if (text != null && text.startsWith("INTERNAL")) { continue; } if (fieldId == 0) { writer.println("<br /><table><tr><th colspan=\"2\">Fields</th></tr>"); } String type = getTypeName(true, false, field.type()); writer.println("<tr><td class=\"return\">" + type + "</td><td class=\"method\">"); String constant = field.constantValueExpression(); // add a link (a name) if there is a <code> tag String link = getFieldLink(text, constant, clazz, name); writer.print("<a href=\"#" + link + "\">" + name + "</a>"); if (constant == null) { writer.println(); } else { writer.println(" = " + constant); } writer.println("</td></tr>"); fieldId++; } if (fieldId > 0) { writer.println("</table>"); } // field details Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { String ca = a.constantValueExpression(); if (ca == null) { ca = a.name(); } String cb = b.constantValueExpression(); if (cb == null) { cb = b.name(); } return ca.compareTo(cb); } }); for (FieldDoc field : fields) { writeFieldDetails(writer, clazz, field); } writer.println("</div></td></tr></table></body></html>"); writer.close(); out.close(); }
Example 13
Project: h2database-master File: Doclet.java View source code |
private void processClass(ClassDoc clazz) throws IOException { String packageName = clazz.containingPackage().name(); String dir = destDir + "/" + packageName.replace('.', '/'); (new File(dir)).mkdirs(); String fileName = dir + "/" + clazz.name() + ".html"; String className = getClass(clazz); FileWriter out = new FileWriter(fileName); PrintWriter writer = new PrintWriter(new BufferedWriter(out)); writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD " + "XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); String language = "en"; writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" " + "lang=\"" + language + "\" xml:lang=\"" + language + "\">"); writer.println("<head>" + "<meta http-equiv=\"Content-Type\" " + "content=\"text/html;charset=utf-8\" /><title>"); writer.println(className); writer.println("</title>" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"../../../stylesheet.css\" />"); writer.println("<script type=\"text/javascript\" " + "src=\"../../../animate.js\"></script>"); writer.println("</head><body onload=\"openLink();\">"); writer.println("<table class=\"content\">" + "<tr class=\"content\">" + "<td class=\"content\">" + "<div class=\"contentDiv\">"); writer.println("<h1>" + className + "</h1>"); writer.println(formatText(clazz.commentText()) + "<br /><br />"); // methods ConstructorDoc[] constructors = clazz.constructors(); MethodDoc[] methods = clazz.methods(); ExecutableMemberDoc[] constructorsMethods = new ExecutableMemberDoc[constructors.length + methods.length]; System.arraycopy(constructors, 0, constructorsMethods, 0, constructors.length); System.arraycopy(methods, 0, constructorsMethods, constructors.length, methods.length); Arrays.sort(constructorsMethods, new Comparator<ExecutableMemberDoc>() { @Override public int compare(ExecutableMemberDoc a, ExecutableMemberDoc b) { // sort static method before non-static methods if (a.isStatic() != b.isStatic()) { return a.isStatic() ? -1 : 1; } return a.name().compareTo(b.name()); } }); // // // Arrays.sort(methods, new Comparator<MethodDoc>() { // public int compare(MethodDoc a, MethodDoc b) { // // sort static method before non-static methods // if (a.isStatic() != b.isStatic()) { // return a.isStatic() ? -1 : 1; // } // return a.name().compareTo(b.name()); // } // }); ArrayList<String> signatures = new ArrayList<String>(); boolean hasMethods = false; int id = 0; for (int i = 0; i < constructorsMethods.length; i++) { ExecutableMemberDoc method = constructorsMethods[i]; String name = method.name(); if (skipMethod(method)) { continue; } if (!hasMethods) { writer.println("<table class=\"block\">" + "<tr onclick=\"return allDetails()\">" + "<th colspan=\"2\">Methods</th></tr>"); hasMethods = true; } String type = getTypeName(method.isStatic(), false, getReturnType(method)); writer.println("<tr id=\"__" + id + "\" onclick=\"return on(" + id + ")\">"); writer.println("<td class=\"return\">" + type + "</td><td class=\"method\">"); Parameter[] params = method.parameters(); StringBuilder buff = new StringBuilder(); StringBuilder buffSignature = new StringBuilder(name); buff.append('('); for (int j = 0; j < params.length; j++) { if (j > 0) { buff.append(", "); } buffSignature.append('_'); Parameter param = params[j]; boolean isVarArgs = method.isVarArgs() && j == params.length - 1; String typeName = getTypeName(false, isVarArgs, param.type()); buff.append(typeName); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-")); buff.append(' '); buff.append(param.name()); } buff.append(')'); if (isDeprecated(method)) { name = "<span class=\"deprecated\">" + name + "</span>"; } String signature = buffSignature.toString(); while (signatures.size() < i) { signatures.add(null); } signatures.add(i, signature); writer.println("<a id=\"" + signature + "\" href=\"#" + signature + "\">" + name + "</a>" + buff.toString()); String firstSentence = getFirstSentence(method.firstSentenceTags()); if (firstSentence != null) { writer.println("<div class=\"methodText\">" + formatText(firstSentence) + "</div>"); } writer.println("</td></tr>"); writer.println("<tr onclick=\"return off(" + id + ")\" class=\"detail\" id=\"_" + id + "\">"); writer.println("<td class=\"return\">" + type + "</td><td>"); writeMethodDetails(writer, clazz, method, signature); writer.println("</td></tr>"); id++; } if (hasMethods) { writer.println("</table>"); } // field overview FieldDoc[] fields = clazz.fields(); if (clazz.interfaces().length > 0) { fields = clazz.interfaces()[0].fields(); } Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { return a.name().compareTo(b.name()); } }); int fieldId = 0; for (FieldDoc field : fields) { if (skipField(clazz, field)) { continue; } String name = field.name(); String text = field.commentText(); if (text == null || text.trim().length() == 0) { addError("Undocumented field (" + getLink(clazz, field.position().line()) + ") " + name); } if (text != null && text.startsWith("INTERNAL")) { continue; } if (fieldId == 0) { writer.println("<br /><table><tr><th colspan=\"2\">Fields</th></tr>"); } String type = getTypeName(true, false, field.type()); writer.println("<tr><td class=\"return\">" + type + "</td><td class=\"method\">"); String constant = field.constantValueExpression(); // add a link (a name) if there is a <code> tag String link = getFieldLink(text, constant, clazz, name); writer.print("<a href=\"#" + link + "\">" + name + "</a>"); if (constant == null) { writer.println(); } else { writer.println(" = " + constant); } writer.println("</td></tr>"); fieldId++; } if (fieldId > 0) { writer.println("</table>"); } // field details Arrays.sort(fields, new Comparator<FieldDoc>() { @Override public int compare(FieldDoc a, FieldDoc b) { String ca = a.constantValueExpression(); if (ca == null) { ca = a.name(); } String cb = b.constantValueExpression(); if (cb == null) { cb = b.name(); } return ca.compareTo(cb); } }); for (FieldDoc field : fields) { writeFieldDetails(writer, clazz, field); } writer.println("</div></td></tr></table></body></html>"); writer.close(); out.close(); }
Example 14
Project: JamVM-PH-master File: AbstractDoclet.java View source code |
protected Map getIndexByName() { if (null == indexByName) { // Create index // Collect index //TreeMap(); indexByName = new HashMap(); // Add packages to index PackageDoc[] packages = rootDoc.specifiedPackages(); for (int i = 0, ilim = packages.length; i < ilim; ++i) { PackageDoc c = packages[i]; if (c.name().length() > 0) { indexByName.put(new IndexKey(c.name()), c); } } // Add classes, fields and methods to index ClassDoc[] sumclasses = rootDoc.classes(); for (int i = 0, ilim = sumclasses.length; i < ilim; ++i) { ClassDoc c = sumclasses[i]; if (null == c.containingClass()) { indexByName.put(new IndexKey(c.name() + " " + c.containingPackage().name()), c); } else { indexByName.put(new IndexKey(c.name().substring(c.containingClass().name().length() + 1) + " " + c.containingClass().name() + " " + c.containingPackage().name()), c); } FieldDoc[] fields = c.fields(); for (int j = 0, jlim = fields.length; j < jlim; ++j) { indexByName.put(new IndexKey(fields[j].name() + " " + fields[j].containingClass().name() + " " + fields[j].containingPackage().name()), fields[j]); } MethodDoc[] methods = c.methods(); for (int j = 0, jlim = methods.length; j < jlim; ++j) { MethodDoc method = methods[j]; indexByName.put(new IndexKey(method.name() + method.signature() + " " + method.containingClass().name() + " " + method.containingPackage().name()), method); } ConstructorDoc[] constructors = c.constructors(); for (int j = 0, jlim = constructors.length; j < jlim; ++j) { ConstructorDoc constructor = constructors[j]; indexByName.put(new IndexKey(constructor.name() + constructor.signature() + " " + constructor.containingClass().name() + " " + constructor.containingPackage().name()), constructor); } } } return indexByName; }
Example 15
Project: jangaroo-tools-master File: MethodDocImpl.java View source code |
public MethodDoc overriddenMethod() { ClassDoc superClass = containingClass().superclass(); while (superClass != null) { MethodDoc superMethodDoc = getSuperMethodDoc(superClass); if (superMethodDoc != null) return superMethodDoc; superClass = superClass.superclass(); } return null; }
Example 16
Project: pentaho-platform-master File: PentahoResourceDoclet.java View source code |
private static String generateComment(MethodDoc methodDoc) {
String documentation = methodDoc.getRawCommentText();
StringBuilder comment = new StringBuilder();
comment.append(MessageFormat.format(SUPPORTED_TAG, isSupported(methodDoc.annotations()))).append(MessageFormat.format(DEPRECATED_TAG, isDeprecated(methodDoc.annotations()))).append(MessageFormat.format(DOCUMENTATION_TAG, documentation));
return comment.toString();
}
Example 17
Project: scalagwt-gwt-master File: Booklet.java View source code |
private void emitModifiers(ProgramElementDoc doc) { if (doc.isPrivate()) { beginEndln("isPrivate"); } else if (doc.isProtected()) { beginEndln("isProtected"); } else if (doc.isPublic()) { beginEndln("isPublic"); } else if (doc.isPackagePrivate()) { beginEndln("isPackagePrivate"); } if (doc.isStatic()) { beginEndln("isStatic"); } if (doc.isFinal()) { beginEndln("isFinal"); } if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; if (methodDoc.isAbstract()) { beginEndln("isAbstract"); } if (methodDoc.isSynchronized()) { beginEndln("isSynchronized"); } } }
Example 18
Project: Sesat-master File: ConfigElement.java View source code |
private void build(final ClassDoc klass) { if (klass != null) { final MethodDoc[] methods = klass.methods(); for (int i = 0; i < methods.length; i++) { final MethodDoc methodDoc = methods[i]; if (!attribNames.contains(methodDoc.name()) && (methodDoc.name().startsWith("set") || methodDoc.name().startsWith("add"))) { final Parameter[] parameters = methodDoc.parameters(); if (parameters.length == 1) { attribNames.add(methodDoc.name()); attributes.add(new ConfigAttribute(methodDoc)); } } } build(klass.superclass()); } }
Example 19
Project: axis2-java-master File: ResourceInfoDoclet.java View source code |
public static boolean start(RootDoc root) throws IOException {
parseOptions(root.options());
ResourceInfo resourceInfo = new ResourceInfo();
for (ClassDoc clazz : root.classes()) {
Resource resource = null;
for (MethodDoc method : clazz.methods()) {
if (getAnnotation(method, "org.apache.axis2.transport.testkit.tests.Setup") != null) {
if (resource == null) {
resource = new Resource(clazz.qualifiedName());
}
ParamTag[] paramTags = method.paramTags();
for (Parameter parameter : method.parameters()) {
Type type = parameter.type();
String name = parameter.name();
String comment = null;
for (ParamTag paramTag : paramTags) {
if (paramTag.parameterName().equals(name)) {
comment = paramTag.parameterComment();
break;
}
}
if (comment == null) {
comment = getFirstSentence(root.classNamed(type.qualifiedTypeName()));
}
resource.addDependency(type.qualifiedTypeName(), type.dimension().equals("[]") ? "0..*" : "1", comment);
}
}
}
if (resource != null) {
resourceInfo.addResource(resource);
}
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outFile));
out.writeObject(resourceInfo);
out.close();
return true;
}
Example 20
Project: classlib6-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 21
Project: ikvm-openjdk-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 22
Project: jdk7u-jdk-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 23
Project: jersey-1.x-old-master File: ResourceDoclet.java View source code |
/**
* Start the doclet.
*
* @param root
* @return true if no exception is thrown
*/
public static boolean start(RootDoc root) {
final String output = getOptionArg(root.options(), OPTION_OUTPUT);
final String classpath = getOptionArg(root.options(), OPTION_CLASSPATH);
// LOG.info( "Have classpath: " + classpath );
final String[] classpathElements = classpath.split(":");
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final ClassLoader ncl = new Loader(classpathElements, ResourceDoclet.class.getClassLoader());
Thread.currentThread().setContextClassLoader(ncl);
final String docProcessorOption = getOptionArg(root.options(), OPTION_DOC_PROCESSORS);
final String[] docProcessors = docProcessorOption != null ? docProcessorOption.split(":") : null;
final DocProcessorWrapper docProcessor = new DocProcessorWrapper();
try {
if (docProcessors != null && docProcessors.length > 0) {
final Class<?> clazz = Class.forName(docProcessors[0], true, Thread.currentThread().getContextClassLoader());
final Class<? extends DocProcessor> dpClazz = clazz.asSubclass(DocProcessor.class);
docProcessor.add(dpClazz.newInstance());
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Could not load docProcessors " + docProcessorOption, e);
}
try {
final ResourceDocType result = new ResourceDocType();
final ClassDoc[] classes = root.classes();
for (ClassDoc classDoc : classes) {
LOG.fine("Writing class " + classDoc.qualifiedTypeName());
final ClassDocType classDocType = new ClassDocType();
classDocType.setClassName(classDoc.qualifiedTypeName());
classDocType.setCommentText(classDoc.commentText());
docProcessor.processClassDoc(classDoc, classDocType);
for (MethodDoc methodDoc : classDoc.methods()) {
final MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodDoc.name());
methodDocType.setCommentText(methodDoc.commentText());
docProcessor.processMethodDoc(methodDoc, methodDocType);
addParamDocs(methodDoc, methodDocType, docProcessor);
addRequestRepresentationDoc(methodDoc, methodDocType);
addResponseDoc(methodDoc, methodDocType);
classDocType.getMethodDocs().add(methodDocType);
}
result.getDocs().add(classDocType);
}
try {
final Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
final JAXBContext c = JAXBContext.newInstance(clazzes);
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
final String[] cdataElements = getCDataElements(docProcessor);
final XMLSerializer serializer = getXMLSerializer(out, cdataElements);
m.marshal(result, serializer);
out.close();
LOG.info("Wrote " + output);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);
return false;
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return true;
}
Example 24
Project: jersey-old-master File: ResourceDoclet.java View source code |
/**
* Start the doclet.
*
* @param root
* @return true if no exception is thrown
*/
public static boolean start(RootDoc root) {
final String output = getOptionArg(root.options(), OPTION_OUTPUT);
final String classpath = getOptionArg(root.options(), OPTION_CLASSPATH);
// LOG.info( "Have classpatch: " + classpath );
final String[] classpathElements = classpath.split(":");
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final ClassLoader ncl = new Loader(classpathElements, ResourceDoclet.class.getClassLoader());
Thread.currentThread().setContextClassLoader(ncl);
final String docProcessorOption = getOptionArg(root.options(), OPTION_DOC_PROCESSORS);
final String[] docProcessors = docProcessorOption != null ? docProcessorOption.split(":") : null;
final DocProcessorWrapper docProcessor = new DocProcessorWrapper();
try {
if (docProcessors != null && docProcessors.length > 0) {
final Class<?> clazz = Class.forName(docProcessors[0], true, Thread.currentThread().getContextClassLoader());
final Class<? extends DocProcessor> dpClazz = clazz.asSubclass(DocProcessor.class);
docProcessor.add(dpClazz.newInstance());
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Could not load docProcessors " + docProcessorOption, e);
}
try {
final ResourceDocType result = new ResourceDocType();
final ClassDoc[] classes = root.classes();
for (ClassDoc classDoc : classes) {
LOG.fine("Writing class " + classDoc.qualifiedTypeName());
final ClassDocType classDocType = new ClassDocType();
classDocType.setClassName(classDoc.qualifiedTypeName());
classDocType.setCommentText(classDoc.commentText());
docProcessor.processClassDoc(classDoc, classDocType);
for (MethodDoc methodDoc : classDoc.methods()) {
final MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodDoc.name());
methodDocType.setCommentText(methodDoc.commentText());
docProcessor.processMethodDoc(methodDoc, methodDocType);
addParamDocs(methodDoc, methodDocType, docProcessor);
addRequestRepresentationDoc(methodDoc, methodDocType);
addResponseDoc(methodDoc, methodDocType);
classDocType.getMethodDocs().add(methodDocType);
}
result.getDocs().add(classDocType);
}
try {
final Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
final JAXBContext c = JAXBContext.newInstance(clazzes);
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
final String[] cdataElements = getCDataElements(docProcessor);
final XMLSerializer serializer = getXMLSerializer(out, cdataElements);
m.marshal(result, serializer);
out.close();
LOG.info("Wrote " + output);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);
return false;
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return true;
}
Example 25
Project: lemma-master File: JavacodeReader.java View source code |
public String[] readSource(Doc doc) {
File file = doc.position().file();
if (doc instanceof ClassDoc) {
ClassDoc classDoc = (ClassDoc) doc;
// If it's a nested class, read only the lines of that nested class source
if (classDoc.containingClass() == null) {
log.finest("Doc is referencing a root type declaration: " + doc.name());
return handler.getContent(file, null);
} else {
String nestedClassName = classDoc.simpleTypeName();
log.finest("Doc is referencing a nested type declaration: " + nestedClassName);
return handler.getContent(file, getLineRangeParser(file).getTypesLineRange().get(nestedClassName));
}
} else if (doc instanceof PackageDoc) {
// For a package we return everything
log.finest("Doc is referencing a package: " + doc.name());
return handler.getContent(file, null);
} else if (doc instanceof ExecutableMemberDoc) {
// For methods we return the lines of the method source (signature matching is complex though)
log.finest("Doc is referencing method declaration: " + doc.name());
return handler.getContent(file, getMethodLineRange(file, (MethodDoc) doc));
} else {
log.warning("Unknown doc type/reference, not reading any source: " + doc);
}
return new String[0];
}
Example 26
Project: ManagedRuntimeInitiative-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 27
Project: openjdk-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 28
Project: openjdk8-jdk-master File: StubSkeletonWriter.java View source code |
/**
* Writes the stub method for the remote method with the given
* operation number.
**/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
RemoteClass.Method method = remoteMethods[opnum];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type[] paramTypes = method.parameterTypes();
String paramNames[] = nameParameters(paramTypes);
Type returnType = methodDoc.returnType();
ClassDoc[] exceptions = method.exceptionTypes();
/*
* Declare stub method; throw exceptions declared in remote
* interface(s).
*/
p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
p.p("public " + returnType.toString() + " " + methodName + "(");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(paramTypes[i].toString() + " " + paramNames[i]);
}
p.plnI(")");
if (exceptions.length > 0) {
p.p("throws ");
for (int i = 0; i < exceptions.length; i++) {
if (i > 0) {
p.p(", ");
}
p.p(exceptions[i].qualifiedName());
}
p.pln();
}
p.pOlnI("{");
/*
* The RemoteRef.invoke methods throw Exception, but unless
* this stub method throws Exception as well, we must catch
* Exceptions thrown from the invocation. So we must catch
* Exception and rethrow something we can throw:
* UnexpectedException, which is a subclass of
* RemoteException. But for any subclasses of Exception that
* we can throw, like RemoteException, RuntimeException, and
* any of the exceptions declared by this stub method, we want
* them to pass through unmodified, so first we must catch any
* such exceptions and rethrow them directly.
*
* We have to be careful generating the rethrowing catch
* blocks here, because javac will flag an error if there are
* any unreachable catch blocks, i.e. if the catch of an
* exception class follows a previous catch of it or of one of
* its superclasses. The following method invocation takes
* care of these details.
*/
List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
/*
* If we need to catch any particular exceptions (i.e. this method
* does not declare java.lang.Exception), put the entire stub
* method in a try block.
*/
if (catchList.size() > 0) {
p.plnI("try {");
}
if (version == StubVersion.VCOMPAT) {
p.plnI("if (useNewInvoke) {");
}
if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
if (!Util.isVoid(returnType)) {
// REMIND: why $?
p.p("Object $result = ");
}
p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
if (paramTypes.length > 0) {
p.p("new java.lang.Object[] {");
for (int i = 0; i < paramTypes.length; i++) {
if (i > 0)
p.p(", ");
p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
}
p.p("}");
} else {
p.p("null");
}
p.pln(", " + method.methodHash() + "L);");
if (!Util.isVoid(returnType)) {
p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
}
}
if (version == StubVersion.VCOMPAT) {
p.pOlnI("} else {");
}
if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
if (paramTypes.length > 0) {
p.plnI("try {");
p.pln("java.io.ObjectOutput out = call.getOutputStream();");
writeMarshalArguments(p, "out", paramTypes, paramNames);
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
p.pOln("}");
}
p.pln("ref.invoke(call);");
if (Util.isVoid(returnType)) {
p.pln("ref.done(call);");
} else {
p.pln(returnType.toString() + " $result;");
// REMIND: why $?
p.plnI("try {");
p.pln("java.io.ObjectInput in = call.getInputStream();");
boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
p.pln(";");
p.pOlnI("} catch (java.io.IOException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
/*
* If any only if readObject has been invoked, we must catch
* ClassNotFoundException as well as IOException.
*/
if (objectRead) {
p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
}
p.pOlnI("} finally {");
p.pln("ref.done(call);");
p.pOln("}");
p.pln("return $result;");
}
}
if (version == StubVersion.VCOMPAT) {
// end if/else (useNewInvoke) block
p.pOln("}");
}
/*
* If we need to catch any particular exceptions, finally write
* the catch blocks for them, rethrow any other Exceptions with an
* UnexpectedException, and end the try block.
*/
if (catchList.size() > 0) {
for (ClassDoc catchClass : catchList) {
p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
p.pln("throw e;");
}
p.pOlnI("} catch (java.lang.Exception e) {");
p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
// end try/catch block
p.pOln("}");
}
// end stub method
p.pOln("}");
}
Example 29
Project: rest.li-master File: RestLiDoclet.java View source code |
/**
* Entry point for Javadoc Doclet.
*
* @param root {@link RootDoc} passed in by Javadoc
* @return is successful or not
*/
public static boolean start(RootDoc root) {
final DocInfo docInfo = new DocInfo();
for (ClassDoc classDoc : root.classes()) {
docInfo.setClassDoc(classDoc.qualifiedName(), classDoc);
for (MethodDoc methodDoc : classDoc.methods()) {
docInfo.setMethodDoc(MethodIdentity.create(methodDoc), methodDoc);
}
}
_currentDocLet = new RestLiDoclet(docInfo);
return true;
}
Example 30
Project: wso2-axis2-transports-master File: ResourceInfoDoclet.java View source code |
public static boolean start(RootDoc root) throws IOException {
parseOptions(root.options());
ResourceInfo resourceInfo = new ResourceInfo();
for (ClassDoc clazz : root.classes()) {
Resource resource = null;
for (MethodDoc method : clazz.methods()) {
if (getAnnotation(method, "org.apache.axis2.transport.testkit.tests.Setup") != null) {
if (resource == null) {
resource = new Resource(clazz.qualifiedName());
}
ParamTag[] paramTags = method.paramTags();
for (Parameter parameter : method.parameters()) {
Type type = parameter.type();
String name = parameter.name();
String comment = null;
for (ParamTag paramTag : paramTags) {
if (paramTag.parameterName().equals(name)) {
comment = paramTag.parameterComment();
break;
}
}
if (comment == null) {
comment = getFirstSentence(root.classNamed(type.qualifiedTypeName()));
}
resource.addDependency(type.qualifiedTypeName(), type.dimension().equals("[]") ? "0..*" : "1", comment);
}
}
}
if (resource != null) {
resourceInfo.addResource(resource);
}
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outFile));
out.writeObject(resourceInfo);
out.close();
return true;
}
Example 31
Project: cloudtm-data-platform-master File: AbstractConfigHtmlGenerator.java View source code |
protected void generateTableRowForAttribute(XSAttributeDecl a, StringBuilder sb, Object beanClassInstance) { sb.append("<tr class=\"b\">"); // name, type... sb.append("<td>").append("<code>" + a.getName() + "</code>").append("</td>\n"); sb.append("<td>").append("<code>" + a.getType().getName() + "</code>"); boolean isRestricted = false; XSRestrictionSimpleType restriction = a.getType().asRestriction(); Collection<? extends XSFacet> declaredFacets = restriction.getDeclaredFacets(); for (XSFacet facet : declaredFacets) { if (facet.getName().equalsIgnoreCase("enumeration")) { isRestricted = true; break; } } debug("attribute = " + a.getName() + "(restricted = " + isRestricted + ")", 1); // restriction on type... if (isRestricted) { sb.append("* ("); for (XSFacet facet : declaredFacets) { sb.append(facet.getValue().toString() + '|'); } sb.deleteCharAt(sb.length() - 1); sb.append(")</td>\n"); } else { sb.append("</td>\n"); } Field field = findField(beanClassInstance.getClass(), a.getName()); if (field == null) { throw new RuntimeException("Null field for " + beanClassInstance.getClass() + " attribute " + a.getName()); } // if default value specified in annotation use it if (a.getDefaultValue() != null) { debug("annotation-defined default = " + a.getDefaultValue(), 2); sb.append("<td>").append(a.getDefaultValue().toString()).append("</td>\n"); } else { // otherwise use reflected field and read default value Object defaultValue = null; try { defaultValue = ReflectionUtil.getValue(beanClassInstance, field.getName()); if (defaultValue != null) { sb.append("<td>").append(defaultValue.toString()).append("</td>\n"); debug("field-defined default = " + defaultValue, 2); } else { debug("field-defined default is null!", 2); sb.append("<td>").append("null").append("</td>\n"); } } catch (Exception e) { debug("Caught exception, bean is " + beanClassInstance.getClass() + ", looking for field " + a.getName() + ", field " + field, 2); e.printStackTrace(); sb.append("<td>").append("N/A").append("</td>\n"); } } // and finally description String desc = null; Doc docElement = null; ConfigurationDocRef docRef = null; if (field.isAnnotationPresent(ConfigurationDoc.class)) { desc = field.getAnnotation(ConfigurationDoc.class).desc(); } else if (field.isAnnotationPresent(ConfigurationDocRef.class)) { docRef = field.getAnnotation(ConfigurationDocRef.class); docElement = findDocElement(docRef.bean(), docRef.targetElement()); desc = docElement.commentText(); } if (desc != null) { sb.append("<td>").append(desc).append("\n"); String htmlFile = field.getDeclaringClass().getName().replace(".", "/").replace("$", ".").concat(".html"); //overridden by ConfigurationDocRef? if (docRef != null) { htmlFile = docRef.bean().getName().replace(".", "/").replace("$", ".").concat(".html"); if (docElement instanceof MethodDoc) { MethodDoc mDocElement = (MethodDoc) docElement; Parameter[] parameters = mDocElement.parameters(); //if this is MethodDoc then docRef is pointing to a method, get targetElement String targetElement = docRef.targetElement(); StringBuilder javadocTarget = new StringBuilder(targetElement); javadocTarget.append("("); for (Parameter parameter : parameters) { javadocTarget.append(parameter.type().qualifiedTypeName()).append(","); } javadocTarget.deleteCharAt(javadocTarget.length() - 1); javadocTarget.append(")"); sb.append(" (<a href=\"" + htmlFile.concat("#").concat(javadocTarget.toString()) + "\">" + "Javadoc</a>)"); } } else { sb.append(" (<a href=\"" + htmlFile.concat("#").concat(field.getName()) + "\">" + "Javadoc</a>)"); } sb.append("</td>\n"); } sb.append("</tr>\n"); }
Example 32
Project: geode-master File: UnitTestDoclet.java View source code |
/** * Summarizes the test methods of the given class */ public static void document(ClassDoc c, PrintWriter pw) throws IOException { pw.println(c.qualifiedName()); { String comment = c.commentText(); if (comment != null && !comment.equals("")) { pw.println(""); indent(comment, 4, pw); pw.println(""); } } MethodDoc[] methods = getTestMethods(c); for (int i = 0; i < methods.length; i++) { MethodDoc method = methods[i]; pw.print(" "); pw.println(method.name()); String comment = method.commentText(); if (comment != null && !comment.equals("")) { pw.println(""); indent(comment, 6, pw); pw.println(""); } } pw.println(""); }
Example 33
Project: hadaps-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 34
Project: hadoop-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 35
Project: hadoop-on-lustre2-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 36
Project: hadoop-release-2.6.0-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 37
Project: HadoopEKG-master File: RootDocProcessor.java View source code |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 38
Project: hbase-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
switch(methodName) {
case "classes":
return filter(((RootDoc) target).classes(), ClassDoc.class);
case "specifiedClasses":
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
case "specifiedPackages":
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
switch(methodName) {
case "methods":
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
case "fields":
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
case "innerClasses":
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
case "constructors":
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
switch(methodName) {
case "allClasses":
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
case "annotationTypes":
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
case "enums":
return filter(((PackageDoc) target).enums(), ClassDoc.class);
case "errors":
return filter(((PackageDoc) target).errors(), ClassDoc.class);
case "exceptions":
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
case "interfaces":
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
case "ordinaryClasses":
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 39
Project: HDP-2.2-Patched-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 40
Project: hops-master File: RootDocProcessor.java View source code |
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (target instanceof Doc) { if (methodName.equals("isIncluded")) { Doc doc = (Doc) target; return !exclude(doc) && doc.isIncluded(); } if (target instanceof RootDoc) { if (methodName.equals("classes")) { return filter(((RootDoc) target).classes(), ClassDoc.class); } else if (methodName.equals("specifiedClasses")) { return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class); } else if (methodName.equals("specifiedPackages")) { return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class); } } else if (target instanceof ClassDoc) { if (isFiltered(args)) { if (methodName.equals("methods")) { return filter(((ClassDoc) target).methods(true), MethodDoc.class); } else if (methodName.equals("fields")) { return filter(((ClassDoc) target).fields(true), FieldDoc.class); } else if (methodName.equals("innerClasses")) { return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class); } else if (methodName.equals("constructors")) { return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class); } } else { if (methodName.equals("methods")) { return filter(((ClassDoc) target).methods(true), MethodDoc.class); } } } else if (target instanceof PackageDoc) { if (methodName.equals("allClasses")) { if (isFiltered(args)) { return filter(((PackageDoc) target).allClasses(true), ClassDoc.class); } else { return filter(((PackageDoc) target).allClasses(), ClassDoc.class); } } else if (methodName.equals("annotationTypes")) { return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class); } else if (methodName.equals("enums")) { return filter(((PackageDoc) target).enums(), ClassDoc.class); } else if (methodName.equals("errors")) { return filter(((PackageDoc) target).errors(), ClassDoc.class); } else if (methodName.equals("exceptions")) { return filter(((PackageDoc) target).exceptions(), ClassDoc.class); } else if (methodName.equals("interfaces")) { return filter(((PackageDoc) target).interfaces(), ClassDoc.class); } else if (methodName.equals("ordinaryClasses")) { return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class); } } } if (args != null) { if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) { args[0] = unwrap(args[0]); } } try { return process(method.invoke(target, args), method.getReturnType()); } catch (InvocationTargetException e) { throw e.getTargetException(); } }
Example 41
Project: infinispan-master File: JmxDoclet.java View source code |
private static MBeanComponent toJmxComponent(ClassDoc cd) {
boolean isMBean = false;
MBeanComponent mbc = new MBeanComponent();
mbc.className = cd.qualifiedTypeName();
mbc.name = cd.typeName();
for (AnnotationDesc a : cd.annotations()) {
AnnotationTypeDoc atd = a.annotationType();
String annotationName = atd.qualifiedTypeName();
if (annotationName.equals(MBean.class.getName())) {
isMBean = true;
setNameDesc(a.elementValues(), mbc);
}
}
// now to test method level annotations
for (MethodDoc method : cd.methods()) {
for (AnnotationDesc a : method.annotations()) {
String annotationName = a.annotationType().qualifiedTypeName();
if (annotationName.equals(ManagedOperation.class.getName())) {
isMBean = true;
MBeanOperation o = new MBeanOperation();
o.name = method.name();
setNameDesc(a.elementValues(), o);
o.returnType = method.returnType().simpleTypeName();
for (Parameter p : method.parameters()) o.addParam(p.type().simpleTypeName());
mbc.operations.add(o);
} else if (annotationName.equals(ManagedAttribute.class.getName())) {
isMBean = true;
MBeanAttribute attr = new MBeanAttribute();
// if this is a getter, look at the return type
if (method.name().startsWith("get") || method.name().startsWith("is")) {
attr.type = method.returnType().simpleTypeName();
} else if (method.parameters().length > 0) {
attr.type = method.parameters()[0].type().simpleTypeName();
}
attr.name = fromBeanConvention(method.name());
setNameDesc(a.elementValues(), attr);
setWritable(a.elementValues(), attr);
mbc.attributes.add(attr);
}
}
}
// and field level annotations
for (FieldDoc field : cd.fields(false)) {
for (AnnotationDesc a : field.annotations()) {
String annotationName = a.annotationType().qualifiedTypeName();
if (annotationName.equals(ManagedAttribute.class.getName())) {
isMBean = true;
MBeanAttribute attr = new MBeanAttribute();
attr.name = field.name();
attr.type = field.type().simpleTypeName();
setNameDesc(a.elementValues(), attr);
setWritable(a.elementValues(), attr);
mbc.attributes.add(attr);
}
}
}
if (isMBean) {
Collections.sort(mbc.attributes);
Collections.sort(mbc.operations);
return mbc;
} else {
return null;
}
}
Example 42
Project: jaxrs-analyzer-master File: ResultInterpreterTest.java View source code |
@Test @Ignore public void testDescriptions() { final MethodDoc methodDocMock = mock(MethodDoc.class); when(methodDocMock.commentText()).thenReturn("Method description."); when(methodDocMock.paramTags()).thenReturn(new ParamTag[0]); when(methodDocMock.parameters()).thenReturn(new Parameter[0]); final Resources expectedResult = new Resources(); expectedResult.setBasePath("path"); final ResourceMethod resourceMethod = ResourceMethodBuilder.withMethod(HttpMethod.GET, "Method description.").andQueryParam("query", "Ljava/lang/String;", null).andResponse(200, ResponseBuilder.withResponseBody(STRING_IDENTIFIER).build()).build(); expectedResult.addMethod("test", resourceMethod); final ClassResult appPathResult = ClassResultBuilder.withApplicationPath("path/").build(); final MethodResult method = MethodResultBuilder.withResponses(HttpResponseBuilder.withStatues(200).andEntityTypes(Types.STRING).build()).andMethodDoc(methodDocMock).andQueryParam("query", "Ljava/lang/String;", null).andMethod(HttpMethod.GET).build(); final ClassResult resClassResult = ClassResultBuilder.withResourcePath("test").andMethods(method).build(); final Set<ClassResult> results = new HashSet<>(Arrays.asList(appPathResult, resClassResult)); final Resources actualResult = classUnderTest.interpret(results); assertEquals(expectedResult, actualResult); }
Example 43
Project: kodkod-master File: SpecificationTaglet.java View source code |
/** * {@inheritDoc} */ @Override public Content getTagletOutput(Doc doc, TagletWriter writer) throws IllegalArgumentException { Tag[] tags = doc.tags(getName()); if (// inherit if necessary and possible tags.length == 0 && doc instanceof MethodDoc) { final DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) doc, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] { inheritedDoc.holderTag }; } if (tags.length == 0) return null; final StringBuilder out = writeHeader(new StringBuilder()); for (Tag tag : tags) { writeTag(out, tag, writer); } return new RawHtml(out.toString()); }
Example 44
Project: oddjob-master File: Processor.java View source code |
/**
* Process all member fields and methods including superclasses.
*
* @param pageData
* @param classDoc
*/
void processAllMembers(WriteableBeanDoc pageData, ClassDoc classDoc) {
if (classDoc == null) {
return;
}
processAllMembers(pageData, classDoc.superclass());
FieldDoc[] fds = classDoc.fields();
for (int i = 0; i < fds.length; ++i) {
processFieldOrMethod(pageData, fds[i]);
}
MethodDoc[] mds = classDoc.methods();
for (int i = 0; i < mds.length; ++i) {
processFieldOrMethod(pageData, mds[i]);
}
}
Example 45
Project: pbase-master File: RootDocProcessor.java View source code |
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 46
Project: rest-doclet-master File: AbstractCollector.java View source code |
/**
* Retrieves all the end point provided in the specified class doc.
* @param contextPath
* @param classDoc
* @param classMapping
* @return
*/
protected Collection<Endpoint> getAllEndpoints(String contextPath, ClassDoc classDoc, EndpointMapping classMapping) {
Collection<Endpoint> endpoints = new ArrayList<Endpoint>();
for (MethodDoc method : classDoc.methods(true)) endpoints.addAll(getEndpoint(contextPath, classMapping, method));
//Check super classes for inherited methods
if (classDoc.superclass() != null)
endpoints.addAll(getAllEndpoints(contextPath, classDoc.superclass(), classMapping));
return endpoints;
}
Example 47
Project: RESTdoclet-master File: DocTypeUtils.java View source code |
/**
* Generates a comment string from the given method, consisting of the
* method return comment and if the return type is an iggroup type, a list
* of attributes (separated by <br>
* )
*
* @param element method doc
* @return documentation string for the method
*/
public static String getReturnDoc(final MethodDoc element) {
LOG.info("Get return type documentation for method: " + element.toString());
String doc = "";
Tag[] tags = element.tags();
String typeDoc = getTypeDoc(element.returnType());
for (final Tag tag : tags) {
final String name = tag.name();
if (StringUtils.contains(name, RETURN_TAG)) {
doc = tag.text();
if (!typeDoc.isEmpty()) {
doc += "<table><tr><td>" + typeDoc + "</td></tr></table>";
}
break;
}
}
//}
return doc;
}
Example 48
Project: restx-master File: ApidocsDoclet.java View source code |
/**
* The starting point of Javadoc render.
*
* _Javadoc spec requirement._
*
* @param rootDoc input class documents
* @return success
*/
@SuppressWarnings("UnusedDeclaration")
public static boolean start(RootDoc rootDoc) {
Path targetDir = Paths.get(Options.TARGET_DIR.getOption(rootDoc.options()).or(""));
rootDoc.printNotice("generating RESTX apidocs notes in: " + targetDir + " ...");
Path apidocsTarget = targetDir.resolve("apidocs");
if (!apidocsTarget.toFile().exists()) {
apidocsTarget.toFile().mkdirs();
}
Trace trace = Options.ENABLE_TRACE.isSet(rootDoc.options()) ? new FileTrace(targetDir.resolve("apidoclet.trace").toFile()) : new NoTrace();
trace.trace("RESTX APIDOCLET " + DateTime.now());
trace.trace("target dir : " + targetDir.toAbsolutePath());
trace.trace("current dir: " + Paths.get("").toAbsolutePath());
ObjectMapper mapper = new ObjectMapper();
for (ClassDoc classDoc : rootDoc.classes()) {
ApiEntryNotes entryNotes = new ApiEntryNotes().setName(classDoc.qualifiedName());
for (MethodDoc methodDoc : classDoc.methods()) {
for (AnnotationDesc annotationDesc : methodDoc.annotations()) {
if (annotationDesc.annotationType().qualifiedName().startsWith("restx.annotations.")) {
Optional<Object> value = getAnnotationParamValue(annotationDesc.elementValues(), "value");
if (value.isPresent()) {
trace.trace(classDoc.name() + " > " + methodDoc.qualifiedName() + " > " + annotationDesc.annotationType().name());
trace.trace(asList(annotationDesc.elementValues()).toString());
trace.trace(methodDoc.commentText());
ApiOperationNotes operation = new ApiOperationNotes().setHttpMethod(annotationDesc.annotationType().name()).setPath(String.valueOf(value.get())).setNotes(methodDoc.commentText());
for (ParamTag paramTag : methodDoc.paramTags()) {
trace.trace("\t" + paramTag.parameterName() + " > " + paramTag.parameterComment());
operation.getParameters().add(new ApiParameterNotes().setName(paramTag.parameterName()).setNotes(paramTag.parameterComment()));
}
for (Tag aReturn : methodDoc.tags("return")) {
trace.trace("\t" + aReturn.name() + " > " + aReturn.text());
operation.getParameters().add(new ApiParameterNotes().setName("response").setNotes(aReturn.text()));
}
entryNotes.getOperations().add(operation);
}
}
}
}
if (!entryNotes.getOperations().isEmpty()) {
Path doc = apidocsTarget.resolve(classDoc.qualifiedName() + ".notes.json");
rootDoc.printNotice("generating RESTX API entry notes for " + classDoc.qualifiedName() + " ...");
trace.trace("generating notes in " + doc.toAbsolutePath());
try {
mapper.writeValue(doc.toFile(), entryNotes);
} catch (IOException e) {
trace.trace("can't write to api doc file " + doc.toFile() + ": " + e);
rootDoc.printError("can't write to api doc file " + doc.toFile() + ": " + e);
}
} else {
trace.trace("no operations found on " + entryNotes.getName());
}
}
if (Options.DISABLE_STANDARD_DOCLET.isSet(rootDoc.options())) {
return true;
}
return Standard.start(rootDoc);
}
Example 49
Project: spacewalk-master File: ApiDoclet.java View source code |
/**
* start the doclet
* @param root the document root
* @param docType 'jsp' or 'wiki'
* @return boolean
* @throws Exception e
*/
public static boolean start(RootDoc root, String docType) throws Exception {
ClassDoc[] classes = root.classes();
List<ClassDoc> serializers = getSerializers(classes);
List<ClassDoc> handlers = getHandlers(classes);
Map<String, String> serialMap = getSerialMap(serializers);
List<Handler> handlerList = new ArrayList<Handler>();
for (ClassDoc clas : handlers) {
Handler handler = new Handler();
if (clas.tags(XMLRPC_IGNORE).length > 0) {
continue;
}
Tag name = getFirst(clas.tags(XMLRPC_NAMESPACE));
if (name != null) {
handler.setName(name.text());
} else {
String error = "Someone didn't set " + XMLRPC_NAMESPACE + " correctly on " + clas.name();
error += " If you really did not want this handler to appear in " + "the API docs. Add @xmlrpc.ignore to the class javadoc. ";
throw new Exception(error);
}
handler.setClassName(clas.name());
Tag classDesc = getFirst(clas.tags(XMLRPC_DOC));
if (classDesc != null) {
handler.setDesc(classDesc.text());
}
for (MethodDoc method : clas.methods()) {
if (method.isPublic() && getFirst(method.tags(XMLRPC_IGNORE)) == null) {
ApiCall call = new ApiCall(method);
call.setName(method.name());
Tag methodDoc = getFirst(method.tags(XMLRPC_DOC));
if (methodDoc != null) {
if (docType.equals("docbook")) {
call.setDoc(DocBookWriter.transcode(methodDoc.text()));
} else {
call.setDoc(methodDoc.text());
}
}
for (Tag param : method.tags(XMLRPC_PARAM)) {
if (docType.equals("docbook")) {
call.addParam(DocBookWriter.transcode(param.text()));
} else {
call.addParam(param.text());
}
}
if (method.tags(DEPRECATED).length > 0) {
call.setDeprecated(true);
call.setDeprecatedReason(getFirst(method.tags(DEPRECATED)).text());
}
if (method.tags(SINCE).length > 0) {
call.setSinceAvailable(true);
call.setSinceVersion(getFirst(method.tags(SINCE)).text());
}
Tag tag = getFirst(method.tags(XMLRPC_RETURN));
if (tag != null) {
//run templating on the return value
//call.setReturnDoc(serialHelper.renderTemplate(tag.text()));
call.setReturnDoc(tag.text());
}
//Finally add the newly built api to the handler
handler.addApiCall(call);
}
}
//Then simply sort the apicalls and add the handler to our List
Collections.sort(handler.getCalls());
handlerList.add(handler);
}
Collections.sort(handlerList);
DocWriter writer;
if (docType.equals("jsp")) {
writer = new JSPWriter();
} else if (docType.equals("html")) {
writer = new HtmlWriter();
} else if (docType.equals("list")) {
writer = new ListWriter();
} else if (docType.equals("singlepage")) {
writer = new SinglePageWriter();
} else if (docType.equals("docbook")) {
writer = new DocBookWriter();
} else {
writer = new JSPWriter();
}
writer.write(handlerList, serialMap);
return true;
}
Example 50
Project: yarn-comment-master File: RootDocProcessor.java View source code |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
Doc doc = (Doc) target;
return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
if (methodName.equals("classes")) {
return filter(((RootDoc) target).classes(), ClassDoc.class);
} else if (methodName.equals("specifiedClasses")) {
return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
} else if (methodName.equals("specifiedPackages")) {
return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
}
} else if (target instanceof ClassDoc) {
if (isFiltered(args)) {
if (methodName.equals("methods")) {
return filter(((ClassDoc) target).methods(true), MethodDoc.class);
} else if (methodName.equals("fields")) {
return filter(((ClassDoc) target).fields(true), FieldDoc.class);
} else if (methodName.equals("innerClasses")) {
return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
} else if (methodName.equals("constructors")) {
return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
}
}
} else if (target instanceof PackageDoc) {
if (methodName.equals("allClasses")) {
if (isFiltered(args)) {
return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
} else {
return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
}
} else if (methodName.equals("annotationTypes")) {
return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
} else if (methodName.equals("enums")) {
return filter(((PackageDoc) target).enums(), ClassDoc.class);
} else if (methodName.equals("errors")) {
return filter(((PackageDoc) target).errors(), ClassDoc.class);
} else if (methodName.equals("exceptions")) {
return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
} else if (methodName.equals("interfaces")) {
return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
} else if (methodName.equals("ordinaryClasses")) {
return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
}
}
}
if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) {
args[0] = unwrap(args[0]);
}
}
try {
return process(method.invoke(target, args), method.getReturnType());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
Example 51
Project: com.revolsys.open-master File: DocletUtil.java View source code |
public static void documentationReturn(final XmlWriter writer, final MethodDoc method) {
final Type type = method.returnType();
if (type != null && !"void".equals(type.qualifiedTypeName())) {
Tag[] descriptionTags = null;
for (final Tag tag : method.tags()) {
if (tag.name().equals("@return")) {
descriptionTags = tag.inlineTags();
}
}
writer.startTag(HtmlElem.DIV);
writer.startTag(HtmlElem.STRONG);
writer.text("Return");
writer.endTag(HtmlElem.STRONG);
writer.endTagLn(HtmlElem.DIV);
typeNameLink(writer, type);
writer.text(" ");
description(writer, method.containingClass(), descriptionTags);
}
}
Example 52
Project: DPJ-master File: ClassDocImpl.java View source code |
/**
* Return methods in class.
* This method is overridden by AnnotationTypeDocImpl.
*
* @param filter include only the included methods if filter==true
* @return an array of MethodDocImpl for representing the visible
* methods in this class. Does not include constructors.
*/
public MethodDoc[] methods(boolean filter) {
Name.Table names = tsym.name.table;
List<MethodDocImpl> methods = List.nil();
for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
if (e.sym != null && e.sym.kind == Kinds.MTH && e.sym.name != names.init) {
MethodSymbol s = (MethodSymbol) e.sym;
if (!filter || env.shouldDocument(s)) {
methods = methods.prepend(env.getMethodDoc(s));
}
}
}
//### Cache methods here?
return methods.toArray(new MethodDocImpl[methods.length()]);
}
Example 53
Project: flatpack-java-master File: DocStringsDoclet.java View source code |
private void examineClass(ClassDoc clazz) throws IOException {
JsonWriter writer = getJsonWriter(clazz);
String classKey = key(clazz);
// Possibly extract the class's contents
if (hasAnnotation(clazz, EXAMPLE_TYPE_NAME)) {
String contents = extractContents(clazz);
writer.name(classKey + ":contents");
writer.value(contents);
}
String doc = docString(clazz);
if (!doc.isEmpty()) {
writer.name(classKey);
writer.value(doc);
}
for (FieldDoc f : clazz.fields(true)) {
doc = docString(f);
if (doc.isEmpty()) {
continue;
}
writer.name(key(f));
writer.value(doc);
}
for (MethodDoc m : clazz.methods(true)) {
String methodKey = key(m);
// Possibly extract the method's contents
if (hasAnnotation(m, EXAMPLE_TYPE_NAME)) {
String contents = extractContents(m);
writer.name(methodKey + ":contents");
writer.value(contents);
}
doc = docString(m);
if (doc.isEmpty()) {
continue;
}
writer.name(methodKey);
writer.value(doc);
Map<String, Integer> namesToPositions = new HashMap<String, Integer>();
for (Parameter param : m.parameters()) {
namesToPositions.put(param.name(), namesToPositions.size());
}
for (ParamTag tag : m.paramTags()) {
Integer position = namesToPositions.get(tag.parameterName());
// Handle @param tags for non-existant parameters
if (position == null) {
continue;
}
writer.name(methodKey + "[" + position + "]");
writer.value(docString(tag));
}
}
}
Example 54
Project: maven-jellydoc-plugin-master File: TagXMLDoclet.java View source code |
/**
* Generates doc for a tag property
*/
private void propertyXML(MethodDoc methodDoc, org.jvnet.maven.jellydoc.Tag tag) throws SAXException {
if (!methodDoc.isPublic() || methodDoc.isStatic()) {
return;
}
String name = methodDoc.name();
if (!name.startsWith("set")) {
return;
}
Parameter[] parameterArray = methodDoc.parameters();
if (parameterArray == null || parameterArray.length != 1) {
return;
}
Parameter parameter = parameterArray[0];
name = name.substring(3);
name = Introspector.decapitalize(name);
if (name.equals("body") || name.equals("context") || name.equals("parent")) {
return;
}
Attribute a = tag.attribute();
a.name(name);
a.type(parameter.typeName());
if (has(methodDoc, Required.class))
a.use("required");
// maybe do more semantics, like use custom tags to denote if its required, optional etc.
// generate "doc" sub-element
docXML(methodDoc, a);
}
Example 55
Project: Prendamigo-master File: JUnitTestConverter.java View source code |
/** * This method is required for all doclets. * * @return true on success. */ public static boolean start(RootDoc root) { ClassDoc[] classes = root.classes(); for (ClassDoc cd : classes) { if (!isJUnitTest(cd)) { continue; } if (!cd.isAbstract()) m_classNames.add(cd.qualifiedTypeName()); File file; if (null != cd.position().file()) { file = cd.position().file(); } else { file = findFileName(cd); } String fqn = cd.qualifiedTypeName(); int tn = fqn.indexOf(cd.typeName()); if (tn > 0) { m_packageNames.put(file, fqn.substring(0, tn - 1)); } m_typelines.put(file, new Integer(cd.position().line())); MethodDoc[] methods = cd.methods(); List<MethodDoc> testMethods = Lists.newArrayList(); for (MethodDoc md : methods) { if (isTest(md) || isSetUp(md) || isTearDown(md)) { // Add the lines backward, so we can insert them without messing // up their order later testMethods.add(0, md); } } m_files.put(file, testMethods); } return true; }
Example 56
Project: ant-git-tasks-master File: AntTaskDoclet.java View source code |
private static void registerClassData(ClassDoc doc) {
ClassData data = new ClassData();
Scanner sc = new Scanner(doc.commentText());
data.description = sc.nextLine();
sc.close();
data.qualifiedName = doc.qualifiedTypeName();
data.simpleName = doc.name();
data.hidden = doc.isAbstract();
data.parentClassDatas.addAll(collectParentClassesNames(doc));
for (MethodDoc methodDoc : doc.methods()) {
if (!isHiddenMethodDoc(methodDoc)) {
if (isTaskAttribute(methodDoc)) {
data.attributesList.add(AttributeData.fromMethodDoc(methodDoc));
} else if (isTaskElement(methodDoc)) {
data.elementsList.add(ElementData.fromMethodDoc(methodDoc));
}
}
}
classDataMap.put(data.qualifiedName, data);
}
Example 57
Project: gwt-exporter-master File: JsDoclet.java View source code |
@Override protected void generateOtherFiles(RootDoc rootDoc, ClassTree classTree) throws Exception { super.generateOtherFiles(rootDoc, classTree); HtmlDocletWriter writer = new HtmlDocletWriter(configuration, "jsdoc.html"); writer.html(); writer.head(); writer.println("<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>"); writer.println(getCSS()); writer.headEnd(); writer.body("white", true); ClassDoc[] classes = rootDoc.classes(); Arrays.sort(classes); // Document static methods List<MethodDoc> smethods = new ArrayList<MethodDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz)) { // FIXME: implement exportoverlay somehow. classTypeMap.put(clz.simpleTypeName(), getExportedName(clz, false, true)); if (hasStaticMethods(clz)) { for (MethodDoc md : clz.methods()) { if (md.isStatic() && isExportable(md)) { smethods.add(md); } } } } } if (smethods.size() > 0) { writer.h1("Exported JavaScript-API: Index of static functions"); writer.table(1, "100%", 0, 0); java.util.Collections.sort(smethods); for (MethodDoc md : smethods) { writeMethod(writer, false, true, md); } writer.tableEnd(); } List<ClassDoc> eclasses = new ArrayList<ClassDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz) && hasClassMethods(clz) && !isExportedClosure(clz)) { eclasses.add(clz); } } if (eclasses.size() > 0) { // Write an index of classes writer.h1("Exported JavaScript-API: Index of Classes"); writer.ul(); for (ClassDoc clz : eclasses) { writer.li(); writer.println(getExportedName(clz, true, true)); } writer.ulEnd(); // Write each class for (ClassDoc clz : eclasses) { String className = getExportedName(clz, false, true); writer.h2("<div id=" + className + ">" + className + "</div>"); String comments = clz.commentText().trim(); if (!comments.isEmpty()) { writer.println("<div class=jsdocText>" + filter(clz.commentText()) + "</div>"); } writer.table(1, "100%", 0, 0); writeConstructors(writer, clz); writeMethods(writer, clz, true, isExportedAll(clz), new ArrayList<String>()); writer.tableEnd(); } } writer.bodyEnd(); writer.htmlEnd(); writer.flush(); writer.close(); }
Example 58
Project: gwt-exporter-old-master File: JsDoclet.java View source code |
@Override protected void generateOtherFiles(RootDoc rootDoc, ClassTree classTree) throws Exception { super.generateOtherFiles(rootDoc, classTree); HtmlDocletWriter writer = new HtmlDocletWriter(configuration, "jsdoc.html"); writer.html(); writer.head(); writer.println("<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>"); writer.println(getCSS()); writer.headEnd(); writer.body("white", true); ClassDoc[] classes = rootDoc.classes(); Arrays.sort(classes); // Document static methods List<MethodDoc> smethods = new ArrayList<MethodDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz)) { // FIXME: implement exportoverlay somehow. classTypeMap.put(clz.simpleTypeName(), getExportedName(clz, false, true)); if (hasStaticMethods(clz)) { for (MethodDoc md : clz.methods()) { if (md.isStatic() && isExportable(md)) { smethods.add(md); } } } } } if (smethods.size() > 0) { writer.h1("Exported JavaScript-API: Index of static functions"); writer.table(1, "100%", 0, 0); java.util.Collections.sort(smethods); for (MethodDoc md : smethods) { writeMethod(writer, false, true, md); } writer.tableEnd(); } List<ClassDoc> eclasses = new ArrayList<ClassDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz) && hasClassMethods(clz) && !isExportedClosure(clz)) { eclasses.add(clz); } } if (eclasses.size() > 0) { // Write an index of classes writer.h1("Exported JavaScript-API: Index of Classes"); writer.ul(); for (ClassDoc clz : eclasses) { writer.li(); writer.println(getExportedName(clz, true, true)); } writer.ulEnd(); // Write each class for (ClassDoc clz : eclasses) { String className = getExportedName(clz, false, true); writer.h2("<div id=" + className + ">" + className + "</div>"); String comments = clz.commentText().trim(); if (!comments.isEmpty()) { writer.println("<div class=jsdocText>" + filter(clz.commentText()) + "</div>"); } writer.table(1, "100%", 0, 0); writeConstructors(writer, clz); writeMethods(writer, clz, true, isExportedAll(clz), new ArrayList<String>()); writer.tableEnd(); } } writer.bodyEnd(); writer.htmlEnd(); writer.flush(); writer.close(); }
Example 59
Project: OpenJML-master File: MethodWriterJml.java View source code |
/** * Write the javadoc tags (e.g. param and return tags) for the given method * and then write any JML specifications. * * @param method the method being documented. */ // FIXME - major change in b144 // @Override // public void writeTags(@NonNull MethodDoc method) { // super.writeTags(method); // writeJmlSpecs(method); // } // /** Write the JML specifications for the given method. * * @param method the method whose specs are to be written */ public void writeJmlSpecs(MethodDoc method) { if (method instanceof MethodDocImpl) { MethodSymbol oldMethodSym = ((MethodDocImpl) method).sym; Context context = org.jmlspecs.openjml.jmldoc.Main.jmlContext; Name newMethodName = Names.instance(context).fromString(oldMethodSym.name.toString()); Scope.Entry e = currentClassSym.members().lookup(newMethodName); while (!(e.sym instanceof MethodSymbol) || !match((MethodSymbol) e.sym, oldMethodSym)) { //Scope.Entry ee = e; e = e.sibling; if (e == null) { // FIXME - not found? return; //} //e = ee.scope.lookup(newMethodName); } } MethodSymbol newMethodSym = (MethodSymbol) e.sym; JmlSpecs.MethodSpecs mspecs = JmlSpecs.instance(context).getSpecs(newMethodSym); if (mspecs != null) { // Need this if there is tag info, otherwise not // FIXME writer.br(); String s = Utils.jmlAnnotations(newMethodSym); if (Utils.hasSpecs(mspecs) || s.length() != 0) { strong("JML Method Specifications: "); writer.print(s); writer.preNoNewLine(); writer.print(JmlPretty.write(mspecs.cases, false)); writer.preEnd(); } for (ClassSymbol c : Utils.getSupers(currentClassSym)) { MethodSymbol m = findSameContext(newMethodSym, c); if (m != null) { mspecs = JmlSpecs.instance(context).getSpecs(m); String ss = Utils.jmlAnnotations(m); if (Utils.hasSpecs(mspecs) || ss.length() != 0) { strong("JML Specifications inherited from " + c + ": "); writer.print(ss); writer.preNoNewLine(); writer.print(JmlPretty.write(mspecs.cases, false)); writer.preEnd(); } } } } } }
Example 60
Project: osgi-maven-master File: JsDoclet.java View source code |
@Override protected void generateOtherFiles(RootDoc rootDoc, ClassTree classTree) throws Exception { super.generateOtherFiles(rootDoc, classTree); HtmlDocletWriter writer = new HtmlDocletWriter(configuration, "jsdoc.html"); writer.html(); writer.head(); writer.println("<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>"); writer.println(getCSS()); writer.headEnd(); writer.body("white", true); ClassDoc[] classes = rootDoc.classes(); Arrays.sort(classes); // Document static methods List<MethodDoc> smethods = new ArrayList<MethodDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz)) { // FIXME: implement exportoverlay somehow. classTypeMap.put(clz.simpleTypeName(), getExportedName(clz, false, true)); if (hasStaticMethods(clz)) { for (MethodDoc md : clz.methods()) { if (md.isStatic() && isExportable(md)) { smethods.add(md); } } } } } if (smethods.size() > 0) { writer.h1("Exported JavaScript-API: Index of static functions"); writer.table(1, "100%", 0, 0); java.util.Collections.sort(smethods); for (MethodDoc md : smethods) { writeMethod(writer, false, true, md); } writer.tableEnd(); } List<ClassDoc> eclasses = new ArrayList<ClassDoc>(); for (ClassDoc clz : classes) { if (isExportable(clz) && hasClassMethods(clz) && !isExportedClosure(clz)) { eclasses.add(clz); } } if (eclasses.size() > 0) { // Write an index of classes writer.h1("Exported JavaScript-API: Index of Classes"); writer.ul(); for (ClassDoc clz : eclasses) { writer.li(); writer.println(getExportedName(clz, true, true)); } writer.ulEnd(); // Write each class for (ClassDoc clz : eclasses) { String className = getExportedName(clz, false, true); writer.h2("<div id=" + className + ">" + className + "</div>"); String comments = clz.commentText().trim(); if (!comments.isEmpty()) { writer.println("<div class=jsdocText>" + filter(clz.commentText()) + "</div>"); } writer.table(1, "100%", 0, 0); writeConstructors(writer, clz); writeMethods(writer, clz, true, isExportedAll(clz), new ArrayList<String>()); writer.tableEnd(); } } writer.bodyEnd(); writer.htmlEnd(); writer.flush(); writer.close(); }
Example 61
Project: xml-doclet-master File: Parser.java View source code |
protected Interface parseInterface(ClassDoc classDoc) {
Interface interfaceNode = objectFactory.createInterface();
interfaceNode.setName(classDoc.name());
interfaceNode.setQualified(classDoc.qualifiedName());
String comment = classDoc.commentText();
if (comment.length() > 0) {
interfaceNode.setComment(comment);
}
interfaceNode.setIncluded(classDoc.isIncluded());
interfaceNode.setScope(parseScope(classDoc));
for (TypeVariable typeVariable : classDoc.typeParameters()) {
interfaceNode.getGeneric().add(parseTypeParameter(typeVariable));
}
for (Type interfaceType : classDoc.interfaceTypes()) {
interfaceNode.getInterface().add(parseTypeInfo(interfaceType));
}
for (MethodDoc method : classDoc.methods()) {
interfaceNode.getMethod().add(parseMethod(method));
}
for (AnnotationDesc annotationDesc : classDoc.annotations()) {
interfaceNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, classDoc.qualifiedName()));
}
for (Tag tag : classDoc.tags()) {
interfaceNode.getTag().add(parseTag(tag));
}
for (FieldDoc field : classDoc.fields()) {
interfaceNode.getField().add(parseField(field));
}
return interfaceNode;
}
Example 62
Project: antdoclet-master File: AntDoc.java View source code |
/** * Searches the given class for the appropriate setter or getter for the given attribute. * This method only returns the getter if no setter is available. * If the given class provides no method declaration, the superclasses are * searched recursively. * * @param attribute * @param methods * @return The MethodDoc for the given attribute or null if not found */ private static MethodDoc getMethodFor(ClassDoc classDoc, String attribute) { if (classDoc == null) { return null; } MethodDoc result = null; MethodDoc[] methods = classDoc.methods(); for (int i = 0; i < methods.length; i++) { // but if the documentation is only on the "getter", use it if (methods[i].name().equalsIgnoreCase("set" + attribute)) { return methods[i]; } else if (methods[i].name().equalsIgnoreCase("get" + attribute)) { result = methods[i]; } } if (result == null) { return getMethodFor(classDoc.superclass(), attribute); } return result; }
Example 63
Project: fawkez-old-master File: XmlDoclet.java View source code |
private void generateClassBody(ClassDoc cd) throws IOException { generateProgramElementBody(cd); // Interfaces final ClassDoc[] interfaces = cd.interfaces(); for (int i = 0; i < interfaces.length; ++i) { mOut.write("<interface"); addAttribute("name", interfaces[i].qualifiedName()); mOut.write("/>\n"); } // InnerClasses final ClassDoc[] innerClass = cd.innerClasses(); for (int i = 0; i < innerClass.length; ++i) { mOut.write("<inner"); addAttribute("name", innerClass[i].qualifiedName()); mOut.write("/>\n"); } // Fields final FieldDoc[] fields = cd.fields(); for (int i = 0; i < fields.length; ++i) { final FieldDoc field = fields[i]; generateFieldHeader(field); generateFieldBody(field); mOut.write("</field>\n"); } // Constructors final ConstructorDoc[] constructors = cd.constructors(); for (int i = 0; i < constructors.length; ++i) { final ConstructorDoc constructor = constructors[i]; generateConstructorHeader(constructor); generateConstructorBody(constructor); mOut.write("</constructor>\n"); } // Methods. final MethodDoc[] methods = cd.methods(); for (int i = 0; i < methods.length; ++i) { final MethodDoc method = methods[i]; generateMethodHeader(method); generateMethodBody(method); mOut.write("</method>\n"); } }
Example 64
Project: gmf-tooling-master File: ProxyFactory.java View source code |
public ExecutableMemberDocProxy createExecutableMemberDocProxy(ExecutableMemberDoc executableMemberDoc) { ExecutableMemberDocProxy proxy = null; if (executableMemberDoc != null) { proxy = (ExecutableMemberDocProxy) getProxyRegistry().getProxyForObject(executableMemberDoc); if (proxy == null) { if (executableMemberDoc instanceof ConstructorDoc) { proxy = createConstructorDocProxy((ConstructorDoc) executableMemberDoc); } else if (executableMemberDoc instanceof MethodDoc) { proxy = createMethodDocProxy((MethodDoc) executableMemberDoc); } else { proxy = new ExecutableMemberDocProxy(executableMemberDoc); ProxyFactory.getInstance().getProxyRegistry().registerProxy(executableMemberDoc, proxy); } } } return proxy; }
Example 65
Project: jersey-master File: ResourceDoclet.java View source code |
/**
* Start the doclet.
*
* @param root the root JavaDoc document.
* @return true if no exception is thrown.
*/
public static boolean start(final RootDoc root) {
final String output = getOptionArg(root.options(), OPTION_OUTPUT);
final String classpath = getOptionArg(root.options(), OPTION_CLASSPATH);
// LOG.info( "Have classpath: " + classpath );
final String[] classpathElements = classpath.split(File.pathSeparator);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final ClassLoader ncl = new Loader(classpathElements, ResourceDoclet.class.getClassLoader());
Thread.currentThread().setContextClassLoader(ncl);
final String docProcessorOption = getOptionArg(root.options(), OPTION_DOC_PROCESSORS);
final String[] docProcessors = docProcessorOption != null ? docProcessorOption.split(":") : null;
final DocProcessorWrapper docProcessor = new DocProcessorWrapper();
try {
if (docProcessors != null && docProcessors.length > 0) {
final Class<?> clazz = Class.forName(docProcessors[0], true, Thread.currentThread().getContextClassLoader());
final Class<? extends DocProcessor> dpClazz = clazz.asSubclass(DocProcessor.class);
docProcessor.add(dpClazz.newInstance());
}
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not load docProcessors " + docProcessorOption, e);
}
try {
final ResourceDocType result = new ResourceDocType();
final ClassDoc[] classes = root.classes();
for (final ClassDoc classDoc : classes) {
LOG.fine("Writing class " + classDoc.qualifiedTypeName());
final ClassDocType classDocType = new ClassDocType();
classDocType.setClassName(classDoc.qualifiedTypeName());
classDocType.setCommentText(classDoc.commentText());
docProcessor.processClassDoc(classDoc, classDocType);
for (final MethodDoc methodDoc : classDoc.methods()) {
final MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodDoc.name());
methodDocType.setMethodSignature(methodDoc.signature());
methodDocType.setCommentText(methodDoc.commentText());
docProcessor.processMethodDoc(methodDoc, methodDocType);
addParamDocs(methodDoc, methodDocType, docProcessor);
addRequestRepresentationDoc(methodDoc, methodDocType);
addResponseDoc(methodDoc, methodDocType);
classDocType.getMethodDocs().add(methodDocType);
}
result.getDocs().add(classDocType);
}
try {
final Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
final JAXBContext c = JAXBContext.newInstance(clazzes);
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
final String[] cdataElements = getCDataElements(docProcessor);
final XMLSerializer serializer = getXMLSerializer(out, cdataElements);
m.marshal(result, serializer);
out.close();
LOG.info("Wrote " + output);
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);
return false;
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return true;
}
Example 66
Project: mule-devkit-master File: Converter.java View source code |
private static void initClass(ClassDoc c, ClassInfo cl) { MethodDoc[] annotationElements; if (c instanceof AnnotationTypeDoc) { annotationElements = ((AnnotationTypeDoc) c).elements(); } else { annotationElements = new MethodDoc[0]; } cl.init(Converter.obtainType(c), Converter.convertClasses(c.interfaces()), Converter.convertTypes(c.interfaceTypes()), Converter.convertClasses(c.innerClasses()), Converter.convertMethods(c.constructors(false)), Converter.convertMethods(c.methods(false)), Converter.convertMethods(annotationElements), Converter.convertFields(c.fields(false)), Converter.convertFields(c.enumConstants()), Converter.obtainPackage(c.containingPackage()), Converter.obtainClass(c.containingClass()), Converter.obtainClass(c.superclass()), Converter.obtainType(c.superclassType()), Converter.convertAnnotationInstances(c.annotations())); cl.setHiddenMethods(Converter.getHiddenMethods(c.methods(false))); cl.setNonWrittenConstructors(Converter.convertNonWrittenConstructors(c.constructors(false))); cl.init3(Converter.convertTypes(c.typeParameters()), Converter.convertClasses(c.innerClasses(false))); }
Example 67
Project: xchain-master File: NamespaceDoclet.java View source code |
/**
* Add all the attributes for the given class to the given StringBuffer.
*
* @param doc The StringBuffer to append to.
* @param command The command to inspect.
*/
private static void appendAttributes(StringBuffer doc, ClassDoc command) {
// Get attributes from interfaces.
for (ClassDoc parentClassDoc : command.interfaces()) {
appendAttributes(doc, parentClassDoc);
}
// Get attributes from super class.
if (command.superclass() != null) {
appendAttributes(doc, command.superclass());
}
for (MethodDoc methodDoc : command.methods()) {
if (isAttribute(methodDoc)) {
AnnotationDesc annoDesc = getAnnotation(methodDoc.annotations(), Attribute.class);
doc.append(createIndent(5)).append("<tr>");
doc.append("<td>").append(getAttributeName(annoDesc)).append("</td>");
doc.append("<td>").append(methodDoc.commentText()).append("</td>");
String attributeType = getAttributeType(annoDesc);
doc.append("<td><a href=\"./attributetypes.html#").append(attributeType).append("\">").append(attributeType).append("</a></td>");
doc.append("<td>").append(getAttributeDefaultValue(annoDesc)).append("</td>");
doc.append("<td>").append(methodDoc.returnType().typeName()).append("</td>");
doc.append("</tr>\n");
}
}
}
Example 68
Project: bazooka-wo-xmldoclet-master File: XMLDoclet.java View source code |
/** * Transforms an array of methods and an array of constructor methods into XML and adds those to the host node. * * @param methods The methods. * @param constructors The constructors. * @param node The node to add the XML to. */ private static XMLNode toMethods(MethodDoc[] methods) { if (methods.length < 1) return null; // Create the <methods> node XMLNode node = new XMLNode("methods"); // Add the <method> nodes for (MethodDoc method : methods) { XMLNode methodNode = new XMLNode("method"); updateExecutableMemberNode(method, methodNode); methodNode.attribute("type", method.returnType().typeName()); methodNode.attribute("fulltype", method.returnType().toString()); methodNode.attribute("dimension", method.returnType().dimension()); methodNode.attribute("abstract", method.isAbstract()); methodNode.attribute("varargs", method.isVarArgs()); MethodDoc overrides = method.overriddenMethod(); if (overrides != null) { methodNode.attribute("overrides", overrides.toString()); } Tag[] returnTags = method.tags("@return"); if (returnTags.length > 0) { XMLNode returnNode = new XMLNode("returns"); returnNode.text(toComment(returnTags[0])); methodNode.child(returnNode); } // standard block tags methodNode.child(toStandardTags(method)); // Deprecated toDeprecated(method, methodNode); node.child(methodNode); } return node; }
Example 69
Project: dtf-master File: DTFDoclet.java View source code |
public static boolean start(RootDoc root) throws Exception {
ClassDoc[] classes = root.classes();
ArrayList<String> packagenames = new ArrayList<String>();
HashMap<String, ArrayList<ClassDoc>> packages = new HashMap<String, ArrayList<ClassDoc>>();
ArrayList<String> fgroupnames = new ArrayList<String>();
HashMap<String, ArrayList<DTFDoc>> fgroups = new HashMap<String, ArrayList<DTFDoc>>();
String[][] options = root.options();
String destination = null;
String xsd = null;
for (int i = 0; i < options.length; i++) {
if (options[i][0].equals("-d")) {
destination = options[i][1];
}
if (options[i][0].equals("-dtfxsd")) {
xsd = options[i][1];
}
}
if (destination == null) {
throw new IllegalArgumentException("-d option needs to be specified");
}
if (xsd == null) {
throw new IllegalArgumentException("-dtfxsd option needs to be specified");
}
String tagdir = destination + File.separatorChar + TAGS_DIRECOTRY;
File dir = new File(tagdir);
if (!dir.exists() && !dir.mkdirs()) {
throw new DTFException("Unable to create directory [" + tagdir + "]");
}
String featuredir = destination + File.separatorChar + FEATURES_DIRECTORY;
dir = new File(featuredir);
if (!dir.exists() && !dir.mkdirs()) {
throw new DTFException("Unable to create directory [" + featuredir + "]");
}
PrintStream psIndex = createFile(destination + File.separatorChar + "index.html");
psIndex.println("<html>");
psIndex.println(" <head>");
psIndex.println(" <link rel='stylesheet' " + "href='main.css' " + "type='text/css'>");
psIndex.println(" </head>");
psIndex.println(" <body id='body'>");
psIndex.println(" <h1>DTF Documentation</h1>");
ArrayList<String> tnames = new ArrayList<String>();
ArrayList<String> fnames = new ArrayList<String>();
/*
* 1st phase
*
* Filter out non DTF related JavaDocs and also gather the list of
* packages that contain different DTF Actions. Create a TOC for the
* whole document.
*/
for (int i = 0; i < classes.length; ++i) {
ClassDoc classdoc = classes[i];
/*
* Identify which ones have DTF XML tags
*/
if (classdoc.tags(DTF_TAG).length != 0) {
String classname = classdoc.qualifiedName();
String packagename = classname.substring(0, classname.lastIndexOf("."));
tnames.add(classname.replace(packagename + ".", "").toLowerCase());
if (!packages.containsKey(packagename)) {
packages.put(packagename, new ArrayList<ClassDoc>());
packagenames.add(packagename);
}
packages.get(packagename).add(classdoc);
}
MethodDoc[] methoddocs = classes[i].methods();
for (int m = 0; m < methoddocs.length; m++) {
if (methoddocs[m].tags(DTF_FEATURE).length != 0) {
String fgroup = methoddocs[m].tags(DTF_FEATURE_GROUP)[0].text();
if (!fgroups.containsKey(fgroup)) {
fgroups.put(fgroup, new ArrayList<DTFDoc>());
fgroupnames.add(fgroup);
}
DTFDoc dtfdoc = new DTFDoc();
dtfdoc.name = methoddocs[m].tags(DTF_FEATURE)[0].text();
dtfdoc.descriptions = methoddocs[m].tags(DTF_FEATURE_DESC);
dtfdoc.examples = methoddocs[m].tags(DTF_EXAMPLE);
fnames.add(dtfdoc.name.trim().toLowerCase());
fgroups.get(fgroup).add(dtfdoc);
}
}
/*
* Find the documented features through out the code as well
*/
if (classdoc.tags(DTF_FEATURE).length != 0) {
String fgroup = classdoc.tags(DTF_FEATURE_GROUP)[0].text();
if (!fgroups.containsKey(fgroup)) {
fgroups.put(fgroup, new ArrayList<DTFDoc>());
fgroupnames.add(fgroup);
}
DTFDoc dtfdoc = new DTFDoc();
dtfdoc.name = classdoc.tags(DTF_FEATURE)[0].text();
dtfdoc.descriptions = classdoc.tags(DTF_FEATURE_DESC);
dtfdoc.examples = classdoc.tags(DTF_EXAMPLE);
dtfdoc.qname = classdoc.qualifiedName();
fnames.add(dtfdoc.name.trim().toLowerCase());
fgroups.get(fgroup).add(dtfdoc);
}
}
/*
* Sorting makes it easier to find what you want in the documentation
*/
Collections.sort(packagenames);
Collections.sort(fgroupnames);
Iterator<String> iter = fgroupnames.iterator();
psIndex.println("<div id='features'>");
psIndex.println(" <div id='features_title'>Features</div>");
int counttags = 0;
while (iter.hasNext()) {
if (counttags == 0) {
psIndex.println("<div class='feature_row'>");
}
psIndex.println("<div class='feature_div'>");
String feature = (String) iter.next();
psIndex.println("<div class='feature_name'>" + feature + "</div>");
psIndex.println("<div id='collapsible_" + feature + "' class='feature_elems'" + "style='display: block;'>");
ArrayList<DTFDoc> features = fgroups.get(feature);
for (int i = 0; i < features.size(); i++) {
DTFDoc dtfdoc = features.get(i);
psIndex.println("<a class='feature_elem' href='" + FEATURES_DIRECTORY + "/" + dtfdoc.name.toLowerCase() + ".html'>" + dtfdoc.name + "</a>");
}
psIndex.println("</div>");
psIndex.println("</div>");
counttags++;
if (counttags == 4) {
psIndex.println("</div>");
counttags = 0;
}
}
if (counttags > 0) {
psIndex.println("</div>");
}
psIndex.println("</div>");
/*
* Link to the root element of the DTF XML as a starting point for the
* testcase writing.
*/
Collections.sort(packagenames);
iter = packagenames.iterator();
psIndex.println("<div id='tags'>");
psIndex.println("<div id='tags_title'>Tags</div>");
counttags = 0;
while (iter.hasNext()) {
String pname = (String) iter.next();
ArrayList<ClassDoc> tags = packages.get(pname);
String aux = pname.substring(pname.lastIndexOf(".actions.") + "actions.".length() + 1);
aux = aux.replaceAll("\\.", " ");
aux = StringUtil.capitalize(aux);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < tags.size(); i++) {
ClassDoc classdoc = (ClassDoc) tags.get(i);
if (classdoc.tags(DTF_SKIP_INDEX).length == 0) {
String tagname = classdoc.name().toLowerCase();
buffer.append("<a class='tag_elem' href='" + TAGS_DIRECOTRY + "/" + tagname + ".html'>" + tagname + "</a> ");
}
}
if (buffer.length() != 0) {
if (counttags == 0) {
psIndex.println("<div class='tag_row'>");
}
psIndex.println("<div class='tag_div'>");
psIndex.println("<div class='tag_name' " + "onclick=\"togglediv('collapsible_" + aux + "');\">" + aux + "</div>");
psIndex.println("<div id='collapsible_" + aux + "' " + "class='tag_elems' " + "style='display: block;'>");
psIndex.print(buffer.toString());
psIndex.println("</div>");
psIndex.println("</div>");
counttags++;
if (counttags == 5) {
psIndex.println("</div>");
counttags = 0;
}
}
}
if (counttags > 0) {
psIndex.println("</div>");
}
psIndex.println("</div>");
/*
* 1st phase
*
* Tag documentation generation that will generate a separate HTML file
* for each of the DTF actions that are documented with DTF javadoc
* tags.
*/
iter = packagenames.iterator();
FileInputStream fis;
try {
fis = new FileInputStream(xsd);
} catch (FileNotFoundException e) {
throw new Exception("Error accessing XSD.", e);
}
XSDHandler dtfXSD = new XSDHandler(fis);
while (iter.hasNext()) {
String pname = (String) iter.next();
ArrayList tags = (ArrayList) packages.get(pname);
info("Package " + pname);
for (int i = 0; i < tags.size(); i++) {
ClassDoc classdoc = (ClassDoc) tags.get(i);
String tagname = classdoc.name().toLowerCase();
PrintStream ps = createFile(tagdir + File.separatorChar + tagname + ".html");
info("Tag " + tagname);
ps.println("<html>");
ps.println(" <head>");
ps.println(" <link rel='stylesheet' " + "href='../main.css' " + "type='text/css'>");
ps.println(" <title>" + classdoc.name() + "</title>");
ps.println(" </head>");
ps.println(" <body id='body'>");
ps.println("<div id='nav'>");
ps.println("<a href='../index.html'>Home</a></div>");
// Hiding the class name in the tooltip of the title :)
ps.println("<div id='tag_title' title='" + classdoc.qualifiedName() + "'>" + classdoc.name() + "</div>");
/*
* Description
*/
ps.println("<div id='tag_description'>");
Tag[] descriptions = classdoc.tags(DTF_TAG_DESC);
if (descriptions.length != 0) {
for (int d = 0; d < descriptions.length; d++) {
ps.print(treatTag(descriptions[d], tnames, fnames));
}
}
ps.println("</div>");
/*
* Child tags
*/
String children = dtfXSD.generateChildrenString(tagname);
if (children != null && children.trim().length() > 0) {
Pattern pattern = Pattern.compile("([a-zA-Z_]*)");
Matcher matcher = pattern.matcher(children);
StringBuffer result = new StringBuffer();
int laststart = 0;
while (matcher.find()) {
String match = matcher.group();
int start = matcher.start();
int end = matcher.end();
match = match.toLowerCase();
if (match.trim().length() > 0) {
result.append(children.substring(laststart, start));
result.append("<a href='" + match + ".html'>" + match + "</a>");
laststart = end;
}
}
result.append(children.substring(laststart));
ps.print("<div class='tag_children_label'>Children Tags</div>");
ps.print("<div class='tag_children'>");
ps.print(result.toString());
ps.print("</div>");
}
/*
* Events
*/
Tag[] events = classdoc.tags(DTF_EVENT);
Tag[] eventsAttrs = classdoc.tags(DTF_EVENT_ATTR);
Tag[] eventsDesc = classdoc.tags(DTF_EVENT_ATTR_DESC);
if (eventsAttrs.length != eventsDesc.length) {
// XXX: throw an exception
}
if (eventsAttrs.length != 0) {
HashMap<String, HashMap<String, String>> eventMap = new HashMap<String, HashMap<String, String>>();
/*
* Construct all the relations between events and their
* attributes.
*/
for (int a = 0; a < events.length; a++) {
String[] eventNames = events[a].text().trim().split(" ");
for (int e = 0; e < eventNames.length; e++) {
if (!eventMap.containsKey(eventNames[e])) {
eventMap.put(eventNames[e], new HashMap<String, String>());
}
String attrName = eventsAttrs[a].text();
String attrDesc = treatTag(eventsDesc[a], tnames, fnames);
((HashMap) eventMap.get(eventNames[e])).put(attrName, attrDesc);
}
}
ps.print("<div class='tag_events_label'>Events</div>");
Iterator<Entry<String, HashMap<String, String>>> eventIter = eventMap.entrySet().iterator();
ps.print("<div class='tag_events'>");
while (eventIter.hasNext()) {
Entry<String, HashMap<String, String>> entry = eventIter.next();
HashMap<String, String> attribs = entry.getValue();
ps.print("<div class='tag_event'>");
ps.print("<div class='tag_event_name'>" + entry.getKey() + " Event</div>");
Iterator<Entry<String, String>> attribIter = attribs.entrySet().iterator();
while (attribIter.hasNext()) {
Entry<String, String> attrib = attribIter.next();
ps.print("<div class='tag_event_attribute'>");
ps.print("<div class='tag_event_attribute_name'>" + attrib.getKey() + "</div>");
ps.print("<div class='tag_event_attribute_value'>" + attrib.getValue() + "</div>");
ps.print("</div>");
}
ps.print("</div>");
}
ps.print("</div>");
}
/*
* Attributes
*/
HashMap attrs = new HashMap();
ClassDoc aux = classdoc;
while (aux != null) {
FieldDoc[] fieldDocs = aux.fields();
for (int f = 0; f < fieldDocs.length; f++) {
attrs.put(fieldDocs[f].name(), fieldDocs[f]);
}
aux = aux.superclass();
}
ArrayList<String> attributes = dtfXSD.getAttributes(tagname);
ArrayList<String> required = dtfXSD.getRequiredAttributes(tagname);
ArrayList<String> optional = dtfXSD.getOptionalAttributes(tagname);
if (attributes != null) {
boolean someopt = false;
StringBuffer opt = new StringBuffer();
boolean somereq = false;
StringBuffer req = new StringBuffer();
opt.append("<div id='optional_attributes_label'>Optional Attributes</div>");
opt.append("<div id='optional_attributes'>");
req.append("<div id='required_attributes_label'>Required Attributes</div>");
req.append("<div id='required_attributes'>");
Iterator<String> keys = attributes.iterator();
while (keys.hasNext()) {
String aName = keys.next();
StringBuffer which = null;
if (required.contains(aName)) {
which = req;
somereq = true;
} else if (optional.contains(aName)) {
which = opt;
someopt = true;
}
if (which != null) {
which.append("<div class='attribute'>");
which.append("<div class='attribute_name'>" + aName + "</div>");
FieldDoc doc = (FieldDoc) attrs.get(aName);
if (doc != null) {
Tag[] descs = doc.tags(DTF_ATTR_DESC);
if (descs.length != 0) {
which.append("<div class='attribute_desc'>" + treatTag(descs[0], tnames, fnames) + "</div>");
}
}
which.append("</div>");
}
}
if (somereq) {
ps.print(req + "</div>");
}
if (someopt) {
ps.print(opt + "</div>");
}
}
/*
* Examples
*/
Tag[] examples = classdoc.tags(DTF_TAG_EXAMPLE);
if (examples.length != 0) {
ps.print("<div class='tag_examples_label'>Usage Examples</div>");
ps.print("<div class='tag_examples'>");
for (int e = 0; e < examples.length; e++) {
Tag example = examples[e];
try {
String text = example.text().trim();
if (text.length() != 0) {
ps.print("<div class='tag_example_container'>");
ps.print("<div class='tag_example_title'>Example #" + (e + 1) + "</div>");
ps.print("<div class='tag_example'>" + treatXML(text) + "</div>");
ps.print("</div>");
}
} catch (Exception exc) {
throw new Exception("Error handling example #" + (e + 1) + " of tag " + tagname, exc);
}
}
ps.print("</div>");
}
ps.print("</body></html>");
ps.close();
}
}
/*
* 2nd phase for Features
*
*/
iter = fgroupnames.iterator();
while (iter.hasNext()) {
String pname = (String) iter.next();
ArrayList<DTFDoc> tags = fgroups.get(pname);
info(pname);
for (int i = 0; i < tags.size(); i++) {
DTFDoc dtfdoc = tags.get(i);
PrintStream ps = createFile(featuredir + File.separatorChar + dtfdoc.name.toLowerCase() + ".html");
info("Feature [" + dtfdoc.name + "]");
ps.println("<html>");
ps.println(" <head>");
ps.println(" <link rel='stylesheet' " + "href='../main.css' " + "type='text/css'>");
ps.println(" <title>" + dtfdoc.name + "</title>");
ps.println(" </head>");
ps.println(" <body id='body'>");
ps.println("<div id='nav'>");
ps.println("<a href='../index.html'>Home</a></div>");
// Hiding the class name in the tooltip of the title :)
ps.println("<div class='feature_title' title='" + dtfdoc.qname + "'>" + dtfdoc.name + "</div>");
/*
* Description
*/
ps.print("<div class='feature_description'>");
Tag[] descriptions = dtfdoc.descriptions;
if (descriptions.length != 0) {
for (int d = 0; d < descriptions.length; d++) {
ps.print(treatTag(descriptions[d], tnames, fnames));
}
}
ps.print("</div>");
/*
* Examples
*/
Tag[] examples = dtfdoc.examples;
if (examples.length != 0) {
ps.print("<div class='feature_examples_label'>Usage Examples</div>");
ps.print("<div class='feature_examples'>");
for (int e = 0; e < examples.length; e++) {
Tag example = examples[e];
try {
String text = example.text().trim();
if (text.length() != 0) {
ps.print("<div class='feature_example_container'>");
ps.print("<div class='feature_example_title'>Example #" + (e + 1) + "</div>");
ps.print("<div class='feature_example'>" + treatXML(text) + "</div>");
ps.print("</div>");
}
} catch (Exception exc) {
throw new Exception("Error handling example #" + (e + 1) + " of tag " + dtfdoc.name, exc);
}
}
ps.print("</div>");
}
ps.print("</body></html>");
ps.close();
}
}
psIndex.print("</td></tr></table>");
psIndex.print("</body></html>");
psIndex.close();
return true;
}
Example 70
Project: gradle-ikvm-plugin-master File: IKVMDocLet.java View source code |
/** * Prints the member documentation. * * @param pw the writer to print the documentation to * @param programElementDoc the member to document */ private static void print(PrintWriter pw, ProgramElementDoc programElementDoc) { /* * Implementation of proposed @exclude tag: http://java.sun.com/j2se/javadoc/proposed-tags.html */ if (programElementDoc.tags("@exclude").length > 0) { return; } printIndent(pw, 2); pw.print("<member name=\""); printReference(pw, programElementDoc, true); pw.println("\">"); printIndent(pw, 3); pw.print("<summary>"); if (OUTPUT_DEPRECATED) { printTags(pw, programElementDoc, "DEPRECATED:", "@deprecated"); } printComment(pw, programElementDoc, programElementDoc.inlineTags()); if (OUTPUT_AUTHOR) { printTags(pw, programElementDoc, "Author:", "@author"); } if (OUTPUT_VERSION) { printTags(pw, programElementDoc, "Version:", "@version"); } if (OUTPUT_SINCE) { printTags(pw, programElementDoc, "Since:", "@since"); } printTags(pw, programElementDoc, "Serial:", "@serial"); printTags(pw, programElementDoc, "Serial Field:", "@serialField"); printTags(pw, programElementDoc, "Serial Data:", "@serialData"); pw.println("</summary>"); if (programElementDoc instanceof ExecutableMemberDoc) { ExecutableMemberDoc executableMemberDoc = (ExecutableMemberDoc) programElementDoc; printParamTags(pw, executableMemberDoc); printReturnTag(pw, executableMemberDoc); printThrowsTags(pw, executableMemberDoc); } printSeeTags(pw, programElementDoc); printIndent(pw, 2); pw.println("</member>"); // Document class members if (programElementDoc instanceof ClassDoc) { ClassDoc classDoc = (ClassDoc) programElementDoc; FieldDoc[] fields = classDoc.fields(); for (FieldDoc fieldDoc : fields) { print(pw, fieldDoc); } ConstructorDoc[] constructors = classDoc.constructors(); for (ConstructorDoc constructorDoc : constructors) { print(pw, constructorDoc); } MethodDoc[] methods = classDoc.methods(); for (MethodDoc methodDoc : methods) { print(pw, methodDoc); } } }
Example 71
Project: sx10-master File: X10ClassDoc.java View source code |
public MemberDoc getMemberDoc(String name) {
for (X10FieldDoc doc : fields.values()) {
if (doc.name().equals(name))
return doc;
}
String shortname = name;
String signature = "()";
int index = name.indexOf("(");
if (index != -1) {
shortname = name.substring(0, name.indexOf("("));
signature = name.substring(index);
signature = makeQualifiedParams(signature);
}
index = shortname.indexOf("[");
if (index != -1) {
shortname = shortname.substring(0, index);
}
for (X10ConstructorDoc doc : constructors.values()) {
if (doc.name().equals(shortname) && doc.signature().equals(signature)) {
return doc;
}
}
for (MethodDoc doc : methods.values()) {
String n = doc.name();
String s = doc.signature();
if (doc.name().equals(shortname) && doc.signature().equals(signature)) {
return doc;
}
}
return null;
}
Example 72
Project: easytest-codegen-master File: TestingStrategy.java View source code |
/**
*
* Checks if method that is encapsulated in method doc is testable
* It mainly checks if method is not abstract, protected, private, annotated, enum const
* It is a public method
*
* @param doc the class doc
* @param naming naming strategy object, used to find out test class name
*/
public boolean isTestableMethod(MethodDoc doc) {
boolean returnValue;
returnValue = (doc != null);
returnValue = returnValue && !doc.isAbstract();
returnValue = returnValue && !doc.isProtected();
returnValue = returnValue && !doc.isPrivate();
returnValue = returnValue && !doc.isAnnotationTypeElement();
returnValue = returnValue && !doc.isEnumConstant();
returnValue = returnValue && doc.isPublic();
return returnValue;
}
Example 73
Project: texdoclet-master File: TeXDoclet.java View source code |
/** * Enumerates the members of a section of the document and formats them * using Tex statements. */ static void printMember(ExecutableMemberDoc mem, ExecutableMemberDoc copiedTo) { PackageDoc pac = copiedTo == null ? mem.containingPackage() : copiedTo.containingPackage(); if (mem instanceof MethodDoc) { MethodDoc method = (MethodDoc) mem; if (method.commentText() == "" && method.seeTags().length == 0 && method.throwsTags().length == 0 && method.paramTags().length == 0) { // No javadoc available for this method. Recurse through // superclasses // and implemented interfaces to find javadoc of overridden // methods. boolean found = false; ClassDoc doc = method.overriddenClass(); if (doc != null) { for (int i = 0; !found && i < doc.methods().length; ++i) { if (doc.methods()[i].name().equals(mem.name()) && doc.methods()[i].signature().equals(mem.signature())) { printMember(doc.methods()[i], copiedTo == null ? mem : copiedTo); found = true; } } } doc = method.containingClass(); for (int j = 0; !found && j < doc.interfaces().length; j++) { ClassDoc inf = doc.interfaces()[j]; for (int i = 0; !found && i < inf.methods().length; ++i) { if (inf.methods()[i].name().equals(mem.name()) && inf.methods()[i].signature().equals(mem.signature())) { printMember(inf.methods()[i], copiedTo == null ? mem : copiedTo); found = true; } } } if (found) { return; } } } ParamTag[] params = mem.paramTags(); // Some index and hyperref stuff // os.println("\\item{\\vskip -1.9ex " ); os.println("\\item{ "); os.println("\\index{" + HTMLtoLaTeXBackEnd.fixText(mem.name() + mem.flatSignature()) + "}"); if (hyperref) { if (copiedTo == null) { os.print("\\hypertarget{" + refName(makeRefKey(mem.qualifiedName() + mem.signature())) + "}{"); } else { os.print("\\hypertarget{" + refName(makeRefKey(copiedTo.qualifiedName() + copiedTo.signature())) + "}{"); } } os.print(BOLD + " " + HTMLtoLaTeXBackEnd.fixText(mem.name()) + "}\\\\"); if (hyperref) { os.print("}"); } os.println(); // Print signature os.println("\\begin{lstlisting}[frame=" + methodDeclarationFrame + "]"); if (!mem.containingClass().isInterface()) { os.print(mem.modifiers() + " "); } if (mem instanceof MethodDoc) { os.print(packageRelativIdentifier(pac, ((MethodDoc) mem).returnType().toString()) + " "); } os.print(mem.name() + "("); Parameter[] parms = mem.parameters(); int p = 0; String qparmstr = ""; String parmstr = ""; for (; p < parms.length; ++p) { if (p > 0) { os.print(","); } Type t = parms[p].type(); os.print(packageRelativIdentifier(pac, t.qualifiedTypeName())); os.print(t.dimension()); if (parms[p].name().equals("") == false) { os.print(" " + parms[p].name()); } if (qparmstr.length() != 0) { qparmstr += ","; } qparmstr += t.qualifiedTypeName() + t.dimension(); if (parmstr.length() != 0) { parmstr += ","; } parmstr += t.typeName() + t.dimension(); } os.print(")"); // Thrown exceptions ClassDoc[] thrownExceptions = mem.thrownExceptions(); if (thrownExceptions != null && thrownExceptions.length > 0) { os.print(" throws " + thrownExceptions[0].qualifiedName()); for (int e = 1; e < thrownExceptions.length; e++) { os.print(", " + thrownExceptions[e].qualifiedName()); } } os.println("\\end{lstlisting} %end signature"); boolean yet = false; // Description if (mem.inlineTags().length > 0) { if (!yet) { os.println("\\begin{itemize}"); yet = true; } os.println("\\item{"); if (copiedTo == null) { os.println(BOLD + " Description}\n"); } else { os.print(BOLD + " Description copied from "); String classname = mem.containingClass().qualifiedName(); if (hyperref) { os.print("\\hyperlink{" + refName(makeRefKey(classname)) + "}{"); } os.print(packageRelativIdentifier(pac, classname)); if (hyperref) { os.print("}"); } os.print("{\\small "); os.print("\\refdefined{" + refName(makeRefKey(classname)) + "}"); os.println("} }\n"); } printTags(mem.containingPackage(), mem.inlineTags()); os.println("\n}"); } // Parameter tags if (params.length > 0) { if (!yet) { os.println("\\begin{itemize}"); yet = true; } os.println("\\item{"); os.println(BOLD + " Parameters}"); os.println(" \\begin{itemize}"); for (int j = 0; j < params.length; ++j) { os.println(" \\item{"); os.print(TRUETYPE + HTMLtoLaTeXBackEnd.fixText(params[j].parameterName()) + "}" + " -- "); printTags(mem.containingPackage(), params[j].inlineTags()); os.println("}"); } os.println(" \\end{itemize}"); os.println("}%end item"); } // Return tag if (mem instanceof MethodDoc) { Tag[] ret = mem.tags("return"); if (ret.length > 0) { if (!yet) { os.println("\\begin{itemize}"); yet = true; } os.println("\\item{" + BOLD + " Returns} -- "); for (int j = 0; j < ret.length; ++j) { printTags(mem.containingPackage(), ret[j].inlineTags()); os.println(" "); } os.println("}%end item"); } } // Throws or Exceptions tag if (mem instanceof ExecutableMemberDoc) { ThrowsTag[] excp = (mem).throwsTags(); if (excp.length > 0) { if (!yet) { os.println("\\begin{itemize}"); yet = true; } os.println("\\item{" + BOLD + " Throws}"); os.println(" \\begin{itemize}"); for (int j = 0; j < excp.length; ++j) { String ename = excp[j].exceptionName(); ClassDoc cdoc = excp[j].exception(); if (cdoc != null) { ename = cdoc.qualifiedName(); } os.print(" \\item{\\vskip -.6ex " + TRUETYPE + HTMLtoLaTeXBackEnd.fixText(ename) + "} -- "); printTags(mem.containingPackage(), excp[j].inlineTags()); os.println("}"); } os.println(" \\end{itemize}"); os.println("}%end item"); } } // See tags SeeTag[] sees = mem.seeTags(); if (sees.length > 0) { if (!yet) { os.println("\\begin{itemize}"); yet = true; } os.println("\\item{" + BOLD + " See also}"); os.println(" \\begin{itemize}"); for (int j = 0; j < sees.length; ++j) { os.print("\\item{ "); printSeesTag(sees[j], pac); os.println("}"); } os.println(" \\end{itemize}"); os.println("}%end item"); } if (yet) { os.println("\\end{itemize}"); } os.println("}%end item"); }