mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-06 10:42:45 +00:00
8235947: Cleanup/simplify Utils.getBlockTags
Reviewed-by: prappo, hannesw
This commit is contained in:
parent
a3c0f4c804
commit
dc5728ed95
@ -38,6 +38,7 @@ import javax.lang.model.util.ElementFilter;
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.DocTree.Kind;
|
||||
import com.sun.source.doctree.UnknownBlockTagTree;
|
||||
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
|
||||
import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
@ -365,7 +366,9 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
|
||||
utils.propertyName((ExecutableElement) member));
|
||||
fullBody.addAll(cmtutils.makeFirstSentenceTree(text));
|
||||
}
|
||||
List<? extends DocTree> propertyTags = utils.getBlockTags(property, "propertyDescription");
|
||||
List<? extends DocTree> propertyTags = utils.getBlockTags(property,
|
||||
t -> (t instanceof UnknownBlockTagTree)
|
||||
&& ((UnknownBlockTagTree) t).getTagName().equals("propertyDescription"));
|
||||
if (propertyTags.isEmpty()) {
|
||||
List<? extends DocTree> comment = utils.getFullBody(property);
|
||||
blockTags.addAll(cmtutils.makePropertyDescriptionTree(comment));
|
||||
@ -378,14 +381,10 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
|
||||
List<? extends DocTree> tags = utils.getBlockTags(property, Kind.SINCE);
|
||||
blockTags.addAll(tags);
|
||||
|
||||
List<? extends DocTree> bTags = utils.getBlockTags(property, Kind.UNKNOWN_BLOCK_TAG);
|
||||
CommentHelper ch = utils.getCommentHelper(property);
|
||||
for (DocTree dt : bTags) {
|
||||
String tagName = ch.getTagName(dt);
|
||||
if ( "defaultValue".equals(tagName)) {
|
||||
blockTags.add(dt);
|
||||
}
|
||||
}
|
||||
List<? extends DocTree> bTags = utils.getBlockTags(property,
|
||||
t -> (t instanceof UnknownBlockTagTree)
|
||||
&& ((UnknownBlockTagTree) t).getTagName().equals("defaultValue"));
|
||||
blockTags.addAll(bTags);
|
||||
|
||||
//add @see tags
|
||||
if (!isGetter && !isSetter) {
|
||||
|
||||
@ -29,6 +29,7 @@ import java.util.Set;
|
||||
import javax.lang.model.element.Element;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.UnknownBlockTagTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
@ -42,11 +43,20 @@ import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
*/
|
||||
public class BaseTaglet implements Taglet {
|
||||
|
||||
protected final DocTree.Kind tagKind;
|
||||
protected final String name;
|
||||
private final boolean inline;
|
||||
private final Set<Location> sites;
|
||||
|
||||
BaseTaglet(DocTree.Kind tagKind, boolean inline, Set<Location> sites) {
|
||||
this.tagKind = tagKind;
|
||||
this.name = tagKind.tagName;
|
||||
this.inline = inline;
|
||||
this.sites = sites;
|
||||
}
|
||||
|
||||
BaseTaglet(String name, boolean inline, Set<Location> sites) {
|
||||
this.tagKind = inline ? DocTree.Kind.UNKNOWN_INLINE_TAG : DocTree.Kind.UNKNOWN_BLOCK_TAG;
|
||||
this.name = name;
|
||||
this.inline = inline;
|
||||
this.sites = sites;
|
||||
@ -59,6 +69,7 @@ public class BaseTaglet implements Taglet {
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in constructor documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in constructor documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
@ -68,78 +79,111 @@ public class BaseTaglet implements Taglet {
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in field documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in field documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inField() {
|
||||
return sites.contains(Location.FIELD);
|
||||
return sites.contains(Location.FIELD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in method documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in method documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inMethod() {
|
||||
return sites.contains(Location.METHOD);
|
||||
return sites.contains(Location.METHOD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in overview documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in method documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inOverview() {
|
||||
return sites.contains(Location.OVERVIEW);
|
||||
return sites.contains(Location.OVERVIEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in module documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in module documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inModule() {
|
||||
return sites.contains(Location.MODULE);
|
||||
return sites.contains(Location.MODULE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in package documentation.
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in package documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inPackage() {
|
||||
return sites.contains(Location.PACKAGE);
|
||||
return sites.contains(Location.PACKAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} can be used in type documentation (classes or interfaces).
|
||||
*
|
||||
* @return true if this {@code Taglet} can be used in type documentation and false
|
||||
* otherwise.
|
||||
*/
|
||||
public final boolean inType() {
|
||||
return sites.contains(Location.TYPE);
|
||||
return sites.contains(Location.TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this {@code Taglet} is an inline tag.
|
||||
*
|
||||
* @return true if this {@code Taglet} represents an inline tag and false otherwise.
|
||||
*/
|
||||
public final boolean isInlineTag() {
|
||||
return inline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of trees recognized by this taglet.
|
||||
*
|
||||
* @return the kind of trees recognized by this taglet
|
||||
*/
|
||||
public DocTree.Kind getTagKind() {
|
||||
return tagKind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this tag.
|
||||
*
|
||||
* @return the name of this tag.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this taglet accepts a {@code DocTree} node.
|
||||
* The taglet accepts a tree node if it has the same kind, and
|
||||
* if the kind is {@code UNKNOWN_BLOCK_TAG} the same tag name.
|
||||
*
|
||||
* @param tree the tree node
|
||||
* @return {@code true} if this taglet accepts this tree node.
|
||||
*/
|
||||
public boolean accepts(DocTree tree) {
|
||||
return (tree.getKind() == DocTree.Kind.UNKNOWN_BLOCK_TAG
|
||||
&& tagKind == DocTree.Kind.UNKNOWN_BLOCK_TAG)
|
||||
? ((UnknownBlockTagTree) tree).getTagName().equals(name)
|
||||
: tree.getKind() == tagKind;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws UnsupportedTagletOperationException thrown when the method is
|
||||
* not supported by the taglet.
|
||||
* not supported by the taglet.
|
||||
*/
|
||||
public Content getTagletOutput(Element element, DocTree tag, TagletWriter writer) {
|
||||
throw new UnsupportedTagletOperationException("Method not supported in taglet " + getName() + ".");
|
||||
@ -147,8 +191,9 @@ public class BaseTaglet implements Taglet {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws UnsupportedTagletOperationException thrown when the method is not
|
||||
* supported by the taglet.
|
||||
* supported by the taglet.
|
||||
*/
|
||||
public Content getTagletOutput(Element holder, TagletWriter writer) {
|
||||
throw new UnsupportedTagletOperationException("Method not supported in taglet " + getName() + ".");
|
||||
|
||||
@ -33,8 +33,6 @@ import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.CODE;
|
||||
|
||||
/**
|
||||
* An inline Taglet used to denote literal code fragments.
|
||||
* The enclosed text is interpreted as not containing HTML markup or
|
||||
@ -56,7 +54,7 @@ import static com.sun.source.doctree.DocTree.Kind.CODE;
|
||||
public class CodeTaglet extends BaseTaglet {
|
||||
|
||||
CodeTaglet() {
|
||||
super(CODE.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.CODE, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -28,11 +28,10 @@ package jdk.javadoc.internal.doclets.toolkit.taglets;
|
||||
import java.util.EnumSet;
|
||||
import javax.lang.model.element.Element;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.DEPRECATED;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @deprecated tag.
|
||||
*
|
||||
@ -45,7 +44,7 @@ import static com.sun.source.doctree.DocTree.Kind.DEPRECATED;
|
||||
public class DeprecatedTaglet extends BaseTaglet {
|
||||
|
||||
public DeprecatedTaglet() {
|
||||
super(DEPRECATED.tagName, false,
|
||||
super(DocTree.Kind.DEPRECATED, false,
|
||||
EnumSet.of(Location.MODULE, Location.TYPE, Location.CONSTRUCTOR, Location.METHOD, Location.FIELD));
|
||||
}
|
||||
|
||||
|
||||
@ -32,8 +32,6 @@ import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.DOC_ROOT;
|
||||
|
||||
/**
|
||||
* An inline Taglet representing {@docRoot}. This taglet is
|
||||
* used to get the relative path to the document's root output
|
||||
@ -51,7 +49,7 @@ public class DocRootTaglet extends BaseTaglet {
|
||||
* Construct a new DocRootTaglet.
|
||||
*/
|
||||
public DocRootTaglet() {
|
||||
super(DOC_ROOT.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.DOC_ROOT, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -32,8 +32,6 @@ import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.INDEX;
|
||||
|
||||
/**
|
||||
* An inline Taglet used to index word or a phrase.
|
||||
* The enclosed text is interpreted as not containing HTML markup or
|
||||
@ -43,7 +41,7 @@ import static com.sun.source.doctree.DocTree.Kind.INDEX;
|
||||
public class IndexTaglet extends BaseTaglet {
|
||||
|
||||
IndexTaglet() {
|
||||
super(INDEX.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.INDEX, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -39,8 +39,6 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.INHERIT_DOC;
|
||||
|
||||
/**
|
||||
* An inline Taglet representing the {@code inheritDoc} tag. This tag should only
|
||||
* be used with a method. It is used to inherit documentation from overridden
|
||||
@ -58,7 +56,7 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
* Construct a new InheritDocTaglet.
|
||||
*/
|
||||
public InheritDocTaglet () {
|
||||
super(INHERIT_DOC.tagName, true, EnumSet.of(Location.TYPE, Location.METHOD));
|
||||
super(DocTree.Kind.INHERIT_DOC, true, EnumSet.of(Location.TYPE, Location.METHOD));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +112,7 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
|
||||
@Override
|
||||
public Content getTagletOutput(Element e, DocTree tag, TagletWriter tagletWriter) {
|
||||
DocTree inheritTag = (tag.getKind() == INHERIT_DOC) ? null : tag;
|
||||
DocTree inheritTag = (tag.getKind() == DocTree.Kind.INHERIT_DOC) ? null : tag;
|
||||
return retrieveInheritedDocumentation(tagletWriter, e,
|
||||
inheritTag, tagletWriter.isFirstSentence);
|
||||
}
|
||||
|
||||
@ -31,8 +31,6 @@ import javax.lang.model.element.Element;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.LITERAL;
|
||||
/**
|
||||
* An inline Taglet used to denote literal text.
|
||||
* For example, the text:
|
||||
@ -49,7 +47,7 @@ import static com.sun.source.doctree.DocTree.Kind.LITERAL;
|
||||
public class LiteralTaglet extends BaseTaglet {
|
||||
|
||||
LiteralTaglet() {
|
||||
super(LITERAL.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.LITERAL, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,7 +29,6 @@ import java.util.*;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
@ -42,8 +41,6 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.PARAM;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @param tag.
|
||||
*
|
||||
@ -66,7 +63,7 @@ public class ParamTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
* Construct a ParamTaglet.
|
||||
*/
|
||||
public ParamTaglet() {
|
||||
super(PARAM.tagName, false, EnumSet.of(Location.TYPE, Location.CONSTRUCTOR, Location.METHOD));
|
||||
super(DocTree.Kind.PARAM, false, EnumSet.of(Location.TYPE, Location.CONSTRUCTOR, Location.METHOD));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -42,8 +42,6 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.RETURN;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @return tag.
|
||||
*
|
||||
@ -55,7 +53,7 @@ import static com.sun.source.doctree.DocTree.Kind.RETURN;
|
||||
public class ReturnTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
|
||||
public ReturnTaglet() {
|
||||
super(RETURN.tagName, false, EnumSet.of(Location.METHOD));
|
||||
super(DocTree.Kind.RETURN, false, EnumSet.of(Location.METHOD));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,7 +74,7 @@ public class ReturnTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
Messages messages = writer.configuration().getMessages();
|
||||
Utils utils = writer.configuration().utils;
|
||||
TypeMirror returnType = utils.getReturnType((ExecutableElement)holder);
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, name);
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, DocTree.Kind.RETURN);
|
||||
|
||||
//Make sure we are not using @return tag on method with void return type.
|
||||
if (returnType != null && utils.isVoid(returnType)) {
|
||||
|
||||
@ -38,8 +38,6 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.SEE;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @see tag.
|
||||
*
|
||||
@ -51,7 +49,7 @@ import static com.sun.source.doctree.DocTree.Kind.SEE;
|
||||
public class SeeTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
|
||||
public SeeTaglet() {
|
||||
super(SEE.tagName, false, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.SEE, false, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -64,47 +64,70 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
protected final boolean enabled;
|
||||
|
||||
/**
|
||||
* Construct a <code>SimpleTaglet</code>.
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output.
|
||||
* @param locations the possible locations that this tag
|
||||
* can appear in. The <code>String</code> can contain 'p'
|
||||
* for package, 't' for type, 'm' for method, 'c' for constructor
|
||||
* and 'f' for field.
|
||||
* Constructs a {@code SimpleTaglet}.
|
||||
*
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output
|
||||
* @param locations the possible locations that this tag can appear in
|
||||
* The string can contain 'p' for package, 't' for type,
|
||||
* 'm' for method, 'c' for constructor and 'f' for field.
|
||||
* See {@linbk #getLocations(String) getLocations} for the
|
||||
* complete list.
|
||||
*/
|
||||
public SimpleTaglet(String tagName, String header, String locations) {
|
||||
this(tagName, header, getSites(locations), isEnabled(locations));
|
||||
this(tagName, header, getLocations(locations), isEnabled(locations));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>SimpleTaglet</code>.
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output.
|
||||
* @param sites the possible sites (locations) that this tag
|
||||
* can appear in. The <code>String</code> can contain 'p'
|
||||
* for package, 't' for type, 'm' for method, 'c' for constructor
|
||||
* and 'f' for field.
|
||||
* Constructs a {@code SimpleTaglet}.
|
||||
*
|
||||
* @param tagKind the kind of this tag
|
||||
* @param header the header to output
|
||||
* @param locations the possible locations that this tag can appear in.
|
||||
*/
|
||||
public SimpleTaglet(String tagName, String header, Set<Location> sites) {
|
||||
this(tagName, header, sites, true);
|
||||
public SimpleTaglet(DocTree.Kind tagKind, String header, Set<Location> locations) {
|
||||
this(tagKind, header, locations, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a {@code SimpleTaglet}.
|
||||
*
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output.
|
||||
* @param locations the possible locations that this tag can appear in
|
||||
*/
|
||||
public SimpleTaglet(String tagName, String header, Set<Location> locations) {
|
||||
this(tagName, header, locations, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a <code>SimpleTaglet</code>.
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output.
|
||||
* @param sites the possible sites (locations) that this tag
|
||||
* can appear in. The <code>String</code> can contain 'p'
|
||||
* for package, 't' for type, 'm' for method, 'c' for constructor
|
||||
* and 'f' for field.
|
||||
* Constructs a {@code SimpleTaglet}.
|
||||
*
|
||||
* @param tagName the name of this tag
|
||||
* @param header the header to output.
|
||||
* @param locations the possible locations that this tag can appear in
|
||||
*/
|
||||
public SimpleTaglet(String tagName, String header, Set<Location> sites, boolean enabled) {
|
||||
super(tagName, false, sites);
|
||||
public SimpleTaglet(String tagName, String header, Set<Location> locations, boolean enabled) {
|
||||
super(tagName, false, locations);
|
||||
this.header = header;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
private static Set<Location> getSites(String locations) {
|
||||
/**
|
||||
* Constructs a {@code SimpleTaglet}.
|
||||
*
|
||||
* @param tagKind the kind of this tag
|
||||
* @param header the header to output.
|
||||
* @param locations the possible locations that this tag can appear in
|
||||
*/
|
||||
public SimpleTaglet(DocTree.Kind tagKind, String header, Set<Location> locations, boolean enabled) {
|
||||
super(tagKind, false, locations);
|
||||
this.header = header;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
private static Set<Location> getLocations(String locations) {
|
||||
Set<Location> set = EnumSet.noneOf(Location.class);
|
||||
for (int i = 0; i < locations.length(); i++) {
|
||||
switch (locations.charAt(i)) {
|
||||
@ -144,7 +167,7 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
|
||||
@Override
|
||||
public void inherit(DocFinder.Input input, DocFinder.Output output) {
|
||||
List<? extends DocTree> tags = input.utils.getBlockTags(input.element, name);
|
||||
List<? extends DocTree> tags = input.utils.getBlockTags(input.element, this);
|
||||
if (!tags.isEmpty()) {
|
||||
output.holder = input.element;
|
||||
output.holderTag = tags.get(0);
|
||||
@ -163,7 +186,7 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
|
||||
@Override
|
||||
public Content getTagletOutput(Element holder, TagletWriter writer) {
|
||||
Utils utils = writer.configuration().utils;
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, getName());
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, this);
|
||||
if (header == null || tags.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -33,8 +33,6 @@ import jdk.javadoc.doclet.Taglet.Location;
|
||||
import com.sun.source.doctree.SummaryTree;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.SUMMARY;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @summary tag.
|
||||
*
|
||||
@ -47,7 +45,7 @@ import static com.sun.source.doctree.DocTree.Kind.SUMMARY;
|
||||
public class SummaryTaglet extends BaseTaglet {
|
||||
|
||||
public SummaryTaglet() {
|
||||
super(SUMMARY.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.SUMMARY, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -32,8 +32,6 @@ import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||
import javax.lang.model.element.Element;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.SYSTEM_PROPERTY;
|
||||
|
||||
/**
|
||||
* A taglet that represents the {@code @systemProperty} tag.
|
||||
*
|
||||
@ -46,7 +44,7 @@ import static com.sun.source.doctree.DocTree.Kind.SYSTEM_PROPERTY;
|
||||
public class SystemPropertyTaglet extends BaseTaglet {
|
||||
|
||||
SystemPropertyTaglet(){
|
||||
super(SYSTEM_PROPERTY.tagName, true, EnumSet.of(Location.CONSTRUCTOR, Location.METHOD, Location.FIELD,
|
||||
super(DocTree.Kind.SYSTEM_PROPERTY, true, EnumSet.of(Location.CONSTRUCTOR, Location.METHOD, Location.FIELD,
|
||||
Location.PACKAGE, Location.MODULE, Location.TYPE));
|
||||
}
|
||||
|
||||
|
||||
@ -622,22 +622,22 @@ public class TagletManager {
|
||||
addStandardTaglet(new ReturnTaglet());
|
||||
addStandardTaglet(new ThrowsTaglet());
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(EXCEPTION.tagName, null,
|
||||
new SimpleTaglet(EXCEPTION, null,
|
||||
EnumSet.of(Location.METHOD, Location.CONSTRUCTOR)));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(SINCE.tagName, resources.getText("doclet.Since"),
|
||||
new SimpleTaglet(SINCE, resources.getText("doclet.Since"),
|
||||
EnumSet.allOf(Location.class), !nosince));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(VERSION.tagName, resources.getText("doclet.Version"),
|
||||
new SimpleTaglet(VERSION, resources.getText("doclet.Version"),
|
||||
EnumSet.of(Location.OVERVIEW, Location.MODULE, Location.PACKAGE, Location.TYPE), showversion));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(AUTHOR.tagName, resources.getText("doclet.Author"),
|
||||
new SimpleTaglet(AUTHOR, resources.getText("doclet.Author"),
|
||||
EnumSet.of(Location.OVERVIEW, Location.MODULE, Location.PACKAGE, Location.TYPE), showauthor));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(SERIAL_DATA.tagName, resources.getText("doclet.SerialData"),
|
||||
new SimpleTaglet(SERIAL_DATA, resources.getText("doclet.SerialData"),
|
||||
EnumSet.noneOf(Location.class)));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(HIDDEN.tagName, null,
|
||||
new SimpleTaglet(HIDDEN, null,
|
||||
EnumSet.of(Location.TYPE, Location.METHOD, Location.FIELD)));
|
||||
|
||||
// This appears to be a default custom (non-standard) taglet
|
||||
@ -660,15 +660,15 @@ public class TagletManager {
|
||||
// Keep track of the names of standard tags for error checking purposes.
|
||||
// The following are not handled above.
|
||||
addStandardTaglet(new DeprecatedTaglet());
|
||||
addStandardTaglet(new BaseTaglet(LINK.tagName, true, EnumSet.allOf(Location.class)));
|
||||
addStandardTaglet(new BaseTaglet(LINK_PLAIN.tagName, true, EnumSet.allOf(Location.class)));
|
||||
addStandardTaglet(new BaseTaglet(USES.tagName, false, EnumSet.of(Location.MODULE)));
|
||||
addStandardTaglet(new BaseTaglet(PROVIDES.tagName, false, EnumSet.of(Location.MODULE)));
|
||||
addStandardTaglet(new BaseTaglet(LINK, true, EnumSet.allOf(Location.class)));
|
||||
addStandardTaglet(new BaseTaglet(LINK_PLAIN, true, EnumSet.allOf(Location.class)));
|
||||
addStandardTaglet(new BaseTaglet(USES, false, EnumSet.of(Location.MODULE)));
|
||||
addStandardTaglet(new BaseTaglet(PROVIDES, false, EnumSet.of(Location.MODULE)));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(SERIAL.tagName, null,
|
||||
new SimpleTaglet(SERIAL, null,
|
||||
EnumSet.of(Location.PACKAGE, Location.TYPE, Location.FIELD)));
|
||||
addStandardTaglet(
|
||||
new SimpleTaglet(SERIAL_FIELD.tagName, null, EnumSet.of(Location.FIELD)));
|
||||
new SimpleTaglet(SERIAL_FIELD, null, EnumSet.of(Location.FIELD)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,6 +27,7 @@ package jdk.javadoc.internal.doclets.toolkit.taglets;
|
||||
|
||||
import java.util.List;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
@ -218,7 +219,7 @@ public abstract class TagletWriter {
|
||||
* the given member.
|
||||
*
|
||||
* @param tagletManager the manager that manages the taglets.
|
||||
* @param element the Doc that we are print tags for.
|
||||
* @param element the element that we are print tags for.
|
||||
* @param taglets the taglets to print.
|
||||
* @param writer the writer that will generate the output strings.
|
||||
* @param output the output buffer to store the output in.
|
||||
@ -234,6 +235,16 @@ public abstract class TagletWriter {
|
||||
// section away from the tag info, so skip here.
|
||||
continue;
|
||||
}
|
||||
if (element.getKind() == ElementKind.MODULE && taglet instanceof BaseTaglet) {
|
||||
BaseTaglet t = (BaseTaglet) taglet;
|
||||
switch (t.getTagKind()) {
|
||||
// @uses and @provides are handled separately, so skip here.
|
||||
// See ModuleWriterImpl.computeModulesData
|
||||
case USES:
|
||||
case PROVIDES:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (taglet instanceof DeprecatedTaglet) {
|
||||
//Deprecated information is documented "inline", not in tag info
|
||||
//section.
|
||||
@ -249,7 +260,7 @@ public abstract class TagletWriter {
|
||||
} catch (UnsupportedTagletOperationException utoe) {
|
||||
//The taglet does not take a member as an argument. Let's try
|
||||
//a single tag.
|
||||
List<? extends DocTree> tags = utils.getBlockTags(element, taglet.getName());
|
||||
List<? extends DocTree> tags = utils.getBlockTags(element, taglet);
|
||||
if (!tags.isEmpty()) {
|
||||
currentOutput = taglet.getTagletOutput(element, tags.get(0), writer);
|
||||
}
|
||||
|
||||
@ -47,8 +47,6 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.THROWS;
|
||||
|
||||
/**
|
||||
* A taglet that represents the @throws tag.
|
||||
*
|
||||
@ -61,7 +59,7 @@ public class ThrowsTaglet extends BaseTaglet
|
||||
implements InheritableTaglet {
|
||||
|
||||
public ThrowsTaglet() {
|
||||
super(THROWS.tagName, false, EnumSet.of(Location.CONSTRUCTOR, Location.METHOD));
|
||||
super(DocTree.Kind.THROWS, false, EnumSet.of(Location.CONSTRUCTOR, Location.METHOD));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -143,7 +143,7 @@ public class UserTaglet implements Taglet {
|
||||
public Content getTagletOutput(Element holder, TagletWriter writer) {
|
||||
Content output = writer.getOutputInstance();
|
||||
Utils utils = writer.configuration().utils;
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, getName());
|
||||
List<? extends DocTree> tags = utils.getBlockTags(holder, this);
|
||||
if (!tags.isEmpty()) {
|
||||
String tagString = userTaglet.toString(tags, holder);
|
||||
if (tagString != null) {
|
||||
|
||||
@ -37,8 +37,6 @@ import jdk.javadoc.internal.doclets.toolkit.Messages;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
import static com.sun.source.doctree.DocTree.Kind.VALUE;
|
||||
|
||||
/**
|
||||
* An inline Taglet representing the value tag. This tag should only be used with
|
||||
* constant fields that have a value. It is used to access the value of constant
|
||||
@ -60,7 +58,7 @@ public class ValueTaglet extends BaseTaglet {
|
||||
* Construct a new ValueTaglet.
|
||||
*/
|
||||
public ValueTaglet() {
|
||||
super(VALUE.tagName, true, EnumSet.allOf(Location.class));
|
||||
super(DocTree.Kind.VALUE, true, EnumSet.allOf(Location.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -105,7 +105,6 @@ public class CommentHelper {
|
||||
overriddenElement = ove;
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public String getTagName(DocTree dtree) {
|
||||
switch (dtree.getKind()) {
|
||||
case AUTHOR:
|
||||
|
||||
@ -35,6 +35,7 @@ import java.text.RuleBasedCollator;
|
||||
import java.util.*;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
@ -77,6 +78,7 @@ import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.DocTree.Kind;
|
||||
import com.sun.source.doctree.ParamTree;
|
||||
import com.sun.source.doctree.SerialFieldTree;
|
||||
import com.sun.source.doctree.UnknownBlockTagTree;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.tree.LineMap;
|
||||
import com.sun.source.util.DocSourcePositions;
|
||||
@ -89,6 +91,8 @@ import jdk.javadoc.internal.doclets.toolkit.CommentUtils.DocCommentDuo;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Messages;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Resources;
|
||||
import jdk.javadoc.internal.doclets.toolkit.WorkArounds;
|
||||
import jdk.javadoc.internal.doclets.toolkit.taglets.BaseTaglet;
|
||||
import jdk.javadoc.internal.doclets.toolkit.taglets.Taglet;
|
||||
import jdk.javadoc.internal.tool.DocEnvImpl;
|
||||
|
||||
import static javax.lang.model.element.ElementKind.*;
|
||||
@ -1397,16 +1401,6 @@ public class Utils {
|
||||
return sb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a locale independent upper cased String. That is, it
|
||||
* always uses US locale, this is a clone of the one in StringUtils.
|
||||
* @param s to convert
|
||||
* @return converted String
|
||||
*/
|
||||
public static String toUpperCase(String s) {
|
||||
return s.toUpperCase(Locale.US);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a locale independent lower cased String. That is, it
|
||||
* always uses US locale, this is a clone of the one in StringUtils.
|
||||
@ -2979,74 +2973,36 @@ public class Utils {
|
||||
wksMap.remove(element);
|
||||
}
|
||||
|
||||
public List<? extends DocTree> filteredList(List<? extends DocTree> dlist, DocTree.Kind... select) {
|
||||
List<DocTree> list = new ArrayList<>(dlist.size());
|
||||
if (select == null)
|
||||
return dlist;
|
||||
for (DocTree dt : dlist) {
|
||||
if (dt.getKind() != ERRONEOUS) {
|
||||
for (DocTree.Kind kind : select) {
|
||||
if (dt.getKind() == kind) {
|
||||
list.add(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<? extends DocTree> getBlockTags0(Element element, DocTree.Kind... kinds) {
|
||||
DocCommentTree dcTree = getDocCommentTree(element);
|
||||
if (dcTree == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
return filteredList(dcTree.getBlockTags(), kinds);
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags(Element element) {
|
||||
return getBlockTags0(element, (Kind[]) null);
|
||||
DocCommentTree dcTree = getDocCommentTree(element);
|
||||
return dcTree == null ? Collections.emptyList() : dcTree.getBlockTags();
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags(Element element, DocTree.Kind... kinds) {
|
||||
return getBlockTags0(element, kinds);
|
||||
public List<? extends DocTree> getBlockTags(Element element, Predicate<DocTree> filter) {
|
||||
return getBlockTags(element).stream()
|
||||
.filter(t -> t.getKind() != ERRONEOUS)
|
||||
.filter(filter)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags(Element element, String tagName) {
|
||||
DocTree.Kind kind = null;
|
||||
switch (tagName) {
|
||||
case "author":
|
||||
case "deprecated":
|
||||
case "hidden":
|
||||
case "param":
|
||||
case "return":
|
||||
case "see":
|
||||
case "serial":
|
||||
case "since":
|
||||
case "throws":
|
||||
case "exception":
|
||||
case "version":
|
||||
kind = DocTree.Kind.valueOf(toUpperCase(tagName));
|
||||
return getBlockTags(element, kind);
|
||||
case "serialData":
|
||||
kind = SERIAL_DATA;
|
||||
return getBlockTags(element, kind);
|
||||
case "serialField":
|
||||
kind = SERIAL_FIELD;
|
||||
return getBlockTags(element, kind);
|
||||
default:
|
||||
kind = DocTree.Kind.UNKNOWN_BLOCK_TAG;
|
||||
break;
|
||||
}
|
||||
List<? extends DocTree> blockTags = getBlockTags(element, kind);
|
||||
List<DocTree> out = new ArrayList<>();
|
||||
String tname = tagName.startsWith("@") ? tagName.substring(1) : tagName;
|
||||
CommentHelper ch = getCommentHelper(element);
|
||||
for (DocTree dt : blockTags) {
|
||||
if (ch.getTagName(dt).equals(tname)) {
|
||||
out.add(dt);
|
||||
public List<? extends DocTree> getBlockTags(Element element, DocTree.Kind kind) {
|
||||
return getBlockTags(element, t -> t.getKind() == kind);
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags(Element element, DocTree.Kind kind, DocTree.Kind altKind) {
|
||||
return getBlockTags(element, t -> t.getKind() == kind || t.getKind() == altKind);
|
||||
}
|
||||
|
||||
public List<? extends DocTree> getBlockTags(Element element, Taglet taglet) {
|
||||
return getBlockTags(element, t -> {
|
||||
if (taglet instanceof BaseTaglet) {
|
||||
return ((BaseTaglet) taglet).accepts(t);
|
||||
} else if (t instanceof UnknownBlockTagTree) {
|
||||
return ((UnknownBlockTagTree) t).getTagName().equals(taglet.getName());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasBlockTag(Element element, DocTree.Kind kind) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user