Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/package-info.java
41159 views
/*1* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* The Doclet API provides an environment which, in conjunction with27* the Language Model API and Compiler Tree API, allows clients28* to inspect the source-level structures of programs and29* libraries, including API comments embedded in the source.30*31* <p>32* The {@link StandardDoclet standard doclet} can be used to33* generate HTML-formatted documentation. It supports user-defined34* {@link Taglet taglets}, which can be used to generate customized35* output for user-defined tags in documentation comments.36*37* <p style="font-style: italic">38* <b>Note:</b> The declarations in this package supersede those39* in the older package {@code com.sun.javadoc}. For details on the40* mapping of old types to new types, see the41* <a href="#migration">Migration Guide</a>.42* </p>43*44* <p>45* Doclets are invoked by javadoc and this API can be used to write out46* program information to files. For example, the standard doclet is47* invoked by default, to generate HTML documentation.48* <p>4950* The invocation is defined by the interface {@link jdk.javadoc.doclet.Doclet}51* -- the {@link jdk.javadoc.doclet.Doclet#run(DocletEnvironment) run} interface52* method, defines the entry point.53* <pre>54* public boolean <b>run</b>(DocletEnvironment environment)55* </pre>56* The {@link jdk.javadoc.doclet.DocletEnvironment} instance holds the57* environment that the doclet will be initialized with. From this environment58* all other information can be extracted, in the form of59* {@link javax.lang.model.element.Element elements}. One can further use the APIs and utilities60* described by {@link javax.lang.model Language Model API} to query Elements and Types.61* <p>62*63* <a id="terminology"></a>64* <h2>Terminology</h2>65*66* <dl>67* <dt><a id="selected"></a>Selected</dt>68* <dd>An element is considered to be <em>selected</em>, if the69* <em>selection controls</em> <a href="#options">allow</a> it70* to be documented. (Note that synthetic elements are never71* selected.)72* </dd>73*74* <dt><a id="specified"></a>Specified</dt>75* <dd>The set of elements specified by the user are considered to be <em>specified76* elements</em>. Specified elements provide the starting points77* for determining the <em>included elements</em> to be documented.78* </dd>79*80* <dt><a id="included"></a>Included</dt>81* <dd>An element is considered to be <em>included</em>, if it is82* <em>specified</em> if it contains a <em>specified</em> element,83* or it is enclosed in a <em>specified</em> element, and is <em>selected</em>.84* Included elements will be documented.85* </dd>86*87* </dl>88* <p>89* <a id="options"></a>90* <h2>Options</h2>91* Javadoc <em>selection control</em> can be specified with these options92* as follows:93* <ul>94* <li>{@code --show-members:value} and {@code --show-types:value} can95* be used to filter the members, with the following values:96* <ul>97* <li> public -- considers only public elements98* <li> protected -- considers public and protected elements99* <li> package -- considers public, protected and package private elements100* <li> private -- considers all elements101* </ul>102*103* <li>{@code --show-packages:value} "exported" or "all" can be used104* to consider only exported packages or all packages within a module.105*106* <li>{@code --show-module-contents:value} can be used to specify the level at107* module declarations could be documented. A value of "api" indicates API108* level documentation, and "all" indicates detailed documentation.109* </ul>110* The following options can be used to specify the elements to be documented:111* <ul>112* <li>{@code --module} documents the specified modules.113*114* <li>{@code --expand-requires:value} expand the set of modules to be documented115* by including some or all of the modules dependencies. The value may be116* one of:117* <ul>118* <li> transitive -- each module specified explicitly on the command line is119* expanded to include the closure of its transitive dependencies120* <li> all -- each module specified explicitly on the command line121* is expanded to include the closure of its transitive dependencies,122* and also all of its direct dependencies123* </ul>124* By default, only the specified modules will be considered, without expansion125* of the module dependencies.126*127* <li>{@code packagenames} can be used to specify packages.128* <li>{@code -subpackages} can be used to recursively load packages.129* <li>{@code -exclude} can be used exclude package directories.130* <li>{@code sourcefilenames} can be used to specify source file names.131* </ul>132* <p>133* <a id="legacy-interactions"></a>134* <h3>Interactions with older options.</h3>135*136* The new {@code --show-*} options provide a more detailed replacement137* for the older options {@code -public}, {@code -protected}, {@code -package}, {@code -private}.138* Alternatively, the older options can continue to be used as shorter139* forms for combinations of the new options, as described below:140* <table class="striped">141* <caption>Short form options mapping</caption>142* <thead>143* <tr> <th rowspan="2" scope="col" style="vertical-align:top">144* Older option145* <th colspan="5" scope="col" style="border-bottom: 1px solid black">146* Equivalent to these values with the new option147* <tr> <th scope="col">{@code --show-members}148* <th scope="col">{@code --show-types}149* <th scope="col">{@code --show-packages}150* <th scope="col">{@code --show-module-contents}151* </thead>152* <tbody>153* <tr> <th scope="row">{@code -public}154* <td>public155* <td>public156* <td>exported157* <td>api158* <tr> <th scope="row">{@code -protected}159* <td>protected160* <td>protected161* <td>exported162* <td>api163* <tr> <th scope="row">{@code -package}164* <td>package165* <td>package166* <td>all167* <td>all168* <tr> <th scope="row">{@code -private}169* <td>private170* <td>private171* <td>all172* <td>all173* </tbody>174* </table>175* <p>176* <a id="qualified"></a>177* A <em>qualified</em> element name is one that has its package178* name prepended to it, such as {@code java.lang.String}. A non-qualified179* name has no package name, such as {@code String}.180* <p>181*182* <a id="example"></a>183* <h2>Example</h2>184*185* The following is an example doclet that displays information of a class186* and its members, supporting an option.187* <pre>188* // note imports deleted for clarity189* public class Example implements Doclet {190* Reporter reporter;191* @Override192* public void init(Locale locale, Reporter reporter) {193* reporter.print(Kind.NOTE, "Doclet using locale: " + locale);194* this.reporter = reporter;195* }196*197* public void printElement(DocTrees trees, Element e) {198* DocCommentTree docCommentTree = trees.getDocCommentTree(e);199* if (docCommentTree != null) {200* System.out.println("Element (" + e.getKind() + ": "201* + e + ") has the following comments:");202* System.out.println("Entire body: " + docCommentTree.getFullBody());203* System.out.println("Block tags: " + docCommentTree.getBlockTags());204* }205* }206*207* @Override208* public boolean run(DocletEnvironment docEnv) {209* reporter.print(Kind.NOTE, "overviewfile: " + overviewfile);210* // get the DocTrees utility class to access document comments211* DocTrees docTrees = docEnv.getDocTrees();212*213* // location of an element in the same directory as overview.html214* try {215* Element e = ElementFilter.typesIn(docEnv.getSpecifiedElements()).iterator().next();216* DocCommentTree docCommentTree217* = docTrees.getDocCommentTree(e, overviewfile);218* if (docCommentTree != null) {219* System.out.println("Overview html: " + docCommentTree.getFullBody());220* }221* } catch (IOException missing) {222* reporter.print(Kind.ERROR, "No overview.html found.");223* }224*225* for (TypeElement t : ElementFilter.typesIn(docEnv.getIncludedElements())) {226* System.out.println(t.getKind() + ":" + t);227* for (Element e : t.getEnclosedElements()) {228* printElement(docTrees, e);229* }230* }231* return true;232* }233*234* @Override235* public String getName() {236* return "Example";237* }238*239* private String overviewfile;240*241* @Override242* public Set<? extends Option> getSupportedOptions() {243* Option[] options = {244* new Option() {245* private final List<String> someOption = Arrays.asList(246* "-overviewfile",247* "--overview-file",248* "-o"249* );250*251* @Override252* public int getArgumentCount() {253* return 1;254* }255*256* @Override257* public String getDescription() {258* return "an option with aliases";259* }260*261* @Override262* public Option.Kind getKind() {263* return Option.Kind.STANDARD;264* }265*266* @Override267* public List<String> getNames() {268* return someOption;269* }270*271* @Override272* public String getParameters() {273* return "file";274* }275*276* @Override277* public boolean process(String opt, List<String> arguments) {278* overviewfile = arguments.get(0);279* return true;280* }281* }282* };283* return new HashSet<>(Arrays.asList(options));284* }285*286* @Override287* public SourceVersion getSupportedSourceVersion() {288* // support the latest release289* return SourceVersion.latest();290* }291* }292* </pre>293* <p>294* This doclet can be invoked with a command line, such as:295* <pre>296* javadoc -doclet Example \297* -overviewfile overview.html \298* -sourcepath source-location \299* source-location/Example.java300* </pre>301*302* <h2><a id="migration">Migration Guide</a></h2>303*304* <p>Many of the types in the old {@code com.sun.javadoc} API do not have equivalents in this305* package. Instead, types in the {@code javax.lang.model} and {@code com.sun.source} APIs306* are used instead.307*308* <p>The following table gives a guide to the mapping from old types to their replacements.309* In some cases, there is no direct equivalent.310*311* <table class="striped">312* <caption>Guide for mapping old types to new types</caption>313* <thead>314* <tr><th scope="col">Old Type<th scope="col">New Type315* </thead>316* <tbody style="text-align:left">317* <tr><th scope="row">{@code AnnotatedType} <td>{@link javax.lang.model.type.TypeMirror javax.lang.model.type.TypeMirror}318* <tr><th scope="row">{@code AnnotationDesc} <td>{@link javax.lang.model.element.AnnotationMirror javax.lang.model.element.AnnotationMirror}319* <tr><th scope="row">{@code AnnotationDesc.ElementValuePair}<td>{@link javax.lang.model.element.AnnotationValue javax.lang.model.element.AnnotationValue}320* <tr><th scope="row">{@code AnnotationTypeDoc} <td>{@link javax.lang.model.element.TypeElement javax.lang.model.element.TypeElement}321* <tr><th scope="row">{@code AnnotationTypeElementDoc} <td>{@link javax.lang.model.element.ExecutableElement javax.lang.model.element.ExecutableElement}322* <tr><th scope="row">{@code AnnotationValue} <td>{@link javax.lang.model.element.AnnotationValue javax.lang.model.element.AnnotationValue}323* <tr><th scope="row">{@code ClassDoc} <td>{@link javax.lang.model.element.TypeElement javax.lang.model.element.TypeElement}324* <tr><th scope="row">{@code ConstructorDoc} <td>{@link javax.lang.model.element.ExecutableElement javax.lang.model.element.ExecutableElement}325* <tr><th scope="row">{@code Doc} <td>{@link javax.lang.model.element.Element javax.lang.model.element.Element}326* <tr><th scope="row">{@code DocErrorReporter} <td>{@link jdk.javadoc.doclet.Reporter jdk.javadoc.doclet.Reporter}327* <tr><th scope="row">{@code Doclet} <td>{@link jdk.javadoc.doclet.Doclet jdk.javadoc.doclet.Doclet}328* <tr><th scope="row">{@code ExecutableMemberDoc} <td>{@link javax.lang.model.element.ExecutableElement javax.lang.model.element.ExecutableElement}329* <tr><th scope="row">{@code FieldDoc} <td>{@link javax.lang.model.element.VariableElement javax.lang.model.element.VariableElement}330* <tr><th scope="row">{@code LanguageVersion} <td>{@link javax.lang.model.SourceVersion javax.lang.model.SourceVersion}331* <tr><th scope="row">{@code MemberDoc} <td>{@link javax.lang.model.element.Element javax.lang.model.element.Element}332* <tr><th scope="row">{@code MethodDoc} <td>{@link javax.lang.model.element.ExecutableElement javax.lang.model.element.ExecutableElement}333* <tr><th scope="row">{@code PackageDoc} <td>{@link javax.lang.model.element.PackageElement javax.lang.model.element.PackageElement}334* <tr><th scope="row">{@code Parameter} <td>{@link javax.lang.model.element.VariableElement javax.lang.model.element.VariableElement}335* <tr><th scope="row">{@code ParameterizedType} <td>{@link javax.lang.model.type.DeclaredType javax.lang.model.type.DeclaredType}336* <tr><th scope="row">{@code ParamTag} <td>{@link com.sun.source.doctree.ParamTree com.sun.source.doctree.ParamTree}337* <tr><th scope="row">{@code ProgramElementDoc} <td>{@link javax.lang.model.element.Element javax.lang.model.element.Element}338* <tr><th scope="row">{@code RootDoc} <td>{@link jdk.javadoc.doclet.DocletEnvironment jdk.javadoc.doclet.DocletEnvironment}339* <tr><th scope="row">{@code SeeTag} <td>{@link com.sun.source.doctree.LinkTree com.sun.source.doctree.LinkTree}<br>340* {@link com.sun.source.doctree.SeeTree com.sun.source.doctree.SeeTree}341* <tr><th scope="row">{@code SerialFieldTag} <td>{@link com.sun.source.doctree.SerialFieldTree com.sun.source.doctree.SerialFieldTree}342* <tr><th scope="row">{@code SourcePosition} <td>{@link com.sun.source.util.SourcePositions com.sun.source.util.SourcePositions}343* <tr><th scope="row">{@code Tag} <td>{@link com.sun.source.doctree.DocTree com.sun.source.doctree.DocTree}344* <tr><th scope="row">{@code ThrowsTag} <td>{@link com.sun.source.doctree.ThrowsTree com.sun.source.doctree.ThrowsTree}345* <tr><th scope="row">{@code Type} <td>{@link javax.lang.model.type.TypeMirror javax.lang.model.type.TypeMirror}346* <tr><th scope="row">{@code TypeVariable} <td>{@link javax.lang.model.type.TypeVariable javax.lang.model.type.TypeVariable}347* <tr><th scope="row">{@code WildcardType} <td>{@link javax.lang.model.type.WildcardType javax.lang.model.type.WildcardType}348* </tbody>349* </table>350*351* @see jdk.javadoc.doclet.Doclet352* @see jdk.javadoc.doclet.DocletEnvironment353* @since 9354*/355356package jdk.javadoc.doclet;357358359