Search in sources :

Example 1 with ClassDoc

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

the class TokenTypesDoclet method start.

/**
     * The doclet's starter method.
     * @param root {@code RootDoc} given to the doclet
     * @return true if the given {@code RootDoc} is processed.
     * @exception FileNotFoundException will be thrown if the doclet
     *            will be unable to write to the specified file.
     */
public static boolean start(RootDoc root) throws FileNotFoundException {
    final String fileName = getDestFileName(root.options());
    final FileOutputStream fos = new FileOutputStream(fileName);
    final Writer osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
    final PrintWriter writer = new PrintWriter(osw, false);
    try {
        final ClassDoc[] classes = root.classes();
        final FieldDoc[] fields = classes[0].fields();
        for (final FieldDoc field : fields) {
            if (field.isStatic() && field.isPublic() && field.isFinal() && "int".equals(field.type().qualifiedTypeName())) {
                if (field.firstSentenceTags().length != 1) {
                    final String message = "Should be only one tag.";
                    throw new IllegalArgumentException(message);
                }
                writer.println(field.name() + "=" + field.firstSentenceTags()[0].text());
            }
        }
    } finally {
        writer.close();
    }
    return true;
}
Also used : FieldDoc(com.sun.javadoc.FieldDoc) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) ClassDoc(com.sun.javadoc.ClassDoc)

Example 2 with ClassDoc

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

the class ResourceDoclet method getSerializedLinkFromTag.

private static String getSerializedLinkFromTag(final SeeTag linkTag) {
    final MemberDoc referencedMember = linkTag.referencedMember();
    if (referencedMember == null) {
        throw new NullPointerException("Referenced member of @link " + print(linkTag) + " cannot be resolved.");
    }
    if (!referencedMember.isStatic()) {
        LOG.warning("Referenced member of @link " + print(linkTag) + " is not static." + " Right now only references to static members are supported.");
        return null;
    }
    /* Get referenced example bean
         */
    final ClassDoc containingClass = referencedMember.containingClass();
    final Object object;
    try {
        final Field declaredField = Class.forName(containingClass.qualifiedName(), false, Thread.currentThread().getContextClassLoader()).getDeclaredField(referencedMember.name());
        if (referencedMember.isFinal()) {
            declaredField.setAccessible(true);
        }
        object = declaredField.get(null);
        LOG.log(Level.FINE, "Got object " + object);
    } catch (final Exception e) {
        LOG.info("Have classloader: " + ResourceDoclet.class.getClassLoader().getClass());
        LOG.info("Have thread classloader " + Thread.currentThread().getContextClassLoader().getClass());
        LOG.info("Have system classloader " + ClassLoader.getSystemClassLoader().getClass());
        LOG.log(Level.SEVERE, "Could not get field " + referencedMember.qualifiedName(), e);
        return null;
    }
    /* marshal the bean to xml
         */
    try {
        final JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
        final StringWriter stringWriter = new StringWriter();
        final Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(object, stringWriter);
        final String result = stringWriter.getBuffer().toString();
        LOG.log(Level.FINE, "Got marshalled output:\n" + result);
        return result;
    } catch (final Exception e) {
        LOG.log(Level.SEVERE, "Could serialize bean to xml: " + object, e);
        return null;
    }
}
Also used : Field(java.lang.reflect.Field) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) MemberDoc(com.sun.javadoc.MemberDoc) MalformedURLException(java.net.MalformedURLException) ClassDoc(com.sun.javadoc.ClassDoc)

Example 3 with ClassDoc

use of com.sun.javadoc.ClassDoc in project rest.li by linkedin.

the class RestLiDoclet method start.

/**
   * 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;
}
Also used : MethodDoc(com.sun.javadoc.MethodDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Example 4 with ClassDoc

use of com.sun.javadoc.ClassDoc in project jangaroo-tools by CoreMedia.

the class MethodDocImpl method overriddenMethod.

public MethodDoc overriddenMethod() {
    ClassDoc superClass = containingClass().superclass();
    while (superClass != null) {
        MethodDoc superMethodDoc = getSuperMethodDoc(superClass);
        if (superMethodDoc != null)
            return superMethodDoc;
        superClass = superClass.superclass();
    }
    return null;
}
Also used : MethodDoc(com.sun.javadoc.MethodDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Example 5 with ClassDoc

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

the class XmlDoclet method controllerDocs.

/**
    * Generates Java documentation for controllers.
    * 
    * @param rootDoc the root Java documentation object.
    * @throws IoException
    * @throws JiBXException
    */
public static void controllerDocs(final RootDoc rootDoc) throws IOException, JiBXException {
    LOG.info("Finding controllers.....");
    Boolean found = false;
    for (ClassDoc classDoc : rootDoc.classes()) {
        LOG.debug("Controller? " + classDoc.qualifiedName() + ".java");
        if (isAnnotated(classDoc, org.springframework.stereotype.Controller.class)) {
            LOG.info("Found controller.  Generating javadoc xml for " + classDoc.qualifiedName() + ".java");
            marshallController(new ControllerBuilder().build(new Controller(), classDoc), DocletUtils.documentationFile(classDoc));
            found = true;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("No controllers with Spring @Controller annotation found");
    }
    LOG.info("Done finding controllers.");
}
Also used : ControllerBuilder(com.iggroup.oss.restdoclet.doclet.type.builder.ControllerBuilder) Controller(com.iggroup.oss.restdoclet.doclet.type.Controller) JiBXUtils.marshallController(com.iggroup.oss.restdoclet.doclet.util.JiBXUtils.marshallController) ClassDoc(com.sun.javadoc.ClassDoc)

Aggregations

ClassDoc (com.sun.javadoc.ClassDoc)20 MethodDoc (com.sun.javadoc.MethodDoc)8 FileOutputStream (java.io.FileOutputStream)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 Tag (com.sun.javadoc.Tag)1 Type (com.sun.javadoc.Type)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1