8012177: HTMLDocletWriter methods should generate Content, not Strings
authorjjg
Tue, 14 May 2013 10:14:55 -0700
changeset 17568 d9691936f5f9
parent 17567 56e83a873757
child 17569 ef80738645e2
8012177: HTMLDocletWriter methods should generate Content, not Strings Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:54 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:55 2013 -0700
@@ -1390,17 +1390,17 @@
         return emd.name() + signatureParsed.toString();
     }
 
-    public String seeTagToString(SeeTag see) {
+    public Content seeTagToContent(SeeTag see) {
         String tagName = see.name();
         if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
-            return "";
+            return new ContentBuilder();
         }
 
         String seetext = replaceDocRootDir(see.text());
 
         //Check if @see is an href or "string"
         if (seetext.startsWith("<") || seetext.startsWith("\"")) {
-            return seetext;
+            return new RawHtml(seetext);
         }
 
         boolean plain = tagName.equalsIgnoreCase("@linkplain");
@@ -1421,7 +1421,7 @@
                 //@see is referencing an included package
                 if (label.isEmpty())
                     label = plainOrCode(plain, new StringContent(refPackage.name()));
-                return getPackageLink(refPackage, label).toString();
+                return getPackageLink(refPackage, label);
             } else {
                 //@see is not referencing an included class or package.  Check for cross links.
                 Content classCrossLink;
@@ -1429,16 +1429,16 @@
                 if (packageCrossLink != null) {
                     //Package cross link found
                     return getHyperLink(packageCrossLink,
-                        (label.isEmpty() ? text : label)).toString();
+                        (label.isEmpty() ? text : label));
                 } else if ((classCrossLink = getCrossClassLink(refClassName,
                         refMemName, label, false, "", !plain)) != null) {
                     //Class cross link found (possibly to a member in the class)
-                    return classCrossLink.toString();
+                    return classCrossLink;
                 } else {
                     //No cross link found so print warning
                     configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
                             tagName, seetext);
-                    return (label.isEmpty() ? text: label).toString();
+                    return (label.isEmpty() ? text: label);
                 }
             }
         } else if (refMemName == null) {
@@ -1447,11 +1447,11 @@
                 label = plainOrCode(plain, new StringContent(refClass.name()));
             }
             return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass)
-                    .label(label)).toString();
+                    .label(label));
         } else if (refMem == 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.
-            return (label.isEmpty() ? text: label).toString();
+            return (label.isEmpty() ? text: label);
         } else {
             // 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.
@@ -1487,14 +1487,10 @@
             text = plainOrCode(plain, new StringContent(refMemName));
 
             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) {
         return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
     }
@@ -1586,7 +1582,7 @@
             return;
         }
         Content div;
-        Content result = new RawHtml(commentTagsToString(holderTag, doc, tags, first));
+        Content result = commentTagsToContent(null, doc, tags, first);
         if (depr) {
             Content italic = HtmlTree.I(result);
             div = HtmlTree.DIV(HtmlStyle.block, italic);
@@ -1613,9 +1609,9 @@
      *               present in the text of interest for this doc
      * @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) {
-        StringBuilder result = new StringBuilder();
+        ContentBuilder result = new ContentBuilder();
         boolean textTagChange = false;
         // Array of all possible inline tags for this javadoc run
         configuration.tagletManager.checkTags(doc, tags, true);
@@ -1623,14 +1619,15 @@
             Tag tagelem = tags[i];
             String tagName = tagelem.name();
             if (tagelem instanceof SeeTag) {
-                result.append(seeTagToString((SeeTag)tagelem));
+                result.addContent(seeTagToContent((SeeTag) tagelem));
             } else if (! tagName.equals("Text")) {
-                int originalLength = result.length();
+                boolean wasEmpty = result.isEmpty();
                 TagletOutput output = TagletWriter.getInlineTagOuput(
                     configuration.tagletManager, holderTag,
                     tagelem, getTagletWriterInstance(isFirstSentence));
-                result.append(output == null ? "" : output.toString());
-                if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
+                if (output != null)
+                    result.addContent(((TagletOutputImpl) output).getContent());
+                if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
                     break;
                 } else if (configuration.docrootparent.length() > 0 &&
                         tagelem.name().equals("@docRoot") &&
@@ -1669,10 +1666,10 @@
                     Util.replaceTabs(configuration, line);
                     textBuff.append(line.toString());
                 }
-                result.append(textBuff);
+                result.addContent(new RawHtml(textBuff.toString()));
             }
         }
-        return result.toString();
+        return result;
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue May 14 10:14:54 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue May 14 10:14:55 2013 -0700
@@ -171,7 +171,7 @@
         ContentBuilder body = new ContentBuilder();
         body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
         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);
         return new TagletOutputImpl(result);
     }
@@ -183,8 +183,8 @@
         ContentBuilder result = new ContentBuilder();
         result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
                 new StringContent(configuration.getText("doclet.Returns")))));
-        result.addContent(HtmlTree.DD(new RawHtml(htmlWriter.commentTagsToString(
-                returnTag, null, returnTag.inlineTags(), false))));
+        result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent(
+                returnTag, null, returnTag.inlineTags(), false)));
         return new TagletOutputImpl(result);
     }
 
@@ -196,7 +196,7 @@
         if (seeTags.length > 0) {
             for (int i = 0; i < seeTags.length; ++i) {
                 appendSeparatorIfNotEmpty(body);
-                body.addContent(new RawHtml(htmlWriter.seeTagToString(seeTags[i])));
+                body.addContent(htmlWriter.seeTagToContent(seeTags[i]));
             }
         }
         if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
@@ -251,8 +251,8 @@
             if (i > 0) {
                 body.addContent(", ");
             }
-            body.addContent(new RawHtml(htmlWriter.commentTagsToString(
-                    simpleTags[i], null, simpleTags[i].inlineTags(), false)));
+            body.addContent(htmlWriter.commentTagsToContent(
+                    simpleTags[i], null, simpleTags[i].inlineTags(), false));
         }
         result.addContent(HtmlTree.DD(body));
         return new TagletOutputImpl(result);
@@ -264,8 +264,8 @@
     public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
         ContentBuilder result = new ContentBuilder();
         result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
-        Content body = new RawHtml(htmlWriter.commentTagsToString(
-                simpleTag, null, simpleTag.inlineTags(), false));
+        Content body = htmlWriter.commentTagsToContent(
+                simpleTag, null, simpleTag.inlineTags(), false);
         result.addContent(HtmlTree.DD(body));
         return new TagletOutputImpl(result);
     }
@@ -289,11 +289,11 @@
                 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
                 throwsTag.exceptionType()));
         body.addContent(HtmlTree.CODE(excName));
-        String desc = htmlWriter.commentTagsToString(throwsTag, null,
+        Content desc = htmlWriter.commentTagsToContent(throwsTag, null,
             throwsTag.inlineTags(), false);
         if (desc != null && !desc.isEmpty()) {
             body.addContent(" - ");
-            body.addContent(new RawHtml(desc));
+            body.addContent(desc);
         }
         HtmlTree res2 = HtmlTree.DD(body);
         return new TagletOutputImpl(res2);
@@ -337,8 +337,8 @@
      */
     public TagletOutputImpl commentTagsToOutput(Tag holderTag,
         Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
-        return new TagletOutputImpl(new RawHtml(htmlWriter.commentTagsToString(
-            holderTag, holderDoc, tags, isFirstSentence)));
+        return new TagletOutputImpl(htmlWriter.commentTagsToContent(
+            holderTag, holderDoc, tags, isFirstSentence));
     }
 
     /**