Search in sources :

Example 1 with ExecutableMemberDoc

use of com.sun.javadoc.ExecutableMemberDoc in project beakerx by twosigma.

the class BeakerxDoclet method getInspects.

private static List<MethodInspect> getInspects(ExecutableMemberDoc[] memberDocs) {
    List<MethodInspect> methodInspects = new ArrayList<>(memberDocs.length);
    for (ExecutableMemberDoc memberDoc : memberDocs) {
        List<String> signature = new ArrayList<>();
        for (Parameter parameter : memberDoc.parameters()) {
            signature.add(parameter.type().qualifiedTypeName() + " " + parameter.name());
        }
        MethodInspect methodInspect = new MethodInspect(memberDoc.name(), memberDoc.getRawCommentText(), String.join(", ", signature));
        methodInspects.add(methodInspect);
    }
    return methodInspects;
}
Also used : ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) ArrayList(java.util.ArrayList) Parameter(com.sun.javadoc.Parameter)

Example 2 with ExecutableMemberDoc

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

the class DocletUtil method seeTag.

public static void seeTag(final StringBuilder text, final ClassDoc containingClass, final SeeTag seeTag) {
    final String name = seeTag.name();
    if (name.startsWith("@link") || name.equals("@see")) {
        final boolean code = !name.equalsIgnoreCase("@linkplain");
        String label = seeTag.label();
        final StringBuffer stringbuffer = new StringBuffer();
        final String seeTagText = replaceDocRootDir(seeTag.text());
        if (seeTagText.startsWith("<") || seeTagText.startsWith("\"")) {
            stringbuffer.append(seeTagText);
            text.append(seeTagText);
        } else {
            final ClassDoc referencedClass = seeTag.referencedClass();
            final MemberDoc referencedMember = seeTag.referencedMember();
            String referencedMemberName = seeTag.referencedMemberName();
            if (referencedClass == null) {
                final PackageDoc packagedoc = seeTag.referencedPackage();
                if (packagedoc != null && packagedoc.isIncluded()) {
                    final String packageName = packagedoc.name();
                    if (!StringUtils.hasText(label)) {
                        label = packageName;
                    }
                    link(text, "#" + packageName, label, code);
                } else {
                // TODO link to external package or class
                // String s9 = getCrossPackageLink(referencedClassName);
                // String s8;
                // if (s9 != null)
                // stringbuffer.append(getHyperLink(s9, "", s1.length() != 0 ? s1
                // : s3, false));
                // else if ((s8 = getCrossClassLink(referencedClassName,
                // referencedMemberName, s1, false, "", !plainLink)) != null) {
                // stringbuffer.append(s8);
                // } else {
                // configuration.getDocletSpecificMsg().warning(seeTag.position(),
                // "doclet.see.class_or_package_not_found", name, s2);
                // stringbuffer.append(s1.length() != 0 ? s1 : s3);
                // }
                }
            } else {
                String url = null;
                final String className = referencedClass.qualifiedName();
                if (referencedClass.isIncluded()) {
                    url = "#" + className;
                } else {
                    url = getExternalUrl(className);
                    if (!StringUtils.hasText(url)) {
                        label = className;
                    }
                }
                if (referencedMember != null) {
                    if (referencedMember instanceof ExecutableMemberDoc) {
                        if (referencedMemberName.indexOf('(') < 0) {
                            final ExecutableMemberDoc executableDoc = (ExecutableMemberDoc) referencedMember;
                            referencedMemberName = referencedMemberName + executableDoc.signature();
                        }
                        if (StringUtils.hasText(referencedMemberName)) {
                            label = referencedMemberName;
                        } else {
                            label = seeTagText;
                        }
                    }
                    if (referencedClass.isIncluded()) {
                        url += "." + referencedMemberName;
                    } else if (StringUtils.hasText(url)) {
                        url += "#" + referencedMemberName;
                    } else {
                        label = referencedMember.toString();
                    }
                }
                if (!StringUtils.hasText(label)) {
                    label = referencedClass.name();
                }
                link(text, url, label, code);
            }
        }
    }
}
Also used : PackageDoc(com.sun.javadoc.PackageDoc) ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) MemberDoc(com.sun.javadoc.MemberDoc) ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Example 3 with ExecutableMemberDoc

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

the class DocletUtil method seeTag.

public static void seeTag(final XmlWriter writer, final ClassDoc containingClass, final SeeTag seeTag) {
    final String name = seeTag.name();
    if (name.startsWith("@link") || name.equals("@see")) {
        final boolean code = !name.equalsIgnoreCase("@linkplain");
        String label = seeTag.label();
        final StringBuffer stringbuffer = new StringBuffer();
        final String seeTagText = replaceDocRootDir(seeTag.text());
        if (seeTagText.startsWith("<") || seeTagText.startsWith("\"")) {
            stringbuffer.append(seeTagText);
            writer.write(seeTagText);
        } else {
            final ClassDoc referencedClass = seeTag.referencedClass();
            final MemberDoc referencedMember = seeTag.referencedMember();
            String referencedMemberName = seeTag.referencedMemberName();
            if (referencedClass == null) {
                final PackageDoc packagedoc = seeTag.referencedPackage();
                if (packagedoc != null && packagedoc.isIncluded()) {
                    final String packageName = packagedoc.name();
                    if (!StringUtils.hasText(label)) {
                        label = packageName;
                    }
                    link(writer, "#" + packageName, label, code);
                } else {
                // TODO link to external package or class
                // String s9 = getCrossPackageLink(referencedClassName);
                // String s8;
                // if (s9 != null)
                // stringbuffer.append(getHyperLink(s9, "", s1.length() != 0 ? s1
                // : s3, false));
                // else if ((s8 = getCrossClassLink(referencedClassName,
                // referencedMemberName, s1, false, "", !plainLink)) != null) {
                // stringbuffer.append(s8);
                // } else {
                // configuration.getDocletSpecificMsg().warning(seeTag.position(),
                // "doclet.see.class_or_package_not_found", name, s2);
                // stringbuffer.append(s1.length() != 0 ? s1 : s3);
                // }
                }
            } else {
                String url = null;
                final String className = referencedClass.qualifiedName();
                if (referencedClass.isIncluded()) {
                    url = "#" + className;
                } else {
                    url = getExternalUrl(className);
                    if (!StringUtils.hasText(url)) {
                        label = className;
                    }
                }
                if (referencedMember != null) {
                    if (referencedMember instanceof ExecutableMemberDoc) {
                        if (referencedMemberName.indexOf('(') < 0) {
                            final ExecutableMemberDoc executableDoc = (ExecutableMemberDoc) referencedMember;
                            referencedMemberName = referencedMemberName + executableDoc.signature();
                        }
                        if (StringUtils.hasText(referencedMemberName)) {
                            label = referencedMemberName;
                        } else {
                            label = seeTagText;
                        }
                    }
                    if (referencedClass.isIncluded()) {
                        url += "." + referencedMemberName;
                    } else if (StringUtils.hasText(url)) {
                        url += "#" + referencedMemberName;
                    } else {
                        label = referencedMember.toString();
                    }
                }
                if (!StringUtils.hasText(label)) {
                    label = referencedClass.name();
                }
                link(writer, url, label, code);
            }
        }
    }
}
Also used : PackageDoc(com.sun.javadoc.PackageDoc) ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) MemberDoc(com.sun.javadoc.MemberDoc) ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Example 4 with ExecutableMemberDoc

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

the class Doclet method processClass.

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<>();
    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();
}
Also used : ExecutableMemberDoc(com.sun.javadoc.ExecutableMemberDoc) FieldDoc(com.sun.javadoc.FieldDoc) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) MethodDoc(com.sun.javadoc.MethodDoc) Parameter(com.sun.javadoc.Parameter) File(java.io.File) ConstructorDoc(com.sun.javadoc.ConstructorDoc) PrintWriter(java.io.PrintWriter)

Aggregations

ExecutableMemberDoc (com.sun.javadoc.ExecutableMemberDoc)4 ClassDoc (com.sun.javadoc.ClassDoc)2 MemberDoc (com.sun.javadoc.MemberDoc)2 PackageDoc (com.sun.javadoc.PackageDoc)2 Parameter (com.sun.javadoc.Parameter)2 ArrayList (java.util.ArrayList)2 ConstructorDoc (com.sun.javadoc.ConstructorDoc)1 FieldDoc (com.sun.javadoc.FieldDoc)1 MethodDoc (com.sun.javadoc.MethodDoc)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1