提交 597fdee4 编写于 作者: J jjg

8000666: javadoc should write directly to Writer instead of composing strings

Reviewed-by: bpatel
上级 94dac8ff
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
package com.sun.tools.doclets.formats.html; package com.sun.tools.doclets.formats.html;
import java.io.IOException;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.formats.html.markup.*;
import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.*;
...@@ -193,7 +195,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter ...@@ -193,7 +195,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void printDocument(Content contentTree) { public void printDocument(Content contentTree) throws IOException {
printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType), printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
true, contentTree); true, contentTree);
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.tools.doclets.formats.html; package com.sun.tools.doclets.formats.html;
import java.io.IOException;
import java.util.*; import java.util.*;
import com.sun.javadoc.*; import com.sun.javadoc.*;
...@@ -202,7 +203,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter ...@@ -202,7 +203,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void printDocument(Content contentTree) { public void printDocument(Content contentTree) throws IOException {
printHtmlDocument(configuration.metakeywords.getMetaKeywords(classDoc), printHtmlDocument(configuration.metakeywords.getMetaKeywords(classDoc),
true, contentTree); true, contentTree);
} }
......
...@@ -303,7 +303,7 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter ...@@ -303,7 +303,7 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void printDocument(Content contentTree) { public void printDocument(Content contentTree) throws IOException {
printHtmlDocument(null, true, contentTree); printHtmlDocument(null, true, contentTree);
} }
} }
...@@ -95,7 +95,7 @@ public class FrameOutputWriter extends HtmlDocletWriter { ...@@ -95,7 +95,7 @@ public class FrameOutputWriter extends HtmlDocletWriter {
* Generate the contants in the "index.html" file. Print the frame details * Generate the contants in the "index.html" file. Print the frame details
* as well as warning if browser is not supporting the Html frames. * as well as warning if browser is not supporting the Html frames.
*/ */
protected void generateFrameFile() { protected void generateFrameFile() throws IOException {
Content frameset = getFrameDetails(); Content frameset = getFrameDetails();
if (configuration.windowtitle.length() > 0) { if (configuration.windowtitle.length() > 0) {
printFramesetDocument(configuration.windowtitle, configuration.notimestamp, printFramesetDocument(configuration.windowtitle, configuration.notimestamp,
......
...@@ -79,7 +79,7 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -79,7 +79,7 @@ public class HelpWriter extends HtmlDocletWriter {
/** /**
* Generate the help file contents. * Generate the help file contents.
*/ */
protected void generateHelpFile() { protected void generateHelpFile() throws IOException {
String title = configuration.getText("doclet.Window_Help_title"); String title = configuration.getText("doclet.Window_Help_title");
Content body = getBody(true, getWindowTitle(title)); Content body = getBody(true, getWindowTitle(title));
addTop(body); addTop(body);
......
...@@ -361,7 +361,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -361,7 +361,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @param body the body htmltree to be included in the document * @param body the body htmltree to be included in the document
*/ */
public void printHtmlDocument(String[] metakeywords, boolean includeScript, public void printHtmlDocument(String[] metakeywords, boolean includeScript,
Content body) { Content body) throws IOException {
Content htmlDocType = DocType.Transitional(); Content htmlDocType = DocType.Transitional();
Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
Content head = new HtmlTree(HtmlTag.HEAD); Content head = new HtmlTree(HtmlTag.HEAD);
...@@ -391,7 +391,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -391,7 +391,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
head, body); head, body);
Content htmlDocument = new HtmlDocument(htmlDocType, Content htmlDocument = new HtmlDocument(htmlDocType,
htmlComment, htmlTree); htmlComment, htmlTree);
print(htmlDocument.toString()); htmlDocument.write(this, true);
} }
/** /**
......
...@@ -254,7 +254,7 @@ public class PackageWriterImpl extends HtmlDocletWriter ...@@ -254,7 +254,7 @@ public class PackageWriterImpl extends HtmlDocletWriter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void printDocument(Content contentTree) { public void printDocument(Content contentTree) throws IOException {
printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc), printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
true, contentTree); true, contentTree);
} }
......
...@@ -42,7 +42,7 @@ import com.sun.tools.doclets.internal.toolkit.util.DocletAbortException; ...@@ -42,7 +42,7 @@ import com.sun.tools.doclets.internal.toolkit.util.DocletAbortException;
* @author Atul M Dambalkar * @author Atul M Dambalkar
*/ */
public class SerializedFormWriterImpl extends SubWriterHolderWriter public class SerializedFormWriterImpl extends SubWriterHolderWriter
implements com.sun.tools.doclets.internal.toolkit.SerializedFormWriter { implements SerializedFormWriter {
private static final String FILE_NAME = "serialized-form.html"; private static final String FILE_NAME = "serialized-form.html";
...@@ -214,7 +214,7 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter ...@@ -214,7 +214,7 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void printDocument(Content serializedTree) { public void printDocument(Content serializedTree) throws IOException {
printHtmlDocument(null, true, serializedTree); printHtmlDocument(null, true, serializedTree);
} }
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -38,7 +41,7 @@ import com.sun.tools.doclets.internal.toolkit.util.*; ...@@ -38,7 +41,7 @@ import com.sun.tools.doclets.internal.toolkit.util.*;
* *
* @author Bhavesh Patel * @author Bhavesh Patel
*/ */
public class Comment extends Content{ public class Comment extends Content {
private String commentText; private String commentText;
...@@ -85,11 +88,13 @@ public class Comment extends Content{ ...@@ -85,11 +88,13 @@ public class Comment extends Content{
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { @Override
if (!endsWithNewLine(contentBuilder)) public boolean write(Writer out, boolean atNewline) throws IOException {
contentBuilder.append(DocletConstants.NL); if (!atNewline)
contentBuilder.append("<!-- "); out.write(DocletConstants.NL);
contentBuilder.append(commentText); out.write("<!-- ");
contentBuilder.append(" -->" + DocletConstants.NL); out.write(commentText);
out.write(" -->" + DocletConstants.NL);
return true;
} }
} }
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -112,7 +115,9 @@ public class DocType extends Content{ ...@@ -112,7 +115,9 @@ public class DocType extends Content{
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { @Override
contentBuilder.append(docType); public boolean write(Writer out, boolean atNewline) throws IOException {
out.write(docType);
return true; // guaranteed by constructor
} }
} }
...@@ -325,7 +325,7 @@ public abstract class HtmlDocWriter extends HtmlWriter { ...@@ -325,7 +325,7 @@ public abstract class HtmlDocWriter extends HtmlWriter {
* @param frameset the frameset to be added to the HTML document * @param frameset the frameset to be added to the HTML document
*/ */
public void printFramesetDocument(String title, boolean noTimeStamp, public void printFramesetDocument(String title, boolean noTimeStamp,
Content frameset) { Content frameset) throws IOException {
Content htmlDocType = DocType.Frameset(); Content htmlDocType = DocType.Frameset();
Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
Content head = new HtmlTree(HtmlTag.HEAD); Content head = new HtmlTree(HtmlTag.HEAD);
...@@ -345,7 +345,7 @@ public abstract class HtmlDocWriter extends HtmlWriter { ...@@ -345,7 +345,7 @@ public abstract class HtmlDocWriter extends HtmlWriter {
head, frameset); head, frameset);
Content htmlDocument = new HtmlDocument(htmlDocType, Content htmlDocument = new HtmlDocument(htmlDocType,
htmlComment, htmlTree); htmlComment, htmlTree);
print(htmlDocument.toString()); htmlDocument.write(this, true);
} }
/** /**
......
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import java.util.*; import java.util.*;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -74,7 +77,7 @@ public class HtmlDocument extends Content { ...@@ -74,7 +77,7 @@ public class HtmlDocument extends Content {
* *
* @param htmlContent html content to be added * @param htmlContent html content to be added
*/ */
public void addContent(Content htmlContent) { public final void addContent(Content htmlContent) {
if (htmlContent.isValid()) if (htmlContent.isValid())
docContent.add(htmlContent); docContent.add(htmlContent);
} }
...@@ -101,8 +104,9 @@ public class HtmlDocument extends Content { ...@@ -101,8 +104,9 @@ public class HtmlDocument extends Content {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { public boolean write(Writer out, boolean atNewline) throws IOException {
for (Content c : docContent) for (Content c : docContent)
c.write(contentBuilder); atNewline = c.write(out, atNewline);
return atNewline;
} }
} }
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import java.util.*; import java.util.*;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -756,35 +759,41 @@ public class HtmlTree extends Content { ...@@ -756,35 +759,41 @@ public class HtmlTree extends Content {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { @Override
if (!isInline() && !endsWithNewLine(contentBuilder)) public boolean write(Writer out, boolean atNewline) throws IOException {
contentBuilder.append(DocletConstants.NL); if (!isInline() && !atNewline)
out.write(DocletConstants.NL);
String tagString = htmlTag.toString(); String tagString = htmlTag.toString();
contentBuilder.append("<"); out.write("<");
contentBuilder.append(tagString); out.write(tagString);
Iterator<HtmlAttr> iterator = attrs.keySet().iterator(); Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
HtmlAttr key; HtmlAttr key;
String value = ""; String value = "";
while (iterator.hasNext()) { while (iterator.hasNext()) {
key = iterator.next(); key = iterator.next();
value = attrs.get(key); value = attrs.get(key);
contentBuilder.append(" "); out.write(" ");
contentBuilder.append(key.toString()); out.write(key.toString());
if (!value.isEmpty()) { if (!value.isEmpty()) {
contentBuilder.append("=\""); out.write("=\"");
contentBuilder.append(value); out.write(value);
contentBuilder.append("\""); out.write("\"");
} }
} }
contentBuilder.append(">"); out.write(">");
boolean nl = false;
for (Content c : content) for (Content c : content)
c.write(contentBuilder); nl = c.write(out, nl);
if (htmlTag.endTagRequired()) { if (htmlTag.endTagRequired()) {
contentBuilder.append("</"); out.write("</");
contentBuilder.append(tagString); out.write(tagString);
contentBuilder.append(">"); out.write(">");
}
if (!isInline()) {
out.write(DocletConstants.NL);
return true;
} else {
return false;
} }
if (!isInline())
contentBuilder.append(DocletConstants.NL);
} }
} }
...@@ -266,7 +266,7 @@ public class HtmlWriter extends PrintWriter { ...@@ -266,7 +266,7 @@ public class HtmlWriter extends PrintWriter {
} }
/** /**
* Print the script code to be embeded before the &lt;/HEAD&gt; tag. * Print the script code to be embedded before the &lt;/HEAD&gt; tag.
*/ */
protected void printWinTitleScript(String winTitle){ protected void printWinTitleScript(String winTitle){
if(winTitle != null && winTitle.length() > 0) { if(winTitle != null && winTitle.length() > 0) {
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -87,7 +90,16 @@ public class RawHtml extends Content{ ...@@ -87,7 +90,16 @@ public class RawHtml extends Content{
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { public String toString() {
contentBuilder.append(rawHtmlContent); return rawHtmlContent;
}
/**
* {@inheritDoc}
*/
@Override
public boolean write(Writer out, boolean atNewline) throws IOException {
out.write(rawHtmlContent);
return rawHtmlContent.endsWith(DocletConstants.NL);
} }
} }
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
package com.sun.tools.doclets.formats.html.markup; package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException;
import java.io.Writer;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -98,7 +101,10 @@ public class StringContent extends Content{ ...@@ -98,7 +101,10 @@ public class StringContent extends Content{
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void write(StringBuilder contentBuilder) { @Override
contentBuilder.append(stringContent); public boolean write(Writer out, boolean atNewline) throws IOException {
String s = stringContent.toString();
out.write(s);
return s.endsWith(DocletConstants.NL);
} }
} }
...@@ -153,7 +153,7 @@ public interface AnnotationTypeWriter { ...@@ -153,7 +153,7 @@ public interface AnnotationTypeWriter {
* *
* @param contentTree content tree that will be printed as a document * @param contentTree content tree that will be printed as a document
*/ */
public void printDocument(Content contentTree); public void printDocument(Content contentTree) throws IOException ;
/** /**
* Close the writer. * Close the writer.
......
...@@ -180,7 +180,7 @@ public interface ClassWriter { ...@@ -180,7 +180,7 @@ public interface ClassWriter {
* *
* @param contentTree content tree that will be printed as a document * @param contentTree content tree that will be printed as a document
*/ */
public void printDocument(Content contentTree); public void printDocument(Content contentTree) throws IOException;
/** /**
* Close the writer. * Close the writer.
......
...@@ -139,6 +139,6 @@ public interface ConstantsSummaryWriter { ...@@ -139,6 +139,6 @@ public interface ConstantsSummaryWriter {
* *
* @param contentTree content tree which should be printed * @param contentTree content tree which should be printed
*/ */
public abstract void printDocument(Content contentTree); public abstract void printDocument(Content contentTree) throws IOException;
} }
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
package com.sun.tools.doclets.internal.toolkit; package com.sun.tools.doclets.internal.toolkit;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
/** /**
...@@ -44,10 +48,16 @@ public abstract class Content { ...@@ -44,10 +48,16 @@ public abstract class Content {
* *
* @return string representation of the content * @return string representation of the content
*/ */
@Override
public String toString() { public String toString() {
StringBuilder contentBuilder = new StringBuilder(); StringWriter out = new StringWriter();
write(contentBuilder); try {
return contentBuilder.toString(); write(out, true);
} catch (IOException e) {
// cannot happen from StringWriter
throw new DocletAbortException();
}
return out.toString();
} }
/** /**
...@@ -65,10 +75,10 @@ public abstract class Content { ...@@ -65,10 +75,10 @@ public abstract class Content {
public abstract void addContent(String stringContent); public abstract void addContent(String stringContent);
/** /**
* Writes content to a StringBuilder. * Writes content to a writer.
* *
*/ */
public abstract void write(StringBuilder contentBuilder); public abstract boolean write(Writer writer, boolean atNewline) throws IOException ;
/** /**
* Returns true if the content is empty. * Returns true if the content is empty.
......
...@@ -115,7 +115,7 @@ public interface PackageSummaryWriter { ...@@ -115,7 +115,7 @@ public interface PackageSummaryWriter {
* *
* @param contentTree the content tree that will be printed * @param contentTree the content tree that will be printed
*/ */
public abstract void printDocument(Content contentTree); public abstract void printDocument(Content contentTree) throws IOException;
/** /**
* Close the writer. * Close the writer.
......
...@@ -151,7 +151,7 @@ public interface SerializedFormWriter { ...@@ -151,7 +151,7 @@ public interface SerializedFormWriter {
* *
* @param serializedTree the content tree that will be printed * @param serializedTree the content tree that will be printed
*/ */
public abstract void printDocument(Content serializedTree); public abstract void printDocument(Content serializedTree) throws IOException;
/** /**
* Write the serialized form for a given field. * Write the serialized form for a given field.
......
...@@ -650,9 +650,9 @@ public class Util { ...@@ -650,9 +650,9 @@ public class Util {
fos = new FileOutputStream(filename); fos = new FileOutputStream(filename);
} }
if (docencoding == null) { if (docencoding == null) {
return new OutputStreamWriter(fos); return new BufferedWriter(new OutputStreamWriter(fos));
} else { } else {
return new OutputStreamWriter(fos, docencoding); return new BufferedWriter(new OutputStreamWriter(fos, docencoding));
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册