Search in sources :

Example 11 with ClassDoc

use of com.sun.javadoc.ClassDoc in project wso2-axis2-transports by wso2.

the class TestkitJavadocDoclet method start.

public static boolean start(RootDoc root) throws Exception {
    parseOptions(root.options());
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(resourceInfoFile));
    ResourceInfo resourceInfo = (ResourceInfo) in.readObject();
    in.close();
    for (ClassDoc clazz : root.classes()) {
        String qualifiedName = clazz.qualifiedName();
        List<Resource> usedBy = resourceInfo.getUsedBy(qualifiedName);
        Resource resource = resourceInfo.getResource(qualifiedName);
        List<Dependency> dependencies = resource == null ? null : resource.getDependencies();
        if (dependencies != null || usedBy != null) {
            StringBuilder buffer = new StringBuilder(clazz.getRawCommentText());
            buffer.append("<h2>Resource information</h2>");
            if (usedBy != null) {
                buffer.append("This resource is used by: ");
                boolean first = true;
                for (Resource r : usedBy) {
                    if (first) {
                        first = false;
                    } else {
                        buffer.append(", ");
                    }
                    buffer.append("{@link ");
                    buffer.append(r.getType());
                    buffer.append("}");
                }
            }
            if (dependencies != null) {
                buffer.append("<h3>Dependencies</h3>");
                buffer.append("<dl>");
                for (Dependency dependency : dependencies) {
                    buffer.append("<dt>{@link ");
                    buffer.append(dependency.getType());
                    buffer.append("} (");
                    buffer.append(dependency.getMultiplicity());
                    buffer.append(")</dt><dd>");
                    String comment = dependency.getComment();
                    if (comment == null) {
                        buffer.append("(no documentation available)");
                    } else {
                        buffer.append(comment);
                    }
                    buffer.append("</dd>");
                }
                buffer.append("</dl>");
            }
            clazz.setRawCommentText(buffer.toString());
        }
    }
    return Standard.start(root);
}
Also used : FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream) ClassDoc(com.sun.javadoc.ClassDoc)

Example 12 with ClassDoc

use of com.sun.javadoc.ClassDoc in project wso2-axis2-transports by wso2.

the class ResourceInfoDoclet method start.

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;
}
Also used : ParamTag(com.sun.javadoc.ParamTag) Type(com.sun.javadoc.Type) MethodDoc(com.sun.javadoc.MethodDoc) FileOutputStream(java.io.FileOutputStream) Parameter(com.sun.javadoc.Parameter) ObjectOutputStream(java.io.ObjectOutputStream) ClassDoc(com.sun.javadoc.ClassDoc)

Example 13 with ClassDoc

use of com.sun.javadoc.ClassDoc in project cxf by apache.

the class DumpJavaDoc method start.

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;
}
Also used : ParamTag(com.sun.javadoc.ParamTag) MethodDoc(com.sun.javadoc.MethodDoc) OutputStream(java.io.OutputStream) Parameter(com.sun.javadoc.Parameter) ParamTag(com.sun.javadoc.ParamTag) Tag(com.sun.javadoc.Tag) Properties(java.util.Properties) ClassDoc(com.sun.javadoc.ClassDoc)

Example 14 with ClassDoc

use of com.sun.javadoc.ClassDoc in project jersey by jersey.

the class ResourceDoclet method start.

/**
     * 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;
}
Also used : Marshaller(javax.xml.bind.Marshaller) XMLSerializer(org.apache.xml.serialize.XMLSerializer) ClassDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) URLClassLoader(java.net.URLClassLoader) JAXBContext(javax.xml.bind.JAXBContext) MalformedURLException(java.net.MalformedURLException) MethodDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType) MethodDoc(com.sun.javadoc.MethodDoc) FileOutputStream(java.io.FileOutputStream) URLClassLoader(java.net.URLClassLoader) ResourceDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType) BufferedOutputStream(java.io.BufferedOutputStream) ClassDoc(com.sun.javadoc.ClassDoc)

Example 15 with ClassDoc

use of com.sun.javadoc.ClassDoc in project RESTdoclet by IG-Group.

the class DocTypeUtils method getTypeDoc.

/**
    * Returns as a string a list of attributes plus comments for the given
    * iggroup complex type (or empty string if not iggroup), formatted in an
    * HTML table. This method will recurse if attributes are iggroup complex
    * types
    * 
    * @param type
    * @param processedTypes
    * @param leafType
    * @return
    */
private static String getTypeDoc(final Type type, HashMap<String, String> processedTypes, Boolean leafType) {
    LOG.info("getTypeDoc " + type + " leafType=" + leafType);
    String typeInfo = "";
    if (isRelevantType(type)) {
        ClassDoc typeDoc = type.asClassDoc();
        typeInfo = processedTypes.get(type.toString());
        if (typeInfo != null) {
            LOG.debug("Found cached typedoc for " + type.typeName() + " - " + typeInfo);
        }
        if (typeInfo == null && typeDoc != null) {
            typeInfo = "";
            // if this is a generic type then recurse with the first type argument
            if (isParameterisedType(type)) {
                LOG.debug("Parameterised type");
                if (type.asClassDoc() != null) {
                    typeInfo = getTypeDoc(type.asParameterizedType().typeArguments()[type.asParameterizedType().typeArguments().length - 1], processedTypes, true);
                }
            } else {
                logType(type);
                // put placeholder to stop recursion for self-referential types
                LOG.debug("Starting to cache: " + type.typeName());
                processedTypes.put(type.toString(), "");
                LOG.debug(typeDoc.commentText() + "  " + leafType);
                if (leafType && !typeDoc.commentText().isEmpty()) {
                    typeInfo += "<tr><span class=\"javadoc-header\">" + typeDoc.commentText() + "</span></tr>";
                    LOG.debug(typeInfo);
                }
                if (typeDoc.isEnum()) {
                    LOG.debug("Enum type");
                    typeInfo += getEnumDoc(type);
                } else {
                    // class
                    LOG.debug("Class");
                    // first do base class
                    if (typeDoc.superclass() != null) {
                        LOG.debug("base type = " + typeDoc.superclass().qualifiedName());
                        String baseTypeDoc = getTypeDoc(type.asClassDoc().superclassType(), processedTypes, false);
                        if (!baseTypeDoc.isEmpty()) {
                            LOG.debug("base type DOC = " + baseTypeDoc);
                            typeInfo += baseTypeDoc;
                        }
                    }
                    typeInfo += getPublicConstantDoc(type);
                    Collection<String> getterNames = getGetterNames(type);
                    for (MethodDoc method : typeDoc.methods()) {
                        if (method.isPublic() && getterNames.contains(method.name()) && !ignore(method)) {
                            String attributeInfo = "";
                            String attributeType = method.returnType().simpleTypeName();
                            // check if is this a parameterised type
                            ParameterizedType pt = method.returnType().asParameterizedType();
                            if (pt != null && pt.typeArguments().length > 0) {
                                attributeType += "[";
                                for (int i = 0; i < pt.typeArguments().length; i++) {
                                    attributeType += pt.typeArguments()[i].simpleTypeName();
                                    if (i < pt.typeArguments().length - 1) {
                                        attributeType += ", ";
                                    }
                                }
                                attributeType += "]";
                            }
                            // Check if this is an array
                            attributeType += method.returnType().dimension();
                            final String attributeName = getAttributeNameFromMethod(method.name());
                            attributeInfo += "<td>" + attributeType + " " + attributeName + "</td>";
                            // If type or parameterised type then recurse
                            LOG.debug("Generating attribute doc for " + method.returnType());
                            String attributeTypeDoc = getTypeDoc(method.returnType(), processedTypes, true);
                            if (!attributeTypeDoc.isEmpty()) {
                                LOG.debug("Found attribute doc for " + method.returnType());
                                attributeInfo += "<td>" + attributeTypeDoc + "</td>";
                            } else {
                                // no useful type information, so use whatever's on the attribute doc
                                LOG.debug("Found no attribute doc for " + method.returnType());
                                String fieldDoc = getFieldDoc(type, attributeName, method.commentText());
                                attributeInfo += "<td>" + fieldDoc + "</td>";
                            }
                            if (!attributeInfo.isEmpty()) {
                                typeInfo += "<tr>" + attributeInfo + "</tr>";
                            }
                        }
                    }
                }
                // Wrap in a table tag if this is concrete type
                if (leafType && !typeInfo.isEmpty()) {
                    typeInfo = "<table>" + typeInfo + "</table>";
                }
            }
        }
        LOG.debug("Caching: " + type);
        processedTypes.put(type.toString(), typeInfo);
    }
    if (typeInfo == null) {
        typeInfo = "";
    }
    LOG.debug("XXX " + type.typeName() + " XXX " + typeInfo);
    return typeInfo;
}
Also used : ParameterizedType(com.sun.javadoc.ParameterizedType) MethodDoc(com.sun.javadoc.MethodDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Aggregations

ClassDoc (com.sun.javadoc.ClassDoc)23 MethodDoc (com.sun.javadoc.MethodDoc)10 FileOutputStream (java.io.FileOutputStream)3 ParamTag (com.sun.javadoc.ParamTag)2 Parameter (com.sun.javadoc.Parameter)2 Tag (com.sun.javadoc.Tag)2 Type (com.sun.javadoc.Type)2 OutputStream (java.io.OutputStream)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 JAXBContext (javax.xml.bind.JAXBContext)2 Marshaller (javax.xml.bind.Marshaller)2 Controller (com.iggroup.oss.restdoclet.doclet.type.Controller)1 ResponseParameter (com.iggroup.oss.restdoclet.doclet.type.ResponseParameter)1 ControllerBuilder (com.iggroup.oss.restdoclet.doclet.type.builder.ControllerBuilder)1 JiBXUtils.marshallController (com.iggroup.oss.restdoclet.doclet.util.JiBXUtils.marshallController)1 FieldDoc (com.sun.javadoc.FieldDoc)1 MemberDoc (com.sun.javadoc.MemberDoc)1 ParameterizedType (com.sun.javadoc.ParameterizedType)1 BufferedOutputStream (java.io.BufferedOutputStream)1