|
FlexDoc/Javadoc 2.0 Demo Java Doc |
The standard doclet can be used to generate HTML-formatted documentation. It supports user-defined taglets, which can be used to generate customized output for user-defined tags in documentation comments.
Note: The declarations in this package supersede those in the older package com.sun.javadoc. For details on the mapping of old types to new types, see the Migration Guide.
Doclets are invoked by javadoc and this API can be used to write out program information to files. For example, the standard doclet is invoked by default, to generate HTML documentation.
The invocation is defined by the interface Doclet -- the run interface method, defines the entry point.
public boolean run(DocletEnvironment environment)The DocletEnvironment instance holds the environment that the doclet will be initialized with. From this environment all other information can be extracted, in the form of elements. One can further use the APIs and utilities described by Language Model API to query Elements and Types.
Older option | Equivalent to these values with the new option | |||
---|---|---|---|---|
--show-members | --show-types | --show-packages | --show-module-contents | |
-public | public | public | exported | api |
-protected | protected | protected | exported | api |
-package | package | package | all | all |
-private | private | private | all | all |
A qualified element name is one that has its package name prepended to it, such as java.lang.String. A non-qualified name has no package name, such as String.
// note imports deleted for clarity public class Example implements Doclet { Reporter reporter; @Override public void init(Locale locale, Reporter reporter) { reporter.print(Kind.NOTE, "Doclet using locale: " + locale); this.reporter = reporter; } public void printElement(DocTrees trees, Element e) { DocCommentTree docCommentTree = trees.getDocCommentTree(e); if (docCommentTree != null) { System.out.println("Element (" + e.getKind() + ": " + e + ") has the following comments:"); System.out.println("Entire body: " + docCommentTree.getFullBody()); System.out.println("Block tags: " + docCommentTree.getBlockTags()); } } @Override public boolean run(DocletEnvironment docEnv) { reporter.print(Kind.NOTE, "overviewfile: " + overviewfile); // get the DocTrees utility class to access document comments DocTrees docTrees = docEnv.getDocTrees(); // location of an element in the same directory as overview.html try { Element e = ElementFilter.typesIn(docEnv.getSpecifiedElements()).iterator().next(); DocCommentTree docCommentTree = docTrees.getDocCommentTree(e, overviewfile); if (docCommentTree != null) { System.out.println("Overview html: " + docCommentTree.getFullBody()); } } catch (IOException missing) { reporter.print(Kind.ERROR, "No overview.html found."); } for (TypeElement t : ElementFilter.typesIn(docEnv.getIncludedElements())) { System.out.println(t.getKind() + ":" + t); for (Element e : t.getEnclosedElements()) { printElement(docTrees, e); } } return true; } @Override public String getName() { return "Example"; } private String overviewfile; @Override public Set<? extends Option> getSupportedOptions() { Option[] options = { new Option() { private final List<String> someOption = Arrays.asList( "-overviewfile", "--overview-file", "-o" ); @Override public int getArgumentCount() { return 1; } @Override public String getDescription() { return "an option with aliases"; } @Override public Option.Kind getKind() { return Option.Kind.STANDARD; } @Override public List<String> getNames() { return someOption; } @Override public String getParameters() { return "file"; } @Override public boolean process(String opt, List<String> arguments) { overviewfile = arguments.get(0); return true; } } }; return new HashSet<>(Arrays.asList(options)); } @Override public SourceVersion getSupportedSourceVersion() { // support the latest release return SourceVersion.latest(); } }
This doclet can be invoked with a command line, such as:
javadoc -doclet Example \ -overviewfile overview.html \ -sourcepath source-location \ source-location/Example.java
Many of the types in the old com.sun.javadoc API do not have equivalents in this package. Instead, types in the javax.lang.model and com.sun.source APIs are used instead.
The following table gives a guide to the mapping from old types to their replacements. In some cases, there is no direct equivalent.
Interface Summary |
||
The user doclet must implement this interface, as described in the
package description. |
||
An encapsulation of option name, aliases, parameters and descriptions
as used by the Doclet. |
||
Represents the operating environment of a single invocation
of the doclet. |
||
Interface for reporting diagnostics and other messages. |
||
The interface for a custom taglet supported by doclets such as
the standard doclet. |
Class Summary |
||
This doclet generates HTML-formatted documentation for the specified modules,
packages and types. |
Enum Summary |
||
The kind of an option. |
||
The mode specifying the level of detail of module documentation. |
||
The kind of location in which a tag may be used. |
|
FlexDoc/Javadoc 2.0 Demo Java Doc |