com.sun.javadoc.RootDoc Java Examples

The following examples show how to use com.sun.javadoc.RootDoc. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwaggerMoreDoclet.java    From swagger-more with Apache License 2.0 6 votes vote down vote up
private static void parseAndAnnotate(RootDoc rootDoc) throws ClassNotFoundException, NotFoundException, CannotCompileException, IOException {
    for (ClassDoc classDoc : rootDoc.classes()) {
        if (StringUtils.isEmpty(classDoc.getRawCommentText())) {
            DocLogger.warn("No javadoc found in class " + classDoc.qualifiedName() + "." + classDoc.name());
        }
        Class clazz = Class.forName(classDoc.qualifiedName());
        ClassPool pool = ClassPool.getDefault();
        pool.insertClassPath(new ClassClassPath(clazz));
        CtClass ctClass = pool.get(clazz.getName());
        ApiInfo apiInfo = ApiInfo.fromClassDoc(clazz, classDoc);
        if (!apiInfo.hidden()) {
            annotateClassAnn(ctClass, apiInfo);
            for (MethodDoc methodDoc : classDoc.methods()) {
                ApiMethodInfo apiMethodInfo = ApiMethodInfo.fromMethodDoc(matchingMethod(clazz, methodDoc), methodDoc);
                if (StringUtils.isEmpty(methodDoc.getRawCommentText())) {
                    DocLogger.warn("No javadoc found in method " + classDoc.qualifiedName() + "." + methodDoc.name() + methodDoc.signature());
                }
                annotateMethodAnn(ctClass, apiMethodInfo);
            }
            DocLogger.info("Successfully annotated " + clazz.getTypeName());
        }
        ctClass.writeFile(classDir);
    }
}
 
Example #2
Source File: SwaggerMoreDoclet.java    From swagger-more with Apache License 2.0 6 votes vote down vote up
public static boolean start(RootDoc rootDoc) {
    // 插件启动入口
    DocLogger.setRootDoc(rootDoc);
    if (StringUtils.isEmpty(classDir)) {
        DocLogger.error("-classDir is not specified.");
        return false;
    }
    DocLogger.info("Writing classes to " + classDir);
    try {
        parseAndAnnotate(rootDoc);
    } catch (Exception e) {
        DocLogger.error(e.getMessage() + "\n" +
                Stream.of(e.getStackTrace()).map(StackTraceElement::toString)
                        .collect(joining("\n")));
        if (nonNull(e.getCause())) {
            DocLogger.error(e.getCause().getMessage() + "\n" +
                    Stream.of(e.getStackTrace()).map(StackTraceElement::toString)
                            .collect(joining("\n")));
        }
    }
    return true;
}
 
Example #3
Source File: MarkdownDoclet.java    From markdown-doclet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Construct a new Markdown Doclet.
 * @param options The command line options.
 * @param rootDoc The root document.
 */
public MarkdownDoclet(Options options, RootDoc rootDoc) {
    this.options = options;
    this.rootDoc = rootDoc;
    tagRenderers.put("@author", SimpleTagRenderer.INSTANCE);
    tagRenderers.put("@version", SimpleTagRenderer.INSTANCE);
    tagRenderers.put("@return", SimpleTagRenderer.INSTANCE);
    tagRenderers.put("@deprecated", SimpleTagRenderer.INSTANCE);
    tagRenderers.put("@since", SimpleTagRenderer.INSTANCE);
    tagRenderers.put("@param", ParamTagRenderer.INSTANCE);
    tagRenderers.put("@throws", ThrowsTagRenderer.INSTANCE);
    tagRenderers.put("@see", SeeTagRenderer.INSTANCE);
    UmlTagRenderer umlTagRenderer = new UmlTagRenderer();
    tagRenderers.put("@uml", umlTagRenderer);
    tagRenderers.put("@startuml", umlTagRenderer);
    tagRenderers.put("@enduml", TagRenderer.ELIDE);
    tagRenderers.put("@todo", new TodoTagRenderer());
}
 
Example #4
Source File: T8147801.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
RootDoc getRootDoc(boolean withOption) {
    List<String> opts = new ArrayList<>();
    if (withOption)
        opts.add("-XDfileManager.deferClose=10");
    opts.add("-doclet");
    opts.add(getClass().getName());
    opts.add("-classpath");
    opts.add(jarPath.toString());
    opts.add(Paths.get(System.getProperty("test.src"), "p", "Test.java").toString());
    System.err.println("javadoc opts: " + opts);
    int rc = com.sun.tools.javadoc.Main.execute(
            "javadoc",
            // by specifying our own class loader, we get the same Class instance as this
            getClass().getClassLoader(),
            opts.toArray(new String[opts.size()]));
    if (rc != 0) {
        error("unexpected exit from javadoc or doclet: " + rc);
    }
    return cachedRoot;
}
 
Example #5
Source File: SarlDoclet.java    From sarl with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:all")
@Override
public boolean start(AbstractDoclet doclet, RootDoc root) {
	configuration().root = configuration().getProxyInstaller().installProxies(root);
	if (!isValidDoclet(doclet)) {
		return false;
	}
	try {
		Reflect.callProc(this, AbstractDoclet.class, "startGeneration", //$NON-NLS-1$
				new Class[] { RootDoc.class },
				configuration().root);
	} catch (DocletAbortException e) {
		final Throwable cause = Utils.getCause(e);
		if (cause.getLocalizedMessage() != null) {
			configuration().root.printError(cause.getLocalizedMessage());
		} else {
			configuration().root.printError(cause.toString());
		}
		return false;
	} catch (Throwable exc) {
		Utils.getCause(exc).printStackTrace();
		return false;
	}
	return true;
}
 
Example #6
Source File: ConfigStandardDoclet.java    From tez with Apache License 2.0 6 votes vote down vote up
public static boolean start(RootDoc root) {
  //look for debug flag
  for (String[] opts : root.options()) {
    for (String opt : opts) {
      if (opt.equals(DEBUG_SWITCH)) {
        debugMode = true;
      }
    }
  }

  logMessage("Running doclet " + ConfigStandardDoclet.class.getSimpleName());
  ClassDoc[] classes = root.classes();
  for (int i = 0; i < classes.length; ++i) {
    processDoc(classes[i]);
  }

  return true;
}
 
Example #7
Source File: BatchEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #8
Source File: BatchEnvironment.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #9
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #10
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void installProxies(SarlConfiguration configuration) {
	final RootDoc doc = configuration.root;
	if (!(doc instanceof Proxy) && (doc instanceof RootDocImpl)) {
		configuration.root = new RootDocWrapper((RootDocImpl) doc);
	}
}
 
Example #11
Source File: BatchEnvironment.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #12
Source File: Main.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #13
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public RootDoc installProxies(RootDoc obj) {
	if (obj instanceof RootDocImpl) {
		return new RootDocWrapper((RootDocImpl) obj);
	}
	return obj;
}
 
Example #14
Source File: Main.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #15
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    String text = root.commentText();
    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
Example #16
Source File: BatchEnvironment.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #17
Source File: Main.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #18
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
/**
 * The entry point into parsing the javadoc.
 * 
 * @param rootDoc
 *            The RootDoc intstance obtained via the doclet API
 * @return The root node, containing everything parsed from javadoc doclet
 */
public Root parseRootDoc(RootDoc rootDoc) {
	Root rootNode = objectFactory.createRoot();

	for (ClassDoc classDoc : rootDoc.classes()) {
		PackageDoc packageDoc = classDoc.containingPackage();

		Package packageNode = packages.get(packageDoc.name());
		if (packageNode == null) {
			packageNode = parsePackage(packageDoc);
			packages.put(packageDoc.name(), packageNode);
			rootNode.getPackage().add(packageNode);
		}

		if (classDoc instanceof AnnotationTypeDoc) {
			packageNode.getAnnotation().add(parseAnnotationTypeDoc((AnnotationTypeDoc) classDoc));
		} else if (classDoc.isEnum()) {
			packageNode.getEnum().add(parseEnum(classDoc));
		} else if (classDoc.isInterface()) {
			packageNode.getInterface().add(parseInterface(classDoc));
		} else {
			packageNode.getClazz().add(parseClass(classDoc));
		}
	}

	return rootNode;
}
 
Example #19
Source File: BatchEnvironment.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #20
Source File: BatchEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #21
Source File: MarkdownDoclet.java    From markdown-doclet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * As specified by the Doclet specification.
 *
 * @param rootDoc The root doc.
 *
 * @return `true`, if process was successful.
 *
 * @see com.sun.javadoc.Doclet#start(RootDoc)
 */
public static boolean start(RootDoc rootDoc) {
    final MarkdownTaglets markdownTaglets = MarkdownTaglets.instance();
    Options options = new Options();
    String[][] forwardedOptions = options.load(rootDoc.options(), rootDoc);
    if ( forwardedOptions == null ) {
        return false;
    }
    MarkdownDoclet doclet = new MarkdownDoclet(options, rootDoc);
    markdownTaglets.setDocErrorReporter(doclet);
    doclet.process();
    if ( doclet.isError() ) {
        return false;
    }
    RootDocWrapper rootDocWrapper = new RootDocWrapper(rootDoc, forwardedOptions);
    if ( options.isHighlightEnabled() ) {
        // find the footer option
        int i = 0;
        for ( ; i < rootDocWrapper.options().length; i++ ) {
            if ( rootDocWrapper.options()[i][0].equals("-footer") ) {
                rootDocWrapper.options()[i][1] += HIGHLIGHT_JS_HTML;
                break;
            }
        }
        if ( i >= rootDocWrapper.options().length ) {
            rootDocWrapper.appendOption("-footer", HIGHLIGHT_JS_HTML);
        }
    }
    return Standard.start(rootDocWrapper) && doclet.postProcess();
}
 
Example #22
Source File: Main.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #23
Source File: BatchEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #24
Source File: ProgramHTMLOperatorDocGenerator.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public void generateDoc(Operator op, RootDoc rootDoc, PrintWriter out) {
	ClassDoc opDoc = rootDoc.classNamed(op.getClass().getName());

	// name
	out.println(op.getOperatorDescription().getName());

	// Description
	out.println(transformHTMLJavadocComment(opDoc.commentText(), op.getClass(), op.getOperatorDescription().getName()));

	out.println("#####");
}
 
Example #25
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #26
Source File: Main.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #27
Source File: BatchEnvironment.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new BatchEnvironment with the specified RootDoc.
 **/
public BatchEnvironment(RootDoc rootDoc) {
    this.rootDoc = rootDoc;

    /*
     * Initialize cached ClassDoc for types used by rmic.  Note
     * that any of these could be null if the boot class path is
     * incorrect, which could cause a NullPointerException later.
     */
    docRemote = rootDoc().classNamed(REMOTE);
    docException = rootDoc().classNamed(EXCEPTION);
    docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
    docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
 
Example #28
Source File: BatchEnvironment.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the RootDoc for this environment.
 **/
public RootDoc rootDoc() {
    return rootDoc;
}
 
Example #29
Source File: JavadocWrapper.java    From nomulus with Apache License 2.0 4 votes vote down vote up
/**
 * Obtains a Javadoc root document object for the specified source path and package/Java names.
 * If the source path is null, then the working directory is assumed as the source path.
 *
 * <p>If a list of package names is provided, then Javadoc will run on these packages and all
 * their subpackages, based out of the specified source path.
 *
 * <p>If a list of file names is provided, then Javadoc will also run on these Java source files.
 * The specified source path is not considered in this case.
 *
 * @see <a href="http://relation.to/12969.lace">Testing Java doclets</a>
 * @see <a href="http://www.docjar.com/docs/api/com/sun/tools/javadoc/JavadocTool.html">JavadocTool</a>
 */
private static RootDoc createRootDoc(
    @Nullable String sourcePath,
    Collection<String> packageNames,
    Collection<String> fileNames,
    long visibilityMask,
    boolean quiet) throws IOException {
  // Create a context to hold settings for Javadoc.
  Context context = new Context();

  // Redirect Javadoc stdout/stderr to null writers, since otherwise the Java compiler
  // issues lots of errors for classes that are imported and visible to blaze but not
  // visible locally to the compiler.
  // TODO(b/19124943): Find a way to ignore those errors so we can show real ones?
  Messager.preRegister(
      context,
      JavadocWrapper.class.getName(),
      new PrintWriter(CharStreams.nullWriter()),     // For errors.
      new PrintWriter(CharStreams.nullWriter()),     // For warnings.
      new PrintWriter(CharStreams.nullWriter()));    // For notices.

  // Set source path option for Javadoc.
  try (JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8)) {
    List<File> sourcePathFiles = new ArrayList<>();
    if (sourcePath != null) {
      for (String sourcePathEntry : Splitter.on(':').split(sourcePath)) {
        sourcePathFiles.add(new File(sourcePathEntry));
      }
    }
    fileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePathFiles);

    // Create an instance of Javadoc.
    JavadocTool javadocTool = JavadocTool.make0(context);

    // Convert the package and file lists to a format Javadoc can understand.
    ListBuffer<String> subPackages = new ListBuffer<>();
    subPackages.addAll(packageNames);
    ListBuffer<String> javaNames = new ListBuffer<>();
    javaNames.addAll(fileNames);

    // Invoke Javadoc and ask it for a RootDoc containing the specified packages.
    return javadocTool.getRootDocImpl(
        Locale.US.toString(),                    // Javadoc comment locale
        UTF_8.name(),                            // Source character encoding
        new ModifierFilter(visibilityMask),      // Element visibility filter
        javaNames.toList(),                      // Included Java file names
        com.sun.tools.javac.util.List.nil(),     // Doclet options
        com.sun.tools.javac.util.List.nil(),     // Source files
        false,                                   // Don't use BreakIterator
        subPackages.toList(),                    // Included sub-package names
        com.sun.tools.javac.util.List.nil(),     // Excluded package names
        false,                                   // Read source files, not classes
        false,                                   // Don't run legacy doclet
        quiet);                                  // If asked, run Javadoc quietly
  }
}
 
Example #30
Source File: GetTask_DocletClassTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static boolean start(RootDoc root) {
    lastCaller = root.classNamed("pkg.C").commentText().trim();
    return true;
}