8012177: HTMLDocletWriter methods should generate Content, not Strings

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2013-05-14 10:14:55 -07:00
parent 1631e19242
commit 37eaa21584
2 changed files with 32 additions and 35 deletions

View File

@ -1390,17 +1390,17 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return emd.name() + signatureParsed.toString(); return emd.name() + signatureParsed.toString();
} }
public String seeTagToString(SeeTag see) { public Content seeTagToContent(SeeTag see) {
String tagName = see.name(); String tagName = see.name();
if (! (tagName.startsWith("@link") || tagName.equals("@see"))) { if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
return ""; return new ContentBuilder();
} }
String seetext = replaceDocRootDir(see.text()); String seetext = replaceDocRootDir(see.text());
//Check if @see is an href or "string" //Check if @see is an href or "string"
if (seetext.startsWith("<") || seetext.startsWith("\"")) { if (seetext.startsWith("<") || seetext.startsWith("\"")) {
return seetext; return new RawHtml(seetext);
} }
boolean plain = tagName.equalsIgnoreCase("@linkplain"); boolean plain = tagName.equalsIgnoreCase("@linkplain");
@ -1421,7 +1421,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
//@see is referencing an included package //@see is referencing an included package
if (label.isEmpty()) if (label.isEmpty())
label = plainOrCode(plain, new StringContent(refPackage.name())); label = plainOrCode(plain, new StringContent(refPackage.name()));
return getPackageLink(refPackage, label).toString(); return getPackageLink(refPackage, label);
} else { } else {
//@see is not referencing an included class or package. Check for cross links. //@see is not referencing an included class or package. Check for cross links.
Content classCrossLink; Content classCrossLink;
@ -1429,16 +1429,16 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (packageCrossLink != null) { if (packageCrossLink != null) {
//Package cross link found //Package cross link found
return getHyperLink(packageCrossLink, return getHyperLink(packageCrossLink,
(label.isEmpty() ? text : label)).toString(); (label.isEmpty() ? text : label));
} else if ((classCrossLink = getCrossClassLink(refClassName, } else if ((classCrossLink = getCrossClassLink(refClassName,
refMemName, label, false, "", !plain)) != null) { refMemName, label, false, "", !plain)) != null) {
//Class cross link found (possibly to a member in the class) //Class cross link found (possibly to a member in the class)
return classCrossLink.toString(); return classCrossLink;
} else { } else {
//No cross link found so print warning //No cross link found so print warning
configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found", configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
tagName, seetext); tagName, seetext);
return (label.isEmpty() ? text: label).toString(); return (label.isEmpty() ? text: label);
} }
} }
} else if (refMemName == null) { } else if (refMemName == null) {
@ -1447,11 +1447,11 @@ public class HtmlDocletWriter extends HtmlDocWriter {
label = plainOrCode(plain, new StringContent(refClass.name())); label = plainOrCode(plain, new StringContent(refClass.name()));
} }
return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass) return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass)
.label(label)).toString(); .label(label));
} else if (refMem == null) { } else if (refMem == null) {
// Must be a member reference since refClass is not null and refMemName is not null. // Must be a member reference since refClass is not null and refMemName is not null.
// However, refMem is null, so this referenced member does not exist. // However, refMem is null, so this referenced member does not exist.
return (label.isEmpty() ? text: label).toString(); return (label.isEmpty() ? text: label);
} else { } else {
// Must be a member reference since refClass is not null and refMemName is not null. // Must be a member reference since refClass is not null and refMemName is not null.
// refMem is not null, so this @see tag must be referencing a valid member. // refMem is not null, so this @see tag must be referencing a valid member.
@ -1487,14 +1487,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
text = plainOrCode(plain, new StringContent(refMemName)); text = plainOrCode(plain, new StringContent(refMemName));
return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing, return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing,
refMem, (label.isEmpty() ? text: label).toString(), false).toString(); refMem, (label.isEmpty() ? text: label).toString(), false);
} }
} }
private String plainOrCodeText(boolean plain, String text) {
return (plain || text.isEmpty()) ? text : codeText(text);
}
private Content plainOrCode(boolean plain, Content body) { private Content plainOrCode(boolean plain, Content body) {
return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body); return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
} }
@ -1586,7 +1582,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return; return;
} }
Content div; Content div;
Content result = new RawHtml(commentTagsToString(holderTag, doc, tags, first)); Content result = commentTagsToContent(null, doc, tags, first);
if (depr) { if (depr) {
Content italic = HtmlTree.I(result); Content italic = HtmlTree.I(result);
div = HtmlTree.DIV(HtmlStyle.block, italic); div = HtmlTree.DIV(HtmlStyle.block, italic);
@ -1613,9 +1609,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* present in the text of interest for this doc * present in the text of interest for this doc
* @param isFirstSentence true if text is first sentence * @param isFirstSentence true if text is first sentence
*/ */
public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags, public Content commentTagsToContent(Tag holderTag, Doc doc, Tag[] tags,
boolean isFirstSentence) { boolean isFirstSentence) {
StringBuilder result = new StringBuilder(); ContentBuilder result = new ContentBuilder();
boolean textTagChange = false; boolean textTagChange = false;
// Array of all possible inline tags for this javadoc run // Array of all possible inline tags for this javadoc run
configuration.tagletManager.checkTags(doc, tags, true); configuration.tagletManager.checkTags(doc, tags, true);
@ -1623,14 +1619,15 @@ public class HtmlDocletWriter extends HtmlDocWriter {
Tag tagelem = tags[i]; Tag tagelem = tags[i];
String tagName = tagelem.name(); String tagName = tagelem.name();
if (tagelem instanceof SeeTag) { if (tagelem instanceof SeeTag) {
result.append(seeTagToString((SeeTag)tagelem)); result.addContent(seeTagToContent((SeeTag) tagelem));
} else if (! tagName.equals("Text")) { } else if (! tagName.equals("Text")) {
int originalLength = result.length(); boolean wasEmpty = result.isEmpty();
TagletOutput output = TagletWriter.getInlineTagOuput( TagletOutput output = TagletWriter.getInlineTagOuput(
configuration.tagletManager, holderTag, configuration.tagletManager, holderTag,
tagelem, getTagletWriterInstance(isFirstSentence)); tagelem, getTagletWriterInstance(isFirstSentence));
result.append(output == null ? "" : output.toString()); if (output != null)
if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) { result.addContent(((TagletOutputImpl) output).getContent());
if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
break; break;
} else if (configuration.docrootparent.length() > 0 && } else if (configuration.docrootparent.length() > 0 &&
tagelem.name().equals("@docRoot") && tagelem.name().equals("@docRoot") &&
@ -1669,10 +1666,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
Util.replaceTabs(configuration, line); Util.replaceTabs(configuration, line);
textBuff.append(line.toString()); textBuff.append(line.toString());
} }
result.append(textBuff); result.addContent(new RawHtml(textBuff.toString()));
} }
} }
return result.toString(); return result;
} }
/** /**

View File

@ -171,7 +171,7 @@ public class TagletWriterImpl extends TagletWriter {
ContentBuilder body = new ContentBuilder(); ContentBuilder body = new ContentBuilder();
body.addContent(HtmlTree.CODE(new RawHtml(paramName))); body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
body.addContent(" - "); body.addContent(" - ");
body.addContent(new RawHtml(htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false))); body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false));
HtmlTree result = HtmlTree.DD(body); HtmlTree result = HtmlTree.DD(body);
return new TagletOutputImpl(result); return new TagletOutputImpl(result);
} }
@ -183,8 +183,8 @@ public class TagletWriterImpl extends TagletWriter {
ContentBuilder result = new ContentBuilder(); ContentBuilder result = new ContentBuilder();
result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
new StringContent(configuration.getText("doclet.Returns"))))); new StringContent(configuration.getText("doclet.Returns")))));
result.addContent(HtmlTree.DD(new RawHtml(htmlWriter.commentTagsToString( result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent(
returnTag, null, returnTag.inlineTags(), false)))); returnTag, null, returnTag.inlineTags(), false)));
return new TagletOutputImpl(result); return new TagletOutputImpl(result);
} }
@ -196,7 +196,7 @@ public class TagletWriterImpl extends TagletWriter {
if (seeTags.length > 0) { if (seeTags.length > 0) {
for (int i = 0; i < seeTags.length; ++i) { for (int i = 0; i < seeTags.length; ++i) {
appendSeparatorIfNotEmpty(body); appendSeparatorIfNotEmpty(body);
body.addContent(new RawHtml(htmlWriter.seeTagToString(seeTags[i]))); body.addContent(htmlWriter.seeTagToContent(seeTags[i]));
} }
} }
if (holder.isField() && ((FieldDoc)holder).constantValue() != null && if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
@ -251,8 +251,8 @@ public class TagletWriterImpl extends TagletWriter {
if (i > 0) { if (i > 0) {
body.addContent(", "); body.addContent(", ");
} }
body.addContent(new RawHtml(htmlWriter.commentTagsToString( body.addContent(htmlWriter.commentTagsToContent(
simpleTags[i], null, simpleTags[i].inlineTags(), false))); simpleTags[i], null, simpleTags[i].inlineTags(), false));
} }
result.addContent(HtmlTree.DD(body)); result.addContent(HtmlTree.DD(body));
return new TagletOutputImpl(result); return new TagletOutputImpl(result);
@ -264,8 +264,8 @@ public class TagletWriterImpl extends TagletWriter {
public TagletOutput simpleTagOutput(Tag simpleTag, String header) { public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
ContentBuilder result = new ContentBuilder(); ContentBuilder result = new ContentBuilder();
result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header)))); result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
Content body = new RawHtml(htmlWriter.commentTagsToString( Content body = htmlWriter.commentTagsToContent(
simpleTag, null, simpleTag.inlineTags(), false)); simpleTag, null, simpleTag.inlineTags(), false);
result.addContent(HtmlTree.DD(body)); result.addContent(HtmlTree.DD(body));
return new TagletOutputImpl(result); return new TagletOutputImpl(result);
} }
@ -289,11 +289,11 @@ public class TagletWriterImpl extends TagletWriter {
htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
throwsTag.exceptionType())); throwsTag.exceptionType()));
body.addContent(HtmlTree.CODE(excName)); body.addContent(HtmlTree.CODE(excName));
String desc = htmlWriter.commentTagsToString(throwsTag, null, Content desc = htmlWriter.commentTagsToContent(throwsTag, null,
throwsTag.inlineTags(), false); throwsTag.inlineTags(), false);
if (desc != null && !desc.isEmpty()) { if (desc != null && !desc.isEmpty()) {
body.addContent(" - "); body.addContent(" - ");
body.addContent(new RawHtml(desc)); body.addContent(desc);
} }
HtmlTree res2 = HtmlTree.DD(body); HtmlTree res2 = HtmlTree.DD(body);
return new TagletOutputImpl(res2); return new TagletOutputImpl(res2);
@ -337,8 +337,8 @@ public class TagletWriterImpl extends TagletWriter {
*/ */
public TagletOutputImpl commentTagsToOutput(Tag holderTag, public TagletOutputImpl commentTagsToOutput(Tag holderTag,
Doc holderDoc, Tag[] tags, boolean isFirstSentence) { Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
return new TagletOutputImpl(new RawHtml(htmlWriter.commentTagsToString( return new TagletOutputImpl(htmlWriter.commentTagsToContent(
holderTag, holderDoc, tags, isFirstSentence))); holderTag, holderDoc, tags, isFirstSentence));
} }
/** /**