Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/javadoc/package-info.java
38890 views
/*1* Copyright (c) 1998, 2013, 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/**26The Doclet API (also called the Javadoc API) provides a mechanism27for clients to inspect the source-level structure of programs and28libraries, including javadoc comments embedded in the source.29This is useful for documentation, program checking, automatic30code generation and many other tools.31<p>3233Doclets are invoked by javadoc and use this API to write out34program information to files. For example, the standard doclet is called35by default and writes out documentation to HTML files.36<p>3738The invocation is defined by the abstract {@link com.sun.javadoc.Doclet} class39-- the entry point is the {@link com.sun.javadoc.Doclet#start(RootDoc) start} method:40<pre>41public static boolean <b>start</b>(RootDoc root)42</pre>43The {@link com.sun.javadoc.RootDoc} instance holds the root of the program structure44information. From this root all other program structure45information can be extracted.46<p>4748<a name="terminology"></a>49<h3>Terminology</h3>5051<a name="included"></a>52When calling javadoc, you pass in package names and source file names --53these are called the <em>specified</em> packages and classes.54You also pass in Javadoc options; the <em>access control</em> Javadoc options55(<code>-public</code>, <code>-protected</code>, <code>-package</code>,56and <code>-private</code>) filter program elements, producing a57result set, called the <em>included</em> set, or "documented" set.58(The unfiltered set is also available through59{@link com.sun.javadoc.PackageDoc#allClasses(boolean) allClasses(false)}.)60<p>6162<a name="class"></a>63Throughout this API, the term <em>class</em> is normally a64shorthand for "class or interface", as in: {@link com.sun.javadoc.ClassDoc},65{@link com.sun.javadoc.PackageDoc#allClasses() allClasses()}, and66{@link com.sun.javadoc.PackageDoc#findClass(String) findClass(String)}.67In only a couple of other places, it means "class, as opposed to interface",68as in: {@link com.sun.javadoc.Doc#isClass()}.69In the second sense, this API calls out four kinds of classes:70{@linkplain com.sun.javadoc.Doc#isOrdinaryClass() ordinary classes},71{@linkplain com.sun.javadoc.Doc#isEnum() enums},72{@linkplain com.sun.javadoc.Doc#isError() errors} and73{@linkplain com.sun.javadoc.Doc#isException() exceptions}.74Throughout the API, the detailed description of each program element75describes explicitly which meaning is being used.76<p>7778<a name="qualified"></a>79A <em>qualified</em> class or interface name is one that has its package80name prepended to it, such as <code>java.lang.String</code>. A non-qualified81name has no package name, such as <code>String</code>.82<p>8384<a name="example"></a>85<h3>Example</h3>8687The following is an example doclet that88displays information in the <code>@param</code> tags of the processed89classes:90<pre>91import com.sun.javadoc.*;9293public class ListParams extends <font color=red title="Doclet API">Doclet</font> {9495public static boolean start(<font color=red title="Doclet API">RootDoc</font> root) {96<font color=red title="Doclet API">ClassDoc</font>[] classes = root.<font color=red title="Doclet API">classes</font>();97for (int i = 0; i < classes.length; ++i) {98<font color=red title="Doclet API">ClassDoc</font> cd = classes[i];99printMembers(cd.<font color=red title="Doclet API">constructors</font>());100printMembers(cd.<font color=red title="Doclet API">methods</font>());101}102return true;103}104105static void printMembers(<font color=red title="Doclet API">ExecutableMemberDoc</font>[] mems) {106for (int i = 0; i < mems.length; ++i) {107<font color=red title="Doclet API">ParamTag</font>[] params = mems[i].<font color=red title="Doclet API">paramTags</font>();108System.out.println(mems[i].<font color=red title="Doclet API">qualifiedName</font>());109for (int j = 0; j < params.length; ++j) {110System.out.println(" " + params[j].<font color=red title="Doclet API">parameterName</font>()111+ " - " + params[j].<font color=red title="Doclet API">parameterComment</font>());112}113}114}115}116</pre>117Interfaces and methods from the Javadoc API are marked in118<font color=red title="Doclet API">red</font>.119{@link com.sun.javadoc.Doclet Doclet} is an abstract class that specifies120the invocation interface for doclets,121{@link com.sun.javadoc.Doclet Doclet} holds class or interface information,122{@link com.sun.javadoc.ExecutableMemberDoc} is a123superinterface of {@link com.sun.javadoc.MethodDoc} and124{@link com.sun.javadoc.ConstructorDoc},125and {@link com.sun.javadoc.ParamTag} holds information126from "<code>@param</code>" tags.127<p>128This doclet when invoked with a command line like:129<pre>130javadoc -doclet ListParams -sourcepath <source-location> java.util131</pre>132producing output like:133<pre>134...135java.util.ArrayList.add136index - index at which the specified element is to be inserted.137element - element to be inserted.138java.util.ArrayList.remove139index - the index of the element to removed.140...141142</pre>143@see com.sun.javadoc.Doclet144@see com.sun.javadoc.RootDoc145*/146@jdk.Exported147package com.sun.javadoc;148149150