APIdia Launch Partner
Top Description Inners Methods
jdk.javadoc.doclet

public Interface Taglet

Imports
java.net.URI, java.util.List, .Set, javax.lang.model.element.Element, com.sun.source.doctree.DocTree

The interface for a custom taglet supported by doclets such as the standard doclet. Custom taglets are used to handle custom tags in documentation comments; custom tags can be instantiated individually as either block tags, which appear at the end of a comment, or inline tags, which can appear within the main body of a documentation comment.

Each implementation of a taglet must provide a public no-argument constructor to be used by doclets to instantiate the taglet. A doclet will interact with classes implementing this interface as follows:

  1. The doclet will create an instance of a taglet using the no-arg constructor of the taglet class.
  2. Next, the doclet calls the init method with an appropriate environment and doclet.
  3. Afterwards, the doclet calls getName, getAllowedLocations, and isInlineTag, to determine the characteristics of the tags supported by the taglet.
  4. As appropriate, the doclet calls the toString method on the taglet object, giving it a list of tags, the element whose documentation comment contains the tags, and the root URI of the generated output, from which the taglet can determine the string to be included in the documentation. The doclet will typically specify any requirements on the contents of the string that is returned.

If a taglet object is created and used without the above protocol being followed, then the taglet's behavior is not defined by this interface specification.

API Note

It is typical for a taglet to be designed to work in conjunction with a specific doclet.

Since
9
See Also
User-Defined Taglets for the Standard Doclet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Taglet.Location

The kind of location in which a tag may be used.

Method Summary

Modifier and TypeMethod and Description
public Set<Taglet.Location>

Returns:

the set of supported locations for block tags
getAllowedLocations
()

Returns the set of supported locations for block tags.

public String

Returns:

the name of this tag
getName
()

Returns the name of the tag supported by this taglet.

public default void
init(DocletEnvironment
the environment in which the doclet and taglet are running
env
,
Doclet
the doclet that instantiated this taglet
doclet
)

Initializes this taglet with the given doclet environment and doclet.

public default boolean

Returns:

true if this taglet supports block tags
isBlockTag
()

Indicates whether this taglet supports block tags.

public boolean

Returns:

true if this taglet supports inline tags
isInlineTag
()

Indicates whether this taglet supports inline tags.

public String

Returns:

the string representation of the tags to be included in the generated output
toString
(List<? extends DocTree>
the list of instances of this tag
tags
,
Element
the element to which the enclosing comment belongs
element
)

Returns the string representation of the specified instances of this tag to be included in the generated output.

public default String

Returns:

the string representation of the tags to be included in the generated output
toString
(List<? extends DocTree>
the list of instances of this tag
tags
,
Element
the element to which the enclosing comment belongs
element
,
URI
the root URI of the generated output
docRoot
)

Returns the string representation of the specified instances of this tag to be included in the generated output.

Method Detail

getAllowedLocationsback to summary
public Set<Taglet.Location> getAllowedLocations()

Returns the set of supported locations for block tags.

Returns:Set<Taglet.Location>

the set of supported locations for block tags

getNameback to summary
public String getName()

Returns the name of the tag supported by this taglet.

Returns:String

the name of this tag

initback to summary
public default void init(DocletEnvironment env, Doclet doclet)

Initializes this taglet with the given doclet environment and doclet.

API Note

The environment may be used to access utility classes for elements and types if needed.

Implementation Specification

This implementation does nothing.

Parameters
env:DocletEnvironment

the environment in which the doclet and taglet are running

doclet:Doclet

the doclet that instantiated this taglet

isBlockTagback to summary
public default boolean isBlockTag()

Indicates whether this taglet supports block tags.

Implementation Specification

This implementation returns the inverse result to isInlineTag.

Returns:boolean

true if this taglet supports block tags

Since
15
isInlineTagback to summary
public boolean isInlineTag()

Indicates whether this taglet supports inline tags.

Returns:boolean

true if this taglet supports inline tags

toStringback to summary
public String toString(List<? extends DocTree> tags, Element element)

Returns the string representation of the specified instances of this tag to be included in the generated output.

If this taglet supports inline tags, this method will be called once per instance of the inline tag, each time with a singleton list. If this taglet supports block tags, it will be called once for each comment containing instances of block tags, with a list of all the instances of the block tag in that comment.

API Note

Taglets that do not need the root URI of the generated output may implement this method only. Taglets that require the root URI to link to other doclet-generated resources should override toString(List, Element, URI), and optionally throw an exception in the implementation of this method.

Parameters
tags:List<? extends DocTree>

the list of instances of this tag

element:Element

the element to which the enclosing comment belongs

Returns:String

the string representation of the tags to be included in the generated output

Exceptions
UnsupportedOperationException:
if toString(List, Element, URI) should be invoked instead
See Also
User-Defined Taglets for the Standard Doclet, toString(List, Element, URI)
toStringback to summary
public default String toString(List<? extends DocTree> tags, Element element, URI docRoot)

Returns the string representation of the specified instances of this tag to be included in the generated output.

If this taglet supports inline tags, this method will be called once per instance of the inline tag, each time with a singleton list. If this taglet supports block tags, it will be called once for each comment containing instances of block tags, with a list of all the instances of the block tag in that comment.

The docRoot argument identifies the root of the generated output as seen by the current resource, and may be used to resolve links to other resources generated by the doclet.

API Note

The exact form of docRoot is doclet-specific. For the standard doclet, it is a relative URI from the current resource to the root directory of the generated output. Taglets intended for use with other doclets should check the validity of the docRoot argument as appropriate.

Implementation Specification

The default implementation invokes toString(tags, element).

Parameters
tags:List<? extends DocTree>

the list of instances of this tag

element:Element

the element to which the enclosing comment belongs

docRoot:URI

the root URI of the generated output

Returns:String

the string representation of the tags to be included in the generated output

Exceptions
IllegalArgumentException:
if docRoot is not a valid URI
Since
27
See Also
User-Defined Taglets for the Standard Doclet, toString(List, Element)
jdk.javadoc.doclet back to summary

public final Enum Taglet.Location

extends Enum<Taglet.Location>
Class Inheritance

The kind of location in which a tag may be used.

Field Summary

Modifier and TypeField and Description
public static final Taglet.Location
CONSTRUCTOR

In the documentation for a constructor.

public static final Taglet.Location
FIELD

In the documentation for a field.

public static final Taglet.Location
METHOD

In the documentation for a method.

public static final Taglet.Location
MODULE

In the documentation for a module.

public static final Taglet.Location
OVERVIEW

In an Overview document.

public static final Taglet.Location
PACKAGE

In the documentation for a package.

public static final Taglet.Location
TYPE

In the documentation for a type, such as a class, interface or enum.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Taglet.Location
public static Taglet.Location[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CONSTRUCTORback to summary
public static final Taglet.Location CONSTRUCTOR

In the documentation for a constructor.

FIELDback to summary
public static final Taglet.Location FIELD

In the documentation for a field.

METHODback to summary
public static final Taglet.Location METHOD

In the documentation for a method.

MODULEback to summary
public static final Taglet.Location MODULE

In the documentation for a module.

OVERVIEWback to summary
public static final Taglet.Location OVERVIEW

In an Overview document.

PACKAGEback to summary
public static final Taglet.Location PACKAGE

In the documentation for a package.

TYPEback to summary
public static final Taglet.Location TYPE

In the documentation for a type, such as a class, interface or enum.

Constructor Detail

Locationback to summary
private Location()

Method Detail

valueOfback to summary
public static Taglet.Location valueOf(String name)
valuesback to summary
public static Taglet.Location[] values()