提交 e57a47d2 编写于 作者: J jjg

8000310: Clean up use of StringBuffer in langtools

Reviewed-by: bpatel
上级 a23eee2f
/*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -114,7 +114,7 @@ public class Descriptor {
private String parse(String desc, int start, int end)
throws InvalidDescriptor {
int p = start;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
int dims = 0;
count = 0;
......
......@@ -281,7 +281,7 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
* @return the 1.4.x style anchor for the ExecutableMemberDoc.
*/
protected String getErasureAnchor(ExecutableMemberDoc emd) {
StringBuffer buf = new StringBuffer(emd.name() + "(");
StringBuilder buf = new StringBuilder(emd.name() + "(");
Parameter[] params = emd.parameters();
boolean foundTypeVariable = false;
for (int i = 0; i < params.length; i++) {
......
......@@ -263,7 +263,7 @@ public abstract class AbstractMemberWriter {
if (len <= 0) {
return "";
}
StringBuffer sb = new StringBuffer(len);
StringBuilder sb = new StringBuilder(len);
for(int i = 0; i < len; i++) {
sb.append(' ');
}
......
......@@ -1567,7 +1567,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @param name File name, to which path string is.
*/
protected String pathString(PackageDoc pd, String name) {
StringBuffer buf = new StringBuffer(relativePath);
StringBuilder buf = new StringBuilder(relativePath);
buf.append(DirectoryManager.getPathToPackage(pd, name));
return buf.toString();
}
......@@ -2030,7 +2030,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
return "";
}
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
boolean isplaintext = tagName.toLowerCase().equals("@linkplain");
String label = see.label();
label = (label.length() > 0)?
......@@ -2329,7 +2329,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
text = removeNonInlineHtmlTags(text);
}
StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
StringBuffer textBuff = new StringBuffer();
StringBuilder textBuff = new StringBuilder();
while (lines.hasMoreTokens()) {
StringBuilder line = new StringBuilder(lines.nextToken());
Util.replaceTabs(configuration.sourcetab, line);
......@@ -2398,7 +2398,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
//Redirect all relative links.
int end, begin = text.toLowerCase().indexOf("<a");
if(begin >= 0){
StringBuffer textBuff = new StringBuffer(text);
StringBuilder textBuff = new StringBuilder(text);
while(begin >=0){
if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
......@@ -2688,13 +2688,13 @@ public class HtmlDocletWriter extends HtmlDocWriter {
*/
private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
List<String> results = new ArrayList<String>();
StringBuffer annotation;
StringBuilder annotation;
for (int i = 0; i < descList.length; i++) {
AnnotationTypeDoc annotationDoc = descList[i].annotationType();
if (! Util.isDocumentedAnnotation(annotationDoc)){
continue;
}
annotation = new StringBuffer();
annotation = new StringBuilder();
LinkInfoImpl linkInfo = new LinkInfoImpl(
LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc);
linkInfo.label = "@" + annotationDoc.name();
......@@ -2759,9 +2759,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
List<String> list = getAnnotations(0,
new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
false);
StringBuffer buf = new StringBuffer();
for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
buf.append(iter.next());
StringBuilder buf = new StringBuilder();
for (String s: list) {
buf.append(s);
}
return buf.toString();
} else if (annotationValue.value() instanceof MemberDoc) {
......
......@@ -71,7 +71,7 @@ public class LinkFactoryImpl extends LinkFactory {
classLinkInfo.type != null &&
!classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
"";
StringBuffer label = new StringBuffer(
StringBuilder label = new StringBuilder(
classLinkInfo.getClassLinkLabel(m_writer.configuration));
classLinkInfo.displayLength += label.length();
Configuration configuration = ConfigurationImpl.getInstance();
......@@ -167,7 +167,7 @@ public class LinkFactoryImpl extends LinkFactory {
//with 1.4.2 output.
return linkInfo.classDoc.name() + ".html";
}
StringBuffer buf = new StringBuffer(m_writer.relativePath);
StringBuilder buf = new StringBuilder(m_writer.relativePath);
buf.append(DirectoryManager.getPathToPackage(
linkInfo.classDoc.containingPackage(),
linkInfo.classDoc.name() + ".html"));
......
......@@ -43,13 +43,13 @@ public class LinkOutputImpl implements LinkOutput {
/**
* The output of the link.
*/
public StringBuffer output;
public StringBuilder output;
/**
* Construct a new LinkOutputImpl.
*/
public LinkOutputImpl() {
output = new StringBuffer();
output = new StringBuilder();
}
/**
......
......@@ -41,7 +41,7 @@ import com.sun.tools.doclets.internal.toolkit.taglets.*;
public class TagletOutputImpl implements TagletOutput {
private StringBuffer output;
private StringBuilder output;
public TagletOutputImpl(String o) {
setOutput(o);
......@@ -51,7 +51,7 @@ public class TagletOutputImpl implements TagletOutput {
* {@inheritDoc}
*/
public void setOutput (Object o) {
output = new StringBuffer(o == null ? "" : (String) o);
output = new StringBuilder(o == null ? "" : (String) o);
}
/**
......
......@@ -74,7 +74,7 @@ public class TagletWriterImpl extends TagletWriter {
* {@inheritDoc}
*/
public TagletOutput deprecatedTagOutput(Doc doc) {
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
Tag[] deprs = doc.tags("deprecated");
if (doc instanceof ClassDoc) {
if (Util.isDeprecated((ProgramElementDoc) doc)) {
......@@ -125,9 +125,9 @@ public class TagletWriterImpl extends TagletWriter {
* {@inheritDoc}
*/
public TagletOutput getParamHeader(String header) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append("<dt>");
result.append("<span class=\"strong\">" + header + "</span></dt>");
result.append("<span class=\"strong\">").append(header).append("</span></dt>");
return new TagletOutputImpl(result.toString());
}
......
......@@ -186,7 +186,7 @@ public abstract class HtmlDocWriter extends HtmlWriter {
public String getHyperLinkString(String link, String where,
String label, boolean strong,
String stylename, String title, String target) {
StringBuffer retlink = new StringBuffer();
StringBuilder retlink = new StringBuilder();
retlink.append("<a href=\"");
retlink.append(link);
if (where != null && where.length() != 0) {
......@@ -195,10 +195,10 @@ public abstract class HtmlDocWriter extends HtmlWriter {
}
retlink.append("\"");
if (title != null && title.length() != 0) {
retlink.append(" title=\"" + title + "\"");
retlink.append(" title=\"").append(title).append("\"");
}
if (target != null && target.length() != 0) {
retlink.append(" target=\"" + target + "\"");
retlink.append(" target=\"").append(target).append("\"");
}
retlink.append(">");
if (stylename != null && stylename.length() != 0) {
......
......@@ -465,7 +465,7 @@ public abstract class Configuration {
tagletManager.addNewSimpleCustomTag(tagName, null, "");
} else {
//Create a simple tag with the heading that has the same name as the tag.
StringBuffer heading = new StringBuffer(tagName + ":");
StringBuilder heading = new StringBuilder(tagName + ":");
heading.setCharAt(0, Character.toUpperCase(tagName.charAt(0)));
tagletManager.addNewSimpleCustomTag(tagName, heading.toString(), "a");
}
......
......@@ -179,7 +179,7 @@ public class AnnotationTypeBuilder extends AbstractBuilder {
* @param annotationInfoTree the content tree to which the documentation will be added
*/
public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
StringBuffer modifiers = new StringBuffer(
StringBuilder modifiers = new StringBuilder(
annotationTypeDoc.modifiers() + " ");
writer.addAnnotationTypeSignature(Util.replaceText(
modifiers.toString(), "interface", "@interface"), annotationInfoTree);
......
......@@ -282,18 +282,18 @@ public class ClassBuilder extends AbstractBuilder {
* @param classInfoTree the content tree to which the documentation will be added
*/
public void buildClassSignature(XMLNode node, Content classInfoTree) {
StringBuffer modifiers = new StringBuffer(classDoc.modifiers() + " ");
StringBuilder modifiers = new StringBuilder(classDoc.modifiers() + " ");
if (isEnum) {
modifiers.append("enum ");
int index;
if ((index = modifiers.indexOf("abstract")) >= 0) {
modifiers.delete(index, index + (new String("abstract")).length());
modifiers = new StringBuffer(
modifiers.delete(index, index + "abstract".length());
modifiers = new StringBuilder(
Util.replaceText(modifiers.toString(), " ", " "));
}
if ((index = modifiers.indexOf("final")) >= 0) {
modifiers.delete(index, index + (new String("final")).length());
modifiers = new StringBuffer(
modifiers.delete(index, index + "final".length());
modifiers = new StringBuilder(
Util.replaceText(modifiers.toString(), " ", " "));
}
//} else if (classDoc.isAnnotationType()) {
......
......@@ -84,7 +84,7 @@ public class LiteralTaglet implements Taglet {
* Replace occurrences of the following characters: < > &
*/
protected static String textToString(String text) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
switch (c) {
......
......@@ -449,7 +449,7 @@ public class TagletManager {
//This known tag is excluded.
return;
}
StringBuffer combined_locations = new StringBuffer();
StringBuilder combined_locations = new StringBuilder();
for (int i = 0; i < locations.length; i++) {
if (i > 0) {
combined_locations.append(", ");
......
/*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -119,7 +119,7 @@ public class DirectoryManager {
if (packageName == null || packageName.length() == 0) {
return "";
}
StringBuffer pathstr = new StringBuffer();
StringBuilder pathstr = new StringBuilder();
for (int i = 0; i < packageName.length(); i++) {
char ch = packageName.charAt(i);
if (ch == '.') {
......@@ -151,7 +151,7 @@ public class DirectoryManager {
if (name == null || name.length() == 0) {
return "";
}
StringBuffer pathstr = new StringBuffer();
StringBuilder pathstr = new StringBuilder();
for (int i = 0; i < name.length(); i++) {
char ch = name.charAt(i);
if (ch == '.') {
......@@ -181,7 +181,7 @@ public class DirectoryManager {
* @see #getPath(String)
*/
public static String getRelativePath(String from, String to) {
StringBuffer pathstr = new StringBuffer();
StringBuilder pathstr = new StringBuilder();
pathstr.append(getRelativePath(from));
pathstr.append(getPath(to));
pathstr.append(URL_FILE_SEPARATOR);
......@@ -222,7 +222,7 @@ public class DirectoryManager {
if (from == null || from.length() == 0) {
return "";
}
StringBuffer pathstr = new StringBuffer();
StringBuilder pathstr = new StringBuilder();
for (int i = 0; i < from.length(); i++) {
char ch = from.charAt(i);
if (ch == '.') {
......@@ -293,7 +293,7 @@ public class DirectoryManager {
* @param filename File name to be appended to the path of the package.
*/
public static String getPathToPackage(PackageDoc pd, String filename) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String pathstr = createPathString(pd);
if (pathstr.length() > 0) {
buf.append(pathstr);
......
......@@ -277,7 +277,7 @@ public class Extern {
boolean relative)
throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(input));
StringBuffer strbuf = new StringBuffer();
StringBuilder strbuf = new StringBuilder();
try {
int c;
while ((c = in.read()) >= 0) {
......
......@@ -182,7 +182,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
@Override
public String visitClassType(ClassType t, Locale locale) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
buf.append(visit(t.getEnclosingType(), locale));
buf.append(".");
......@@ -210,7 +210,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
@Override
public String visitWildcardType(WildcardType t, Locale locale) {
StringBuffer s = new StringBuffer();
StringBuilder s = new StringBuilder();
s.append(t.kind);
if (t.kind != UNBOUND) {
s.append(visit(t.type, locale));
......@@ -248,7 +248,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
protected String className(ClassType t, boolean longform, Locale locale) {
Symbol sym = t.tsym;
if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
StringBuffer s = new StringBuffer(visit(t.supertype_field, locale));
StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
s.append("&");
s.append(visit(is.head, locale));
......@@ -287,7 +287,7 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
if (!varArgs) {
return visitTypes(args, locale);
} else {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
while (args.tail.nonEmpty()) {
buf.append(visit(args.head, locale));
args = args.tail;
......
......@@ -1945,7 +1945,7 @@ public class Lower extends TreeTranslator {
* @param sig The signature of type T.
*/
private Name cacheName(String sig) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (sig.startsWith("[")) {
buf = buf.append("array");
while (sig.startsWith("[")) {
......
......@@ -806,7 +806,7 @@ public class JavacParser implements Parser {
t = odStack[0];
if (t.hasTag(JCTree.Tag.PLUS)) {
StringBuffer buf = foldStrings(t);
StringBuilder buf = foldStrings(t);
if (buf != null) {
t = toP(F.at(startPos).Literal(TypeTags.CLASS, buf.toString()));
}
......@@ -833,7 +833,7 @@ public class JavacParser implements Parser {
/** If tree is a concatenation of string literals, replace it
* by a single literal representing the concatenated string.
*/
protected StringBuffer foldStrings(JCTree tree) {
protected StringBuilder foldStrings(JCTree tree) {
if (!allowStringFolding)
return null;
List<String> buf = List.nil();
......@@ -841,8 +841,8 @@ public class JavacParser implements Parser {
if (tree.hasTag(LITERAL)) {
JCLiteral lit = (JCLiteral) tree;
if (lit.typetag == TypeTags.CLASS) {
StringBuffer sbuf =
new StringBuffer((String)lit.value);
StringBuilder sbuf =
new StringBuilder((String)lit.value);
while (buf.nonEmpty()) {
sbuf.append(buf.head);
buf = buf.tail;
......
/*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -260,7 +260,7 @@ public class Convert {
while (i < len) {
char ch = s.charAt(i);
if (ch > 255) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(s.substring(0, i));
while (i < len) {
ch = s.charAt(i);
......
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -287,7 +287,7 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
if (isEmpty()) {
return "";
} else {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(head);
for (List<A> l = tail; l.nonEmpty(); l = l.tail) {
buf.append(sep);
......
/*
* Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -287,7 +287,7 @@ public abstract class Gen {
constString = value.toString();
}
if (constString != null) {
StringBuffer s = new StringBuffer("#undef ");
StringBuilder s = new StringBuilder("#undef ");
s.append(cname); s.append("_"); s.append(fname); s.append(lineSep);
s.append("#define "); s.append(cname); s.append("_");
s.append(fname); s.append(" "); s.append(constString);
......@@ -370,7 +370,7 @@ public abstract class Gen {
// c.f. MethodDoc.signature
String signature(ExecutableElement e) {
StringBuffer sb = new StringBuffer("(");
StringBuilder sb = new StringBuilder("(");
String sep = "";
for (VariableElement p: e.getParameters()) {
sb.append(sep);
......
/*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -647,7 +647,7 @@ public class LLNI extends Gen {
%%% This may not be right, but should be called more often. */
protected final String nameToIdentifier(String name) {
int len = name.length();
StringBuffer buf = new StringBuffer(len);
StringBuilder buf = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = name.charAt(i);
if (isASCIILetterOrDigit(c))
......
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -66,7 +66,7 @@ public class Mangle {
}
public final String mangle(CharSequence name, int mtype) {
StringBuffer result = new StringBuffer(100);
StringBuilder result = new StringBuilder(100);
int length = name.length();
for (int i = 0; i < length; i++) {
......@@ -115,7 +115,7 @@ public class Mangle {
public String mangleMethod(ExecutableElement method, TypeElement clazz,
int mtype) throws TypeSignature.SignatureException {
StringBuffer result = new StringBuffer(100);
StringBuilder result = new StringBuilder(100);
result.append("Java_");
if (mtype == Mangle.Type.METHOD_JDK_1) {
......@@ -164,7 +164,7 @@ public class Mangle {
// Warning: duplicated in Gen
private String signature(ExecutableElement e) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
String sep = "(";
for (VariableElement p: e.getParameters()) {
sb.append(sep);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册