8238646: Cleanup signature and use of CommentHelper

Reviewed-by: prappo
This commit is contained in:
Jonathan Gibbons 2020-02-10 13:29:03 -08:00
parent f0cdbbe120
commit b83285facc
16 changed files with 127 additions and 127 deletions

View file

@ -202,7 +202,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
Content div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel); Content div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel);
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(annotationType, deprs.get(0), div); addInlineDeprecatedComment(annotationType, deprs.get(0), div);
} }

View file

@ -495,7 +495,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
CommentHelper ch = utils.getCommentHelper(typeElement); CommentHelper ch = utils.getCommentHelper(typeElement);
DocTree dt = deprs.get(0); DocTree dt = deprs.get(0);
List<? extends DocTree> commentTags = ch.getBody(configuration, dt); List<? extends DocTree> commentTags = ch.getBody(dt);
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(typeElement, deprs.get(0), div); addInlineDeprecatedComment(typeElement, deprs.get(0), div);
} }

View file

@ -1038,14 +1038,14 @@ public class HtmlDocletWriter {
return new RawHtml(seetext); return new RawHtml(seetext);
} }
boolean isLinkPlain = kind == LINK_PLAIN; boolean isLinkPlain = kind == LINK_PLAIN;
Content label = plainOrCode(isLinkPlain, new RawHtml(ch.getLabel(configuration, see))); Content label = plainOrCode(isLinkPlain, new RawHtml(ch.getLabel(see)));
//The text from the @see tag. We will output this text when a label is not specified. //The text from the @see tag. We will output this text when a label is not specified.
Content text = plainOrCode(kind == LINK_PLAIN, new RawHtml(seetext)); Content text = plainOrCode(kind == LINK_PLAIN, new RawHtml(seetext));
TypeElement refClass = ch.getReferencedClass(configuration, see); TypeElement refClass = ch.getReferencedClass(see);
String refClassName = ch.getReferencedClassName(configuration, see); String refClassName = ch.getReferencedClassName(see);
Element refMem = ch.getReferencedMember(configuration, see); Element refMem = ch.getReferencedMember(see);
String refMemName = ch.getReferencedMemberName(see); String refMemName = ch.getReferencedMemberName(see);
if (refMemName == null && refMem != null) { if (refMemName == null && refMem != null) {
@ -1053,7 +1053,7 @@ public class HtmlDocletWriter {
} }
if (refClass == null) { if (refClass == null) {
//@see is not referencing an included class //@see is not referencing an included class
PackageElement refPackage = ch.getReferencedPackage(configuration, see); PackageElement refPackage = ch.getReferencedPackage(see);
if (refPackage != null && utils.isIncluded(refPackage)) { if (refPackage != null && utils.isIncluded(refPackage)) {
//@see is referencing an included package //@see is referencing an included package
if (label.isEmpty()) if (label.isEmpty())
@ -1169,7 +1169,7 @@ public class HtmlDocletWriter {
*/ */
public void addInlineComment(Element element, DocTree tag, Content htmltree) { public void addInlineComment(Element element, DocTree tag, Content htmltree) {
CommentHelper ch = utils.getCommentHelper(element); CommentHelper ch = utils.getCommentHelper(element);
List<? extends DocTree> description = ch.getDescription(configuration, tag); List<? extends DocTree> description = ch.getDescription(tag);
addCommentTags(element, tag, description, false, false, false, htmltree); addCommentTags(element, tag, description, false, false, false, htmltree);
} }
@ -1194,7 +1194,7 @@ public class HtmlDocletWriter {
*/ */
public void addInlineDeprecatedComment(Element e, DocTree tag, Content htmltree) { public void addInlineDeprecatedComment(Element e, DocTree tag, Content htmltree) {
CommentHelper ch = utils.getCommentHelper(e); CommentHelper ch = utils.getCommentHelper(e);
addCommentTags(e, ch.getBody(configuration, tag), true, false, false, htmltree); addCommentTags(e, ch.getBody(tag), true, false, false, htmltree);
} }
/** /**
@ -1220,8 +1220,8 @@ public class HtmlDocletWriter {
public void addSummaryDeprecatedComment(Element element, DocTree tag, Content htmltree) { public void addSummaryDeprecatedComment(Element element, DocTree tag, Content htmltree) {
CommentHelper ch = utils.getCommentHelper(element); CommentHelper ch = utils.getCommentHelper(element);
List<? extends DocTree> body = ch.getBody(configuration, tag); List<? extends DocTree> body = ch.getBody(tag);
addCommentTags(element, ch.getFirstSentenceTrees(configuration, body), true, true, true, htmltree); addCommentTags(element, ch.getFirstSentenceTrees(body), true, true, true, htmltree);
} }
/** /**

View file

@ -180,7 +180,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl
@Override @Override
public void addMemberDescription(VariableElement field, DocTree serialFieldTag, Content contentTree) { public void addMemberDescription(VariableElement field, DocTree serialFieldTag, Content contentTree) {
CommentHelper ch = utils.getCommentHelper(field); CommentHelper ch = utils.getCommentHelper(field);
List<? extends DocTree> description = ch.getDescription(configuration, serialFieldTag); List<? extends DocTree> description = ch.getDescription(serialFieldTag);
if (!description.isEmpty()) { if (!description.isEmpty()) {
Content serialFieldContent = new RawHtml(ch.getText(description)); Content serialFieldContent = new RawHtml(ch.getText(description));
Content div = HtmlTree.DIV(HtmlStyle.block, serialFieldContent); Content div = HtmlTree.DIV(HtmlStyle.block, serialFieldContent);

View file

@ -375,16 +375,16 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW
}); });
// Generate the map of all services listed using @provides, and the description. // Generate the map of all services listed using @provides, and the description.
(utils.getBlockTags(mdle, DocTree.Kind.PROVIDES)).forEach((tree) -> { (utils.getBlockTags(mdle, DocTree.Kind.PROVIDES)).forEach((tree) -> {
TypeElement t = ch.getServiceType(configuration, tree); TypeElement t = ch.getServiceType(tree);
if (t != null) { if (t != null) {
providesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(configuration, tree), false, true)); providesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
} }
}); });
// Generate the map of all services listed using @uses, and the description. // Generate the map of all services listed using @uses, and the description.
(utils.getBlockTags(mdle, DocTree.Kind.USES)).forEach((tree) -> { (utils.getBlockTags(mdle, DocTree.Kind.USES)).forEach((tree) -> {
TypeElement t = ch.getServiceType(configuration, tree); TypeElement t = ch.getServiceType(tree);
if (t != null) { if (t != null) {
usesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(configuration, tree), false, true)); usesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
} }
}); });
} }
@ -827,7 +827,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW
Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(mdle)); Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(mdle));
deprDiv.add(deprPhrase); deprDiv.add(deprPhrase);
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(mdle, deprs.get(0), deprDiv); addInlineDeprecatedComment(mdle, deprs.get(0), deprDiv);
} }
@ -892,7 +892,7 @@ public class ModuleWriterImpl extends HtmlDocletWriter implements ModuleSummaryW
deprDiv.add(deprPhrase); deprDiv.add(deprPhrase);
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
CommentHelper ch = utils.getCommentHelper(pkg); CommentHelper ch = utils.getCommentHelper(pkg);
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(pkg, deprs.get(0), deprDiv); addInlineDeprecatedComment(pkg, deprs.get(0), deprDiv);
} }

View file

@ -153,7 +153,7 @@ public class PackageWriterImpl extends HtmlDocletWriter
Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(packageElement)); Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(packageElement));
deprDiv.add(deprPhrase); deprDiv.add(deprPhrase);
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(packageElement, deprs.get(0), deprDiv); addInlineDeprecatedComment(packageElement, deprs.get(0), deprDiv);
} }

View file

@ -139,7 +139,7 @@ public class TagletWriterImpl extends TagletWriter {
result.add(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, result.add(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
htmlWriter.getDeprecatedPhrase(element))); htmlWriter.getDeprecatedPhrase(element)));
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); List<? extends DocTree> commentTags = ch.getDescription(deprs.get(0));
if (!commentTags.isEmpty()) { if (!commentTags.isEmpty()) {
result.add(commentTagsToOutput(null, element, commentTags, false)); result.add(commentTagsToOutput(null, element, commentTags, false));
} }
@ -150,7 +150,7 @@ public class TagletWriterImpl extends TagletWriter {
result.add(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, result.add(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
htmlWriter.getDeprecatedPhrase(element))); htmlWriter.getDeprecatedPhrase(element)));
if (!deprs.isEmpty()) { if (!deprs.isEmpty()) {
List<? extends DocTree> bodyTags = ch.getBody(configuration, deprs.get(0)); List<? extends DocTree> bodyTags = ch.getBody(deprs.get(0));
Content body = commentTagsToOutput(null, element, bodyTags, false); Content body = commentTagsToOutput(null, element, bodyTags, false);
if (!body.isEmpty()) if (!body.isEmpty())
result.add(HtmlTree.DIV(HtmlStyle.deprecationComment, body)); result.add(HtmlTree.DIV(HtmlStyle.deprecationComment, body));
@ -191,7 +191,7 @@ public class TagletWriterImpl extends TagletWriter {
Content nameTree = new StringContent(paramName); Content nameTree = new StringContent(paramName);
body.add(HtmlTree.CODE(defineID ? HtmlTree.SPAN_ID("param-" + paramName, nameTree) : nameTree)); body.add(HtmlTree.CODE(defineID ? HtmlTree.SPAN_ID("param-" + paramName, nameTree) : nameTree));
body.add(" - "); body.add(" - ");
List<? extends DocTree> description = ch.getDescription(configuration, paramTag); List<? extends DocTree> description = ch.getDescription(paramTag);
body.add(htmlWriter.commentTagsToContent(paramTag, element, description, false, inSummary)); body.add(htmlWriter.commentTagsToContent(paramTag, element, description, false, inSummary));
return HtmlTree.DD(body); return HtmlTree.DD(body);
} }
@ -215,7 +215,7 @@ public class TagletWriterImpl extends TagletWriter {
result.add(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.returnLabel, result.add(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.returnLabel,
new StringContent(resources.getText("doclet.Returns"))))); new StringContent(resources.getText("doclet.Returns")))));
result.add(HtmlTree.DD(htmlWriter.commentTagsToContent( result.add(HtmlTree.DD(htmlWriter.commentTagsToContent(
returnTag, element, ch.getDescription(configuration, returnTag), false, inSummary))); returnTag, element, ch.getDescription(returnTag), false, inSummary)));
return result; return result;
} }
@ -279,7 +279,7 @@ public class TagletWriterImpl extends TagletWriter {
if (many) { if (many) {
body.add(", "); body.add(", ");
} }
List<? extends DocTree> bodyTags = ch.getBody(configuration, simpleTag); List<? extends DocTree> bodyTags = ch.getBody(simpleTag);
body.add(htmlWriter.commentTagsToContent(simpleTag, element, bodyTags, false, inSummary)); body.add(htmlWriter.commentTagsToContent(simpleTag, element, bodyTags, false, inSummary));
many = true; many = true;
} }
@ -292,7 +292,7 @@ public class TagletWriterImpl extends TagletWriter {
ContentBuilder result = new ContentBuilder(); ContentBuilder result = new ContentBuilder();
result.add(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header)))); result.add(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header))));
CommentHelper ch = utils.getCommentHelper(element); CommentHelper ch = utils.getCommentHelper(element);
List<? extends DocTree> description = ch.getDescription(configuration, simpleTag); List<? extends DocTree> description = ch.getDescription(simpleTag);
Content body = htmlWriter.commentTagsToContent(simpleTag, element, description, false, inSummary); Content body = htmlWriter.commentTagsToContent(simpleTag, element, description, false, inSummary);
result.add(HtmlTree.DD(body)); result.add(HtmlTree.DD(body));
return result; return result;
@ -317,7 +317,7 @@ public class TagletWriterImpl extends TagletWriter {
public Content throwsTagOutput(Element element, DocTree throwsTag, TypeMirror substituteType) { public Content throwsTagOutput(Element element, DocTree throwsTag, TypeMirror substituteType) {
ContentBuilder body = new ContentBuilder(); ContentBuilder body = new ContentBuilder();
CommentHelper ch = utils.getCommentHelper(element); CommentHelper ch = utils.getCommentHelper(element);
Element exception = ch.getException(configuration, throwsTag); Element exception = ch.getException(throwsTag);
Content excName; Content excName;
if (substituteType != null) { if (substituteType != null) {
excName = htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, excName = htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
@ -333,7 +333,7 @@ public class TagletWriterImpl extends TagletWriter {
excName = htmlWriter.getLink(link); excName = htmlWriter.getLink(link);
} }
body.add(HtmlTree.CODE(excName)); body.add(HtmlTree.CODE(excName));
List<? extends DocTree> description = ch.getDescription(configuration, throwsTag); List<? extends DocTree> description = ch.getDescription(throwsTag);
Content desc = htmlWriter.commentTagsToContent(throwsTag, element, description, false, inSummary); Content desc = htmlWriter.commentTagsToContent(throwsTag, element, description, false, inSummary);
if (desc != null && !desc.isEmpty()) { if (desc != null && !desc.isEmpty()) {
body.add(" - "); body.add(" - ");

View file

@ -482,7 +482,7 @@ public class SerializedFormBuilder extends AbstractBuilder {
if (tag.getName() == null || tag.getType() == null) // ignore malformed @serialField tags if (tag.getName() == null || tag.getType() == null) // ignore malformed @serialField tags
continue; continue;
Content fieldsContentTree = fieldWriter.getFieldsContentHeader(tag.equals(tags.last())); Content fieldsContentTree = fieldWriter.getFieldsContentHeader(tag.equals(tags.last()));
TypeElement te = ch.getReferencedClass(configuration, tag); TypeElement te = ch.getReferencedClass(tag);
String fieldType = ch.getReferencedMemberName(tag); String fieldType = ch.getReferencedMemberName(tag);
if (te != null && utils.isPrimitive(te.asType())) { if (te != null && utils.isPrimitive(te.asType())) {
fieldType = utils.getTypeName(te.asType(), false); fieldType = utils.getTypeName(te.asType(), false);

View file

@ -126,7 +126,7 @@ public class ParamTaglet extends BaseTaglet implements InheritableTaglet {
if (rankMap.containsKey(paramName) && rankMap.get(paramName).equals((input.tagId))) { if (rankMap.containsKey(paramName) && rankMap.get(paramName).equals((input.tagId))) {
output.holder = input.element; output.holder = input.element;
output.holderTag = tag; output.holderTag = tag;
output.inlineTags = ch.getBody(utils.configuration, tag); output.inlineTags = ch.getBody(tag);
return; return;
} }
} }

View file

@ -64,8 +64,8 @@ public class ReturnTaglet extends BaseTaglet implements InheritableTaglet {
output.holder = input.element; output.holder = input.element;
output.holderTag = tags.get(0); output.holderTag = tags.get(0);
output.inlineTags = input.isFirstSentence output.inlineTags = input.isFirstSentence
? ch.getFirstSentenceTrees(input.utils.configuration, output.holderTag) ? ch.getFirstSentenceTrees(output.holderTag)
: ch.getDescription(input.utils.configuration, output.holderTag); : ch.getDescription(output.holderTag);
} }
} }

View file

@ -60,7 +60,7 @@ public class SeeTaglet extends BaseTaglet implements InheritableTaglet {
output.holder = input.element; output.holder = input.element;
output.holderTag = tags.get(0); output.holderTag = tags.get(0);
output.inlineTags = input.isFirstSentence output.inlineTags = input.isFirstSentence
? ch.getFirstSentenceTrees(input.utils.configuration, output.holderTag) ? ch.getFirstSentenceTrees(output.holderTag)
: ch.getReference(output.holderTag); : ch.getReference(output.holderTag);
} }
} }

View file

@ -173,8 +173,8 @@ public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
output.holderTag = tags.get(0); output.holderTag = tags.get(0);
CommentHelper ch = input.utils.getCommentHelper(output.holder); CommentHelper ch = input.utils.getCommentHelper(output.holder);
output.inlineTags = input.isFirstSentence output.inlineTags = input.isFirstSentence
? ch.getFirstSentenceTrees(input.utils.configuration, output.holderTag) ? ch.getFirstSentenceTrees(output.holderTag)
: ch.getTags(input.utils.configuration, output.holderTag); : ch.getTags(output.holderTag);
} }
} }

View file

@ -72,7 +72,7 @@ public class ThrowsTaglet extends BaseTaglet
Element exception; Element exception;
CommentHelper ch = utils.getCommentHelper(input.element); CommentHelper ch = utils.getCommentHelper(input.element);
if (input.tagId == null) { if (input.tagId == null) {
exception = ch.getException(utils.configuration, input.docTreeInfo.docTree); exception = ch.getException(input.docTreeInfo.docTree);
input.tagId = exception == null input.tagId = exception == null
? ch.getExceptionName(input.docTreeInfo.docTree).getSignature() ? ch.getExceptionName(input.docTreeInfo.docTree).getSignature()
: utils.getFullyQualifiedName(exception); : utils.getFullyQualifiedName(exception);
@ -81,12 +81,12 @@ public class ThrowsTaglet extends BaseTaglet
} }
for (DocTree dt : input.utils.getThrowsTrees(input.element)) { for (DocTree dt : input.utils.getThrowsTrees(input.element)) {
Element exc = ch.getException(utils.configuration, dt); Element exc = ch.getException(dt);
if (exc != null && (input.tagId.equals(utils.getSimpleName(exc)) || if (exc != null && (input.tagId.equals(utils.getSimpleName(exc)) ||
(input.tagId.equals(utils.getFullyQualifiedName(exc))))) { (input.tagId.equals(utils.getFullyQualifiedName(exc))))) {
output.holder = input.element; output.holder = input.element;
output.holderTag = dt; output.holderTag = dt;
output.inlineTags = ch.getBody(input.utils.configuration, output.holderTag); output.inlineTags = ch.getBody(output.holderTag);
output.tagList.add(dt); output.tagList.add(dt);
} else if (exception != null && exc != null && } else if (exception != null && exc != null &&
utils.isTypeElement(exc) && utils.isTypeElement(exception) && utils.isTypeElement(exc) && utils.isTypeElement(exception) &&
@ -193,7 +193,7 @@ public class ThrowsTaglet extends BaseTaglet
CommentHelper ch = utils.getCommentHelper(entry.getValue()); CommentHelper ch = utils.getCommentHelper(entry.getValue());
Element e = entry.getValue(); Element e = entry.getValue();
for (DocTree dt : entry.getKey()) { for (DocTree dt : entry.getKey()) {
Element te = ch.getException(utils.configuration, dt); Element te = ch.getException(dt);
String excName = ch.getExceptionName(dt).toString(); String excName = ch.getExceptionName(dt).toString();
TypeMirror substituteType = typeSubstitutions.get(excName); TypeMirror substituteType = typeSubstitutions.get(excName);
if ((!allowDuplicates) && if ((!allowDuplicates) &&

View file

@ -77,7 +77,7 @@ public class ValueTaglet extends BaseTaglet {
Element e = signature == null Element e = signature == null
? holder ? holder
: ch.getReferencedMember(config, tag); : ch.getReferencedMember(tag);
return (e != null && config.utils.isVariableElement(e)) return (e != null && config.utils.isVariableElement(e))
? (VariableElement) e ? (VariableElement) e

View file

@ -28,11 +28,10 @@ package jdk.javadoc.internal.doclets.toolkit.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement; import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
@ -84,18 +83,27 @@ import static com.sun.source.doctree.DocTree.Kind.*;
* deletion without notice.</b> * deletion without notice.</b>
*/ */
public class CommentHelper { public class CommentHelper {
private final BaseConfiguration configuration;
public final TreePath path; public final TreePath path;
public final DocCommentTree dctree; public final DocCommentTree dcTree;
public final Element element; public final Element element;
private Element overriddenElement; private Element overriddenElement;
public static final String SPACER = " "; public static final String SPACER = " ";
public CommentHelper(BaseConfiguration configuration, Element element, TreePath path, DocCommentTree dctree) { /**
//this.configuration = configuration; * Creates a utility class to encapsulate the contextual information for a doc comment tree.
*
* @param configuration the configuration
* @param element the element for which this is a doc comment
* @param path the path for the element
* @param dcTree the doc comment
*/
public CommentHelper(BaseConfiguration configuration, Element element, TreePath path, DocCommentTree dcTree) {
this.configuration = configuration;
this.element = element; this.element = element;
this.path = path; this.path = path;
this.dctree = dctree; this.dcTree = dcTree;
} }
public void setOverrideElement(Element ove) { public void setOverrideElement(Element ove) {
@ -144,17 +152,18 @@ public class CommentHelper {
} }
} }
Element getElement(BaseConfiguration c, ReferenceTree rtree) { Element getElement(ReferenceTree rtree) {
Utils utils = configuration.utils;
// likely a synthesized tree // likely a synthesized tree
if (path == null) { if (path == null) {
// NOTE: this code path only supports module/package/type signatures // NOTE: this code path only supports module/package/type signatures
// and not member signatures. For more complete support, // and not member signatures. For more complete support,
// set a suitable path and avoid this branch. // set a suitable path and avoid this branch.
TypeMirror symbol = c.utils.getSymbol(rtree.getSignature()); TypeMirror symbol = utils.getSymbol(rtree.getSignature());
if (symbol == null) { if (symbol == null) {
return null; return null;
} }
return c.docEnv.getTypeUtils().asElement(symbol); return configuration.docEnv.getTypeUtils().asElement(symbol);
} }
// case A: the element contains no comments associated and // case A: the element contains no comments associated and
// the comments need to be copied from ancestor // the comments need to be copied from ancestor
@ -162,37 +171,37 @@ public class CommentHelper {
// as appropriate has to be copied over. // as appropriate has to be copied over.
// Case A. // Case A.
if (dctree == null && overriddenElement != null) { if (dcTree == null && overriddenElement != null) {
CommentHelper ovch = c.utils.getCommentHelper(overriddenElement); CommentHelper ovch = utils.getCommentHelper(overriddenElement);
return ovch.getElement(c, rtree); return ovch.getElement(rtree);
} }
if (dctree == null) { if (dcTree == null) {
return null; return null;
} }
DocTreePath docTreePath = DocTreePath.getPath(path, dctree, rtree); DocTreePath docTreePath = DocTreePath.getPath(path, dcTree, rtree);
if (docTreePath == null) { if (docTreePath == null) {
// Case B. // Case B.
if (overriddenElement != null) { if (overriddenElement != null) {
CommentHelper ovch = c.utils.getCommentHelper(overriddenElement); CommentHelper ovch = utils.getCommentHelper(overriddenElement);
return ovch.getElement(c, rtree); return ovch.getElement(rtree);
} }
return null; return null;
} }
DocTrees doctrees = c.docEnv.getDocTrees(); DocTrees doctrees = configuration.docEnv.getDocTrees();
return doctrees.getElement(docTreePath); return doctrees.getElement(docTreePath);
} }
public Element getException(BaseConfiguration c, DocTree dtree) { public Element getException(DocTree dtree) {
if (dtree.getKind() == THROWS || dtree.getKind() == EXCEPTION) { if (dtree.getKind() == THROWS || dtree.getKind() == EXCEPTION) {
ThrowsTree tt = (ThrowsTree)dtree; ThrowsTree tt = (ThrowsTree)dtree;
ReferenceTree exceptionName = tt.getExceptionName(); ReferenceTree exceptionName = tt.getExceptionName();
return getElement(c, exceptionName); return getElement(exceptionName);
} }
return null; return null;
} }
public List<? extends DocTree> getDescription(BaseConfiguration c, DocTree dtree) { public List<? extends DocTree> getDescription(DocTree dtree) {
return getTags(c, dtree); return getTags(dtree);
} }
public String getText(List<? extends DocTree> list) { public String getText(List<? extends DocTree> list) {
@ -224,16 +233,14 @@ public class CommentHelper {
quote = "\""; quote = "\"";
break; break;
case SINGLE: case SINGLE:
quote = "\'"; quote = "'";
break; break;
default: default:
quote = ""; quote = "";
break; break;
} }
sb.append(quote); sb.append(quote);
node.getValue().stream().forEach((dt) -> { node.getValue().forEach(dt -> dt.accept(this, null));
dt.accept(this, null);
});
sb.append(quote); sb.append(quote);
return null; return null;
} }
@ -259,9 +266,7 @@ public class CommentHelper {
} }
node.getReference().accept(this, null); node.getReference().accept(this, null);
node.getLabel().stream().forEach((dt) -> { node.getLabel().forEach(dt -> dt.accept(this, null) );
dt.accept(this, null);
});
return null; return null;
} }
@ -285,17 +290,13 @@ public class CommentHelper {
@Override @Override
public Void visitSee(SeeTree node, Void p) { public Void visitSee(SeeTree node, Void p) {
node.getReference().stream().forEach((dt) -> { node.getReference().forEach(dt -> dt.accept(this, null));
dt.accept(this, null);
});
return null; return null;
} }
@Override @Override
public Void visitSerial(SerialTree node, Void p) { public Void visitSerial(SerialTree node, Void p) {
node.getDescription().stream().forEach((dt) -> { node.getDescription().forEach(dt -> dt.accept(this, null));
dt.accept(this, null);
});
return null; return null;
} }
@ -303,9 +304,7 @@ public class CommentHelper {
public Void visitStartElement(StartElementTree node, Void p) { public Void visitStartElement(StartElementTree node, Void p) {
sb.append("<"); sb.append("<");
sb.append(node.getName()); sb.append(node.getName());
node.getAttributes().stream().forEach((dt) -> { node.getAttributes().forEach(dt -> dt.accept(this, null));
dt.accept(this, null);
});
sb.append((node.isSelfClosing() ? "/>" : ">")); sb.append((node.isSelfClosing() ? "/>" : ">"));
return null; return null;
} }
@ -318,9 +317,7 @@ public class CommentHelper {
@Override @Override
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) { public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
node.getContent().stream().forEach((dt) -> { node.getContent().forEach(dt -> dt.accept(this, null));
dt.accept(this, null);
});
return null; return null;
} }
@ -338,24 +335,22 @@ public class CommentHelper {
return sb; return sb;
} }
public String getLabel(BaseConfiguration c, DocTree dtree) { public String getLabel(DocTree dtree) {
return new SimpleDocTreeVisitor<String, Void>() { return new SimpleDocTreeVisitor<String, Void>() {
@Override @Override
public String visitLink(LinkTree node, Void p) { public String visitLink(LinkTree node, Void p) {
StringBuilder sb = new StringBuilder(); return node.getLabel().stream()
node.getLabel().stream().forEach((dt) -> { .map(dt -> getText(dt))
sb.append(getText(dt)); .collect(Collectors.joining());
});
return sb.toString();
} }
@Override @Override
public String visitSee(SeeTree node, Void p) { public String visitSee(SeeTree node, Void p) {
StringBuilder sb = new StringBuilder(); Utils utils = configuration.utils;
node.getReference().stream().filter((dt) -> (c.utils.isText(dt))).forEach((dt) -> { return node.getReference().stream()
sb.append(((TextTree)dt).getBody()); .filter(utils::isText)
}); .map(dt -> ((TextTree) dt).getBody())
return sb.toString(); .collect(Collectors.joining());
} }
@Override @Override
@ -365,22 +360,24 @@ public class CommentHelper {
}.visit(dtree, null); }.visit(dtree, null);
} }
public TypeElement getReferencedClass(BaseConfiguration c, DocTree dtree) { public TypeElement getReferencedClass(DocTree dtree) {
Element e = getReferencedElement(c, dtree); Utils utils = configuration.utils;
Element e = getReferencedElement(dtree);
if (e == null) { if (e == null) {
return null; return null;
} else if (c.utils.isTypeElement(e)) { } else if (utils.isTypeElement(e)) {
return (TypeElement) e; return (TypeElement) e;
} else if (!c.utils.isPackage(e)) { } else if (!utils.isPackage(e)) {
return c.utils.getEnclosingTypeElement(e); return utils.getEnclosingTypeElement(e);
} }
return null; return null;
} }
public String getReferencedClassName(BaseConfiguration c, DocTree dtree) { public String getReferencedClassName(DocTree dtree) {
Element e = getReferencedClass(c, dtree); Utils utils = configuration.utils;
Element e = getReferencedClass(dtree);
if (e != null) { if (e != null) {
return c.utils.isTypeElement(e) ? c.utils.getSimpleName(e) : null; return utils.isTypeElement(e) ? utils.getSimpleName(e) : null;
} }
String s = getReferencedSignature(dtree); String s = getReferencedSignature(dtree);
if (s == null) { if (s == null) {
@ -390,12 +387,13 @@ public class CommentHelper {
return (n == -1) ? s : s.substring(0, n); return (n == -1) ? s : s.substring(0, n);
} }
public Element getReferencedMember(BaseConfiguration c, DocTree dtree) { public Element getReferencedMember(DocTree dtree) {
Element e = getReferencedElement(c, dtree); Utils utils = configuration.utils;
Element e = getReferencedElement(dtree);
if (e == null) { if (e == null) {
return null; return null;
} }
return (c.utils.isExecutableElement(e) || c.utils.isVariableElement(e)) ? e : null; return (utils.isExecutableElement(e) || utils.isVariableElement(e)) ? e : null;
} }
public String getReferencedMemberName(DocTree dtree) { public String getReferencedMemberName(DocTree dtree) {
@ -407,33 +405,34 @@ public class CommentHelper {
return (n == -1) ? null : s.substring(n + 1); return (n == -1) ? null : s.substring(n + 1);
} }
public String getReferencedMemberName(BaseConfiguration c, Element e) { public String getReferencedMemberName(Element e) {
if (e == null) { if (e == null) {
return null; return null;
} }
return c.utils.isExecutableElement(e) Utils utils = configuration.utils;
? c.utils.getSimpleName(e) + c.utils.makeSignature((ExecutableElement) e, true, true) return utils.isExecutableElement(e)
: c.utils.getSimpleName(e); ? utils.getSimpleName(e) + utils.makeSignature((ExecutableElement) e, true, true)
: utils.getSimpleName(e);
} }
public PackageElement getReferencedPackage(BaseConfiguration c, DocTree dtree) { public PackageElement getReferencedPackage(DocTree dtree) {
Element e = getReferencedElement(c, dtree); Element e = getReferencedElement(dtree);
if (e != null) { if (e != null) {
return c.utils.containingPackage(e); Utils utils = configuration.utils;
return utils.containingPackage(e);
} }
return null; return null;
} }
public List<? extends DocTree> getFirstSentenceTrees(BaseConfiguration c, List<? extends DocTree> body) { public List<? extends DocTree> getFirstSentenceTrees(List<? extends DocTree> body) {
List<DocTree> firstSentence = c.docEnv.getDocTrees().getFirstSentence(body); return configuration.docEnv.getDocTrees().getFirstSentence(body);
return firstSentence;
} }
public List<? extends DocTree> getFirstSentenceTrees(BaseConfiguration c, DocTree dtree) { public List<? extends DocTree> getFirstSentenceTrees(DocTree dtree) {
return getFirstSentenceTrees(c, getBody(c, dtree)); return getFirstSentenceTrees(getBody(dtree));
} }
private Element getReferencedElement(BaseConfiguration c, DocTree dtree) { private Element getReferencedElement(DocTree dtree) {
return new SimpleDocTreeVisitor<Element, Void>() { return new SimpleDocTreeVisitor<Element, Void>() {
@Override @Override
public Element visitSee(SeeTree node, Void p) { public Element visitSee(SeeTree node, Void p) {
@ -460,7 +459,7 @@ public class CommentHelper {
@Override @Override
public Element visitReference(ReferenceTree node, Void p) { public Element visitReference(ReferenceTree node, Void p) {
return getElement(c, node); return getElement(node);
} }
@Override @Override
@ -480,10 +479,11 @@ public class CommentHelper {
}.visit(dtree, null); }.visit(dtree, null);
} }
public TypeElement getServiceType(BaseConfiguration c, DocTree dtree) { public TypeElement getServiceType(DocTree dtree) {
Element e = getReferencedElement(c, dtree); Element e = getReferencedElement(dtree);
if (e != null) { if (e != null) {
return c.utils.isTypeElement(e) ? (TypeElement) e : null; Utils utils = configuration.utils;
return utils.isTypeElement(e) ? (TypeElement) e : null;
} }
return null; return null;
} }
@ -546,11 +546,11 @@ public class CommentHelper {
} }
} }
public List<? extends DocTree> getTags(BaseConfiguration c, DocTree dtree) { public List<? extends DocTree> getTags(DocTree dtree) {
return new SimpleDocTreeVisitor<List<? extends DocTree>, Void>() { return new SimpleDocTreeVisitor<List<? extends DocTree>, Void>() {
List<? extends DocTree> asList(String content) { List<? extends DocTree> asList(String content) {
List<DocTree> out = new ArrayList<>(); List<DocTree> out = new ArrayList<>();
out.add(c.cmtUtils.makeTextTree(content)); out.add(configuration.cmtUtils.makeTextTree(content));
return out; return out;
} }
@ -651,22 +651,22 @@ public class CommentHelper {
}.visit(dtree, null); }.visit(dtree, null);
} }
public List<? extends DocTree> getBody(BaseConfiguration c, DocTree dtree) { public List<? extends DocTree> getBody(DocTree dtree) {
return getTags(c, dtree); return getTags(dtree);
} }
public ReferenceTree getType(DocTree dtree) { public ReferenceTree getType(DocTree dtree) {
if (dtree.getKind() == SERIAL_FIELD) { if (dtree.getKind() == SERIAL_FIELD) {
return ((SerialFieldTree)dtree).getType(); return ((SerialFieldTree) dtree).getType();
} else { } else {
return null; return null;
} }
} }
public DocTreePath getDocTreePath(DocTree dtree) { public DocTreePath getDocTreePath(DocTree dtree) {
if (path == null || dctree == null || dtree == null) if (path == null || dcTree == null || dtree == null)
return null; return null;
return DocTreePath.getPath(path, dctree, dtree); return DocTreePath.getPath(path, dcTree, dtree);
} }
public Element getOverriddenElement() { public Element getOverriddenElement() {
@ -680,7 +680,7 @@ public class CommentHelper {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("CommentHelper{" + "path=" + path + ", dctree=" + dctree); StringBuilder sb = new StringBuilder("CommentHelper{" + "path=" + path + ", dcTree=" + dcTree);
sb.append(", element="); sb.append(", element=");
sb.append(element.getEnclosingElement()); sb.append(element.getEnclosingElement());
sb.append("::"); sb.append("::");

View file

@ -3198,7 +3198,7 @@ public class Utils {
public DocCommentTree getDocCommentTree(Element element) { public DocCommentTree getDocCommentTree(Element element) {
CommentHelper ch = commentHelperCache.get(element); CommentHelper ch = commentHelperCache.get(element);
if (ch != null) { if (ch != null) {
return ch.dctree; return ch.dcTree;
} }
DocCommentTree dcTree = getDocCommentTree0(element); DocCommentTree dcTree = getDocCommentTree0(element);
if (dcTree != null) { if (dcTree != null) {