JAVA basics: automatically generate your program development documentation
Source: Internet
Author: User
JAVA basics: automatically generate your program development documentation-general Linux technology-Linux programming and kernel information. For more information, see the following. At the end of the project, Everyone began to have a headache-writing documents ...... Yes, most of us are not trained from regular Programer. When I first studied programming, I never thought about writing a complete document for the programs I wrote, all the comments are only for you to remember what the code was doing at the time. No one has ever thought about upgrading or sharing the code. However, after commercial software is started, everything has changed, especially in large-scale team development projects.
You may have noticed that the java API documentation is always updated with the increase of the JSDK version. Imagine it is possible to manually maintain such complex documents? Of course it is impossible. All of this is the benefit of the javadoc applet (of course, there is also a credit for the java class library authors to make program comments ). The API documentation is automatically generated based on the latest source code, and everything is so easy-you only need to write the comments you are about to write in a more standardized manner, and then a little more detailed. However, it seems that people are not even aware of its existence, and few will use it to generate documents for their own programs. I don't know. Are you interested in it now? Now let's start this easy automatic document generation journey.
[How to insert comments]
JAVADOC does not generate code for you out of thin air, nor does it automatically analyze your code-everyone has their own code style. If you want to analyze and translate the code, I am afraid the machine code is more likely to generate hundreds of times. Its analysis mechanism relies on adding appropriate and sufficient comments to your code according to the specifications. Only when you write comments honestly can you do the previous work that requires dual copies.
The Javadoc tool extracts information from the following objects:
· Package.
· Public class.
· Public interface.
· Public or protected methods.
· Public or protected variables/constants.
You should provide a comment for each feature. Each comment must start with/** and end. In each entry /**
...... */Document annotations can contain texts in any format ., Its first sentence should be a summative statement, and javadoc will automatically propose it to make a summary page. Of course, here you can use some HTML tags, such... italics ;... indicates the "Printer" font of the same width ;... it indicates bold; it is even used to include an image. (But do not use something similar
Mark the title format, or horizontal separator.
--------------------------------------------------------------------------------
They will conflict with the document's own format) and then some special "tags" will be attached to the end ". Each tag starts with @, for example, @ author or @ param.
If the annotation contains links to other files that point to other files (for example, your illustrations and images), you need to place those files in the subdirectory named doc-files. Javadoc copies these directories and their files from the source directory to the document directory. Next we will classify and explain some of the tags that we may commonly use.
■ Regular comment
The following tags can be used in all document annotations.
◇ @ Since version
This tag can generate a comment indicating which version of the feature (class, interface, attribute, or method) is provided after the software version.
◇ @ Deprecated class, attribute, method name, etc.
You can add a comment indicating that the corresponding class, method, or attribute should no longer be used. Javadoc only copies the first sentence to the overview part and the index. The following sentence can explain why you are not encouraged to use it. Sometimes, we recommend another solution, for example:
@ Deprecated Use theAnotherMethod
Or use {@ link} to mark a recommended connection. We will introduce it immediately.
◇ @ See link
This tag adds a hyperlink in the "See also" (See) section. The link here can be the following:
· Package. class # Add an anchor link to the member in the member label. Before the space, the link is the target and the text is displayed. Note that the separator class and its members are # rather than the point number. You can omit the package name or even the class name. The default value is the current package and class, which makes the comment more concise, but # cannot be omitted. Label can be omitted.
· The label does not need to be explained.
· "Text" is directly added to "See also.
◇ {@ Link Target display text}
In fact, the usage of link is the same as that of see. see lists links in the item for reference, link directly embeds a hyperlink text at any position in the current comment.
■ Add comments to classes and interfaces
The comments of the class or interface must be followed by all the import statements and must be located before the class definition. In addition to the general mark mentioned above, you can also use the following mark in the class annotation:
◇ @ Author name
When the author flag is used, the "Author" (author) item is added to the generated document with the specified text. Document comments can contain multiple @ author tags. You can specify one or more names for each @ author. Of course, you can also use multiple author tags, but they must be put together.
◇ @ Version
We recommend that you use a version entry for this tag. The text below can be any description of the current version.
The following is an example of class annotation:
/**
* An implementation of a menu bar. You add JMenu
Objects to
* Menu bar to construct a menu. When the user selects
JMenu
* Object, its associated JPopupMenu
Is displayed, allowing
* User to select one of the JMenuItems
On it.
*
* For information and examples of using menu bars see
*
Href = "http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html"> How
To Use Menus,
* A section in The Java Tutorial.
* For the keyboard keys used by this component in the standard
Look and
* Feel (L & F) renditions, see
* JMenuBar
Key assignments.
*
* Warning:
* Serialized objects of this class will not be compatible
With
* Future Swing releases. The current serialization support
Is appropriate
* For short term storage or RMI between applications running
The same
* Version of Swing. A future release of Swing will provide
Support
* Long term persistence.
*
* @ Beaninfo
* Attribute: isContainer true
* Description: A container for holding and displaying menus.
*
* @ Version 1.85 04/06/00
* @ Author Georges Saab
* @ Author David Karlton
* @ Author Arnaud Weber
* @ See JMenu
* @ See JPopupMenu
* @ See JMenuItem
*/
■ Method Annotation
Immediately before each method annotation, there must be a signature for the method it describes. In addition to marking for general purposes, you can also use the following annotations for methods:
◇ @ Param variable description
All parameters required by the current method need to be interpreted using this tag, and these tags should be put together. The specific description (description) can span multiple rows at the same time, and can be marked with html.
◇ @ Return the return value of this method
This label adds a return value ("Returns") Section for the current method. The specific description also supports html and can span multiple rows.
◇ @ Throws the exception thrown by this method
This tag adds an entry to the current method in the Throws section and creates a hyperlink automatically. The specific description can span multiple rows, and can also include html tags. All throws of a method must be put together.
The following is an example of a method annotation:
/**
* Returns the model object that
Handles single selections.
*
* @ Param ui the new MenuBarUI L & F
Object
* @ Return the SingleSelectionModel
Property
* @ See SingleSelectionModel
* @ See JComponent # getUIClassID
* @ See UIDefaults # getUI
*/
■ Package and summary comments
The preceding annotations are for a class and method. They can be directly stored in the JAVA source file. In order to generate a package, you can set a file named package.html in the directory of each package to describe the package. The text between tags... will be automatically extracted by javadoc.
You can also write all source files into the overview.html file and put them under the parent directory of all source files. Tag
The text between... will also be automatically extracted by javadoc to make the Overview of the document.
[How to extract program documentation]
First, let's take a look at the basic usage of javadoc according to the Convention. You can use javadoc
-Help to obtain detailed settings of the current version.
· Packagenames: the names of a series of packages are separated by spaces. Each package for which you want to create a document must be specified. Javadoc does not apply recursively to each package or use wildcards.
· Sourcefiles: names of a series of source files, separated by spaces. The source file name can contain paths and wildcards such as "*".
· @ Files: contains one or more package names and source files in any order. When too many files need to be specified in sourcefiles, you can use it to simplify the operation. The source file names are separated by spaces or carriage returns.
Common options include:
-D path
Specifies the target directory for saving the generated HTML file by javadoc. The default value is the current directory.
-Author
Include the author information in the document (omitted by default)
-Version
Include version information in the document (it will be omitted by default)
-Header text
Specifies the header file that is placed at the top of each output file. This header file is placed on the right of the upper navigation bar. The header text can contain HTML tags and spaces, but it must be enclosed by quotation marks. No escape is allowed for any internal quotation marks in the header.
-Footer text
Specifies the footer text placed at the bottom of each output file. The script will be placed on the right of the lower navigation bar, and the rest will be the same as the header.
-Bottom text
Specifies the text placed at the bottom of the output file. The text will be placed at the bottom of the page, under the navigation bar. Other parameters with the same header.
-Protected
Only the protected and common classes and members are displayed. This is the default status.
-Public
Only public classes and members are displayed.
-Package
Only packages, protected and public classes and members are displayed.
-Private
Show all classes and members. This is useful for internal development and use of program documentation.
-Sourcepath sourcepathlist
When the package name is passed to javadoc, you can specify the search path for the source file (. java. Note that the sourcepath option can be used only when the package name is specified using the javadoc command. If sourcepath is omitted, javadoc uses classpath to find the source file. Note: You need to set sourcepath to the directory where the source file of the target package is located. For example, you have a package cn.com. linuxaid: If you want to generate a document for the file in it, you must write it as c: jprojectcncomlinuxaid.
-Clathpath clathpathlist
Specify the path for javadoc to search for "Reference classes". "Reference classes" are classes with document values plus any classes they reference. Javadoc searches all subdirectories in the specified path. Classpathlist can contain multiple paths separated by semicolons.
Here is an example:
Assume that we need to place the generated document in targetdocdir and create a program document for the source file in the cn.com. linuxaid package in c: jproject. Then we need to enter the c: jprojectcncom(also contains the overview.html directory -- if you provide it ). Then run
Javadoc-d targetdocdir cn.com. linuxaid
In addition to the rich option parameters provided by javadoc for you to customize the program documentation you need to generate, you can also use doclet to generate any form of output, the specific situation, read the online help documentation carefully.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service