Search in sources :

Example 31 with Tag

use of com.sun.javadoc.Tag in project jdk8u_jdk by JetBrains.

the class GenDocletBeanInfo method start.

/** @beaninfo
     * bound:true
     * constrained:false
     * expert:true
     * hidden:true
     * preferred:false
     * description: the description of this method can
     *              do all sorts of funky things. if it \n
     *              is indented like this, we have to remove
     *              all char spaces greater than 2 and also any hard-coded \n
     *              newline characters and all newlines
     * displayname: theString
     * propertyeditorclass: foo.bar.MyPropertyEditorClass
     * customizerclass: foo.bar.MyCustomizerClass
     * attribute:key1 value1
     * attribute: key2  value2
     *
     */
public static boolean start(RootDoc doc) {
    readOptions(doc.options());
    if (templateDir.length() == 0) {
        System.err.println("-t option not specified");
        return false;
    }
    if (fileDir.length() == 0) {
        System.err.println("-d option not specified");
        return false;
    }
    GenSwingBeanInfo generator = new GenSwingBeanInfo(fileDir, templateDir, DEBUG);
    Hashtable dochash = new Hashtable();
    DocBeanInfo dbi;
    /* "javadoc Foo.java Bar.java" will return:
        *         "Foo Foo.I1 Foo.I2 Bar Bar.I1 Bar.I2"
        * i.e., with all the innerclasses of classes specified in the command
        * line.  We don't want to generate BeanInfo for any of these inner
        * classes, so we ignore these by remembering what the last outer
        * class was.  A hack, I admit, but makes the build faster.
        */
    String previousClass = null;
    ClassDoc[] classes = doc.classes();
    for (int cnt = 0; cnt < classes.length; cnt++) {
        String className = classes[cnt].qualifiedName();
        if (previousClass != null && className.startsWith(previousClass) && className.charAt(previousClass.length()) == '.') {
            continue;
        }
        previousClass = className;
        // XXX - debug
        System.out.println("\n>>> Generating beaninfo for " + className + "...");
        // Examine the javadoc tags and look for the the @beaninfo tag
        // This first block looks at the javadoc for the class
        Tag[] tags = classes[cnt].tags();
        for (int i = 0; i < tags.length; i++) {
            if (tags[i].kind().equalsIgnoreCase("@beaninfo")) {
                if (DEBUG)
                    System.out.println("GenDocletBeanInfo: found @beaninfo tagged Class: " + tags[i].text());
                dbi = genDocletInfo(tags[i].text(), classes[cnt].name());
                dochash.put(dbi.name, dbi);
                break;
            }
        }
        // This block looks at the javadoc for the class methods.
        int startPos = -1;
        MethodDoc[] methods = classes[cnt].methods();
        for (int j = 0; j < methods.length; j++) {
            // actually don't "introspect" - look for all
            // methods with a @beaninfo tag
            tags = methods[j].tags();
            for (int x = 0; x < tags.length; x++) {
                if (tags[x].kind().equalsIgnoreCase("@beaninfo")) {
                    if ((methods[j].name().startsWith("get")) || (methods[j].name().startsWith("set")))
                        startPos = 3;
                    else if (methods[j].name().startsWith("is"))
                        startPos = 2;
                    else
                        startPos = 0;
                    String propDesc = Introspector.decapitalize((methods[j].name()).substring(startPos));
                    if (DEBUG)
                        System.out.println("GenDocletBeanInfo: found @beaninfo tagged Method: " + tags[x].text());
                    dbi = genDocletInfo(tags[x].text(), propDesc);
                    dochash.put(dbi.name, dbi);
                    break;
                }
            }
        }
        if (DEBUG) {
            // dump our classes doc beaninfo
            System.out.println(">>>>DocletBeanInfo for class: " + classes[cnt].name());
            Enumeration e = dochash.elements();
            while (e.hasMoreElements()) {
                DocBeanInfo db = (DocBeanInfo) e.nextElement();
                System.out.println(db.toString());
            }
        }
        // Use the generator to create the beaninfo code for the class.
        generator.genBeanInfo(classes[cnt].containingPackage().name(), classes[cnt].name(), dochash);
        // reset the values!
        dochash.clear();
    }
    // end for loop
    return true;
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) MethodDoc(com.sun.javadoc.MethodDoc) Tag(com.sun.javadoc.Tag) ClassDoc(com.sun.javadoc.ClassDoc)

Example 32 with Tag

use of com.sun.javadoc.Tag in project com.revolsys.open by revolsys.

the class RestDoclet method responseStatus.

private void responseStatus(final MethodDoc method) {
    final Map<String, List<String>> responseStatusDescriptions = new TreeMap<>();
    for (final Tag tag : method.tags()) {
        if (tag.name().equals("@web.response.status")) {
            final String text = DocletUtil.description(method.containingClass(), tag);
            final int index = text.indexOf(" ");
            if (index != -1) {
                final String status = text.substring(0, index);
                final String description = text.substring(index + 1).trim();
                addResponseStatusDescription(responseStatusDescriptions, status, description);
            }
        }
    }
    addResponseStatusDescription(responseStatusDescriptions, "500", "<p><b>Internal Server Error</b></p>" + "<p>This error indicates that there was an unexpected error on the server. " + "This is sometimes temporary so try again after a few minutes. " + "The problem could also be caused by bad input data so verify all input parameters and files. " + "If the problem persists contact the support desk with exact details of the parameters you were using.</p>");
    if (!responseStatusDescriptions.isEmpty()) {
        DocletUtil.panelStart(this.writer, "panel-info", HtmlElem.H4, null, null, "HTTP Status Codes", null);
        this.writer.element(HtmlElem.P, "The resource will return one of the following status codes. The HTML error page may include an error message. The descriptions of the messages and the cause are described below.");
        this.writer.startTag(HtmlElem.DIV);
        this.writer.attribute(HtmlAttr.CLASS, "table-responsive");
        this.writer.startTag(HtmlElem.TABLE);
        this.writer.attribute(HtmlAttr.CLASS, "table table-striped table-bordered table-condensed");
        this.writer.startTag(HtmlElem.THEAD);
        this.writer.startTag(HtmlElem.TR);
        this.writer.element(HtmlElem.TH, "HTTP Status Code");
        this.writer.element(HtmlElem.TH, "Description");
        this.writer.endTag(HtmlElem.TR);
        this.writer.endTag(HtmlElem.THEAD);
        this.writer.startTag(HtmlElem.TBODY);
        for (final Entry<String, List<String>> entry : responseStatusDescriptions.entrySet()) {
            final String code = entry.getKey();
            for (final String message : entry.getValue()) {
                this.writer.startTag(HtmlElem.TR);
                this.writer.element(HtmlElem.TD, code);
                this.writer.startTag(HtmlElem.TD);
                this.writer.write(message);
                this.writer.endTag(HtmlElem.TD);
                this.writer.endTag(HtmlElem.TR);
            }
        }
        this.writer.endTag(HtmlElem.TBODY);
        this.writer.endTag(HtmlElem.TABLE);
        this.writer.endTag(HtmlElem.DIV);
        DocletUtil.panelEnd(this.writer);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.sun.javadoc.Tag) TreeMap(java.util.TreeMap)

Example 33 with Tag

use of com.sun.javadoc.Tag in project com.revolsys.open by revolsys.

the class DocletUtil method description.

public static String description(final ClassDoc containingClass, final Tag[] tags) {
    final StringBuilder text = new StringBuilder();
    if (tags != null && tags.length > 0) {
        for (final Tag tag : tags) {
            final String kind = tag.kind();
            if (tag instanceof SeeTag) {
                final SeeTag seeTag = (SeeTag) tag;
                seeTag(text, containingClass, seeTag);
            } else if ("Text".equals(kind)) {
                text.append(tag.text());
            }
        }
    }
    return text.toString();
}
Also used : SeeTag(com.sun.javadoc.SeeTag) Tag(com.sun.javadoc.Tag) ParamTag(com.sun.javadoc.ParamTag) SeeTag(com.sun.javadoc.SeeTag)

Example 34 with Tag

use of com.sun.javadoc.Tag in project com.revolsys.open by revolsys.

the class DocletUtil method documentationReturn.

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);
    }
}
Also used : Type(com.sun.javadoc.Type) ParameterizedType(com.sun.javadoc.ParameterizedType) WildcardType(com.sun.javadoc.WildcardType) Tag(com.sun.javadoc.Tag) ParamTag(com.sun.javadoc.ParamTag) SeeTag(com.sun.javadoc.SeeTag)

Example 35 with Tag

use of com.sun.javadoc.Tag in project h2database by h2database.

the class Doclet method writeMethodDetails.

private void writeMethodDetails(PrintWriter writer, ClassDoc clazz, ExecutableMemberDoc method, String signature) {
    String name = method.name();
    if (skipMethod(method)) {
        return;
    }
    Parameter[] params = method.parameters();
    StatementBuilder buff = new StatementBuilder();
    buff.append('(');
    int i = 0;
    for (Parameter p : params) {
        boolean isVarArgs = method.isVarArgs() && i++ == params.length - 1;
        buff.appendExceptFirst(", ");
        buff.append(getTypeName(false, isVarArgs, p.type()));
        buff.append(' ');
        buff.append(p.name());
    }
    buff.append(')');
    ClassDoc[] exceptions = method.thrownExceptions();
    if (exceptions.length > 0) {
        buff.append(" throws ");
        buff.resetCount();
        for (ClassDoc ex : exceptions) {
            buff.appendExceptFirst(", ");
            buff.append(ex.typeName());
        }
    }
    if (isDeprecated(method)) {
        name = "<span class=\"deprecated\">" + name + "</span>";
    }
    writer.println("<a id=\"" + signature + "\" href=\"#" + signature + "\">" + name + "</a>" + buff.toString());
    boolean hasComment = method.commentText() != null && method.commentText().trim().length() != 0;
    writer.println("<div class=\"methodText\">" + formatText(method.commentText()) + "</div>");
    ParamTag[] paramTags = method.paramTags();
    ThrowsTag[] throwsTags = method.throwsTags();
    boolean hasThrowsTag = throwsTags != null && throwsTags.length > 0;
    if (paramTags.length != params.length) {
        if (hasComment && !method.commentText().startsWith("[")) {
            // [Not supported] and such are not problematic
            addError("Undocumented parameter(s) (" + getLink(clazz, method.position().line()) + ") " + name + " documented: " + paramTags.length + " params: " + params.length);
        }
    }
    for (int j = 0; j < paramTags.length; j++) {
        String paramName = paramTags[j].parameterName();
        String comment = paramTags[j].parameterComment();
        if (comment.trim().length() == 0) {
            addError("Undocumented parameter (" + getLink(clazz, method.position().line()) + ") " + name + " " + paramName);
        }
        String p = paramName + " - " + comment;
        if (j == 0) {
            writer.println("<div class=\"itemTitle\">Parameters:</div>");
        }
        writer.println("<div class=\"item\">" + p + "</div>");
    }
    Tag[] returnTags = method.tags("return");
    Type returnType = getReturnType(method);
    if (returnTags != null && returnTags.length > 0) {
        writer.println("<div class=\"itemTitle\">Returns:</div>");
        String returnComment = returnTags[0].text();
        if (returnComment.trim().length() == 0) {
            addError("Undocumented return value (" + getLink(clazz, method.position().line()) + ") " + name);
        }
        writer.println("<div class=\"item\">" + returnComment + "</div>");
    } else if (returnType != null && !returnType.toString().equals("void")) {
        if (hasComment && !method.commentText().startsWith("[") && !hasThrowsTag) {
            // [Not supported] and such are not problematic
            // also not problematic are methods that always throw an
            // exception
            addError("Undocumented return value (" + getLink(clazz, method.position().line()) + ") " + name + " " + getReturnType(method));
        }
    }
    if (hasThrowsTag) {
        writer.println("<div class=\"itemTitle\">Throws:</div>");
        for (ThrowsTag tag : throwsTags) {
            String p = tag.exceptionName();
            String c = tag.exceptionComment();
            if (c.length() > 0) {
                p += " - " + c;
            }
            writer.println("<div class=\"item\">" + p + "</div>");
        }
    }
}
Also used : ParamTag(com.sun.javadoc.ParamTag) ThrowsTag(com.sun.javadoc.ThrowsTag) Type(com.sun.javadoc.Type) StatementBuilder(org.h2.util.StatementBuilder) Parameter(com.sun.javadoc.Parameter) Tag(com.sun.javadoc.Tag) ParamTag(com.sun.javadoc.ParamTag) ThrowsTag(com.sun.javadoc.ThrowsTag) ClassDoc(com.sun.javadoc.ClassDoc)

Aggregations

Tag (com.sun.javadoc.Tag)40 ParamTag (com.sun.javadoc.ParamTag)14 SeeTag (com.sun.javadoc.SeeTag)12 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Matcher (java.util.regex.Matcher)4 Test (org.junit.Test)4 ClassDoc (com.sun.javadoc.ClassDoc)3 MethodDoc (com.sun.javadoc.MethodDoc)3 TagletOutputImpl (com.sun.tools.doclets.formats.html.TagletOutputImpl)3 HashMap (java.util.HashMap)3 Parameter (com.sun.javadoc.Parameter)2 ThrowsTag (com.sun.javadoc.ThrowsTag)2 Type (com.sun.javadoc.Type)2 TagletWriterImpl (com.sun.tools.doclets.formats.html.TagletWriterImpl)2 RepresentationDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)2 JSONObject (org.json.JSONObject)2 JavadocInlineTagHandler (com.eden.orchid.javadoc.api.JavadocInlineTagHandler)1 ApiField (com.emc.apidocs.model.ApiField)1 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)1