/** * {@inheritDoc} */ protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { MethodDoc property = (MethodDoc)member; addModifierAndType(property, property.returnType(), tdSummaryType); }
private Type getType(MemberDoc member) { if (member instanceof FieldDoc) { return ((FieldDoc) member).type(); } else { return ((MethodDoc) member).returnType(); } } }
private Type getType(MemberDoc member) { if (member instanceof FieldDoc) { return ((FieldDoc) member).type(); } else { return ((MethodDoc) member).returnType(); } } }
protected void printSummaryType( ProgramElementDoc member ) { MethodDoc meth = (MethodDoc) member; printModifierAndType( meth, meth.returnType() ); }
/** * {@inheritDoc} */ protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { MethodDoc meth = (MethodDoc)member; addModifierAndType(meth, meth.returnType(), tdSummaryType); }
protected String typeString(MemberDoc member) { String type = ""; if (member instanceof MethodDoc) { type = ((MethodDoc)member).returnType().toString(); } else if (member instanceof FieldDoc) { type = ((FieldDoc)member).type().toString(); } return type; }
private Type getType(MemberDoc member) { if (member instanceof FieldDoc) { return ((FieldDoc) member).type(); } else { return ((MethodDoc) member).returnType(); } } }
private boolean isPropertyMethod(MethodDoc method) { if (!method.name().endsWith("Property")) { return false; } if (! memberIsVisible(method)) { return false; } if (pattern.matcher(method.name()).matches()) { return false; } return 0 == method.parameters().length && !"void".equals(method.returnType().simpleTypeName()); }
protected void printReturnType( MethodDoc method ) { Type type = method.returnType(); if( type != null ) { writer.printLink( new LinkInfoImpl( LinkInfoImpl.CONTEXT_RETURN_TYPE, type ) ); print( ' ' ); } }
protected String typeString(MemberDoc member) { String type = ""; if (member instanceof MethodDoc) { type = ((MethodDoc)member).returnType().toString(); } else if (member instanceof FieldDoc) { type = ((FieldDoc)member).type().toString(); } return type; }
private MethodDoc setterForField(MethodDoc[] methods, MethodDoc propertyMethod) { final String propertyMethodName = propertyMethod.name(); final String fieldName = propertyMethodName.substring(0, propertyMethodName.lastIndexOf("Property")); final String fieldNameUppercased = "" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); final String setter = "set" + fieldNameUppercased; for (MethodDoc methodDoc : methods) { if (setter.equals(methodDoc.name())) { if (1 == methodDoc.parameters().length && "void".equals(methodDoc.returnType().simpleTypeName()) && (methodDoc.isPublic() || methodDoc.isProtected())) { return methodDoc; } } } return null; }
import com.sun.javadoc.ClassDoc; import com.sun.javadoc.Doclet; import com.sun.javadoc.MethodDoc; import com.sun.javadoc.RootDoc; import com.sun.tools.javadoc.Main; public class DocletTest { public static void main(String[] args) { Main.execute("", Analyzer.class.getName(), new String[] {"path/to/your/file.java"}); } public static class Analyzer extends Doclet { public static boolean start(RootDoc root) { for (ClassDoc classDoc : root.classes()) { System.out.println("Class: " + classDoc.qualifiedName()); for (MethodDoc methodDoc : classDoc.methods()) { System.out.println(" " + methodDoc.returnType() + " " + methodDoc.name() + methodDoc.signature()); } } return false; } } }
protected int getReturnTypeLength(ExecutableMemberDoc member) { if (member instanceof MethodDoc) { MethodDoc method = (MethodDoc)member; Type rettype = method.returnType(); if (rettype.isPrimitive()) { return rettype.typeName().length() + rettype.dimension().length(); } else { LinkInfoImpl linkInfo = new LinkInfoImpl( LinkInfoImpl.CONTEXT_MEMBER, rettype); writer.getLink(linkInfo); return linkInfo.displayLength; } } else { // it's a constructordoc return -1; } }
public static void returnDoc(ApiDoc apiDoc, ClassDoc classDoc, MethodDoc methodDoc) throws Exception { Method method = DocletUtil.getMethodByDoc(Class.forName(classDoc.qualifiedTypeName()), methodDoc); Type returnType = method.getGenericReturnType(); if (returnType.toString().equalsIgnoreCase("void")) { return; } ResultDoc resultDoc = new ResultDoc(); Tag[] tags = methodDoc.tags("return"); if (tags != null && tags.length == 1) { String[] returnTexts = tags[0].text().split("(e.g|eg|e.g.|example|exam|例如|如)(:|:)", 2); resultDoc.setDesc(returnTexts[0]); resultDoc.setExampleValue(returnTexts.length==2 ? returnTexts[1] : ""); resultDoc.setName(""); resultDoc.setType(methodDoc.returnType().typeName() + methodDoc.returnType().dimension()); } addRefType(classDoc, returnType, resultDoc); apiDoc.setResultDoc(resultDoc); }
/** * Add the return type. * * @param method the method being documented. * @param htmltree the content tree to which the return type will be added */ protected void addReturnType(MethodDoc method, Content htmltree) { Type type = method.returnType(); if (type != null) { Content linkContent = writer.getLink( new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type)); htmltree.addContent(linkContent); htmltree.addContent(writer.getSpace()); } }
/** * {@inheritDoc} */ public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) { Type returnType = ((MethodDoc) holder).returnType(); Tag[] tags = holder.tags(name); //Make sure we are not using @return tag on method with void return type. if (returnType.isPrimitive() && returnType.typeName().equals("void")) { if (tags.length > 0) { writer.getMsgRetriever().warning(holder.position(), "doclet.Return_tag_on_void_method"); } return null; } //Inherit @return tag if necessary. if (tags.length == 0) { DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) holder, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null; } }
/** * {@inheritDoc} */ public Content getTagletOutput(Doc holder, TagletWriter writer) { Type returnType = ((MethodDoc) holder).returnType(); Tag[] tags = holder.tags(name); //Make sure we are not using @return tag on method with void return type. if (returnType.isPrimitive() && returnType.typeName().equals("void")) { if (tags.length > 0) { writer.getMsgRetriever().warning(holder.position(), "doclet.Return_tag_on_void_method"); } return null; } //Inherit @return tag if necessary. if (tags.length == 0) { DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) holder, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null; } }
/** Print the class's operations m */ private boolean operations(Options opt, MethodDoc m[]) { boolean printed = false; for (MethodDoc md : m) { if (hidden(md)) continue; // Filter-out static initializer method if (md.name().equals("<clinit>") && md.isStatic() && md.isPackagePrivate()) continue; stereotype(opt, md, Align.LEFT); String op = visibility(opt, md) + md.name() + // (opt.showType ? "(" + parameter(opt, md.parameters()) + ")" + typeAnnotation(opt, md.returnType()) : "()"); tableLine(Align.LEFT, (md.isAbstract() ? Font.ABSTRACT : Font.NORMAL).wrap(opt, op)); printed = true; tagvalue(opt, md); } return printed; }
/** Print the class's operations m */ private boolean operations(Options opt, MethodDoc m[]) { boolean printed = false; for (MethodDoc md : m) { if (hidden(md)) continue; // Filter-out static initializer method if (md.name().equals("<clinit>") && md.isStatic() && md.isPackagePrivate()) continue; stereotype(opt, md, Align.LEFT); String op = visibility(opt, md) + md.name(); if (opt.showType) { op += "(" + parameter(opt, md.parameters()) + ")" + typeAnnotation(opt, md.returnType()); } else { op += "()"; } tableLine(Align.LEFT, op, opt, md.isAbstract() ? Font.ABSTRACT : Font.NORMAL); printed = true; tagvalue(opt, md); } return printed; }
/** * {@inheritDoc} */ public Content getSignature(MethodDoc property) { Content pre = new HtmlTree(HtmlTag.PRE); writer.addAnnotationInfo(property, pre); addModifiers(property, pre); Content propertylink = writer.getLink(new LinkInfoImpl( configuration, LinkInfoImpl.Kind.MEMBER, property.returnType())); pre.addContent(propertylink); pre.addContent(" "); if (configuration.linksource) { Content propertyName = new StringContent(property.name()); writer.addSrcLink(property, propertyName, pre); } else { addName(property.name(), pre); } return pre; }