Skip to content

Commit

Permalink
Apply "Convert StringBuffer to StringBuilder" to jdt-core(-tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Oct 21, 2023
1 parent eb364b2 commit 1de7c8f
Show file tree
Hide file tree
Showing 394 changed files with 900 additions and 900 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void optionsChanged(DebugOptions options) {

public static void trace(final String msg){
if (DEBUG) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('[');
// SimpleDateFormat is not thread-safe, according to javadoc
synchronized(TRACE_DATE_FORMAT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ public String toString() {
return "null"; //$NON-NLS-1$
} else if (_value instanceof String) {
String value = (String) _value;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('"');
for (int i = 0; i < value.length(); i++) {
Util.appendEscapedChar(sb, value.charAt(i), true);
}
sb.append('"');
return sb.toString();
} else if (_value instanceof Character) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('\'');
Util.appendEscapedChar(sb, ((Character) _value).charValue(), false);
sb.append('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static Status createInfoStatus(Throwable e, String message) {

public static void trace(final String msg) {
if (DEBUG) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('[');
// SimpleDateFormat is not thread-safe, according to javadoc
synchronized (TRACE_DATE_FORMAT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public CompilerInvocationTestsArguments(
}
@Override
public String toString() {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (String option: this.options) {
result.append(option);
result.append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
DeclaredType genericType = element.asType().accept(new GenericTypeVisitor(types), null);
DeclaredType erasedType = (DeclaredType) types.erasure(genericType);

StringBuffer message = new StringBuffer();
StringBuilder message = new StringBuilder();
message.append("Erased type: " + erasedType);
message.append(" - type arguments: ");
for (TypeMirror typeArgument : erasedType.getTypeArguments()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static String xmlToString(Document model) {
public static String xmlToCutAndPasteString(Document model, int indent, boolean shift) {
String modelAsString = xmlToString(model);
int length = modelAsString.length();
StringBuffer buffer = new StringBuffer(length);
StringBuilder buffer = new StringBuilder(length);
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(modelAsString, "\n\r", true);
for (int i = 0; i < indent; i++) buffer.append("\t");
if (shift) indent++;
Expand All @@ -101,7 +101,7 @@ public static String xmlToCutAndPasteString(Document model, int indent, boolean
}
continue;
}
StringBuffer tokenBuffer = new StringBuffer();
StringBuilder tokenBuffer = new StringBuilder();
for (int i = 0; i < token.length(); i++){
char c = token.charAt(i);
switch (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg + " (Binary mode= " + isBinaryMode + ")");
}
protected String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -217,7 +217,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand All @@ -235,7 +235,7 @@ protected void verifyAnnotations(AnnotatedConstruct construct, String[] annots)
protected String getAnnotationString(AnnotationMirror annot) {
DeclaredType annotType = annot.getAnnotationType();
TypeElement type = (TypeElement) annotType.asElement();
StringBuffer buf = new StringBuffer("@" + type.getSimpleName());
StringBuilder buf = new StringBuilder("@" + type.getSimpleName());
Map<? extends ExecutableElement, ? extends AnnotationValue> values = annot.getElementValues();
Set<? extends ExecutableElement> keys = values.keySet();
buf.append('(');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
private String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -227,7 +227,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
private String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -438,7 +438,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
private String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -233,7 +233,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ private void createPackageBinary() throws IOException {
}

private String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -1147,7 +1147,7 @@ private void verifyAnnotations(AnnotatedConstruct construct, String[] annots, St
private String getAnnotationString(AnnotationMirror annot) {
DeclaredType annotType = annot.getAnnotationType();
TypeElement type = (TypeElement) annotType.asElement();
StringBuffer buf = new StringBuffer("@" + type.getSimpleName());
StringBuilder buf = new StringBuilder("@" + type.getSimpleName());
Map<? extends ExecutableElement, ? extends AnnotationValue> values = annot.getElementValues();
Set<? extends ExecutableElement> keys = values.keySet();
buf.append('(');
Expand Down Expand Up @@ -1244,7 +1244,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
protected String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down Expand Up @@ -1310,7 +1310,7 @@ static boolean equalsRegardingNull(Object expected, Object actual) {

public void assertEquals(String msg, int expected, int actual) {
if (expected != actual) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(msg);
buf.append(", expected " + expected + " but was " + actual);
reportError(buf.toString());
Expand All @@ -1333,7 +1333,7 @@ private void verifyAnnotations(AnnotatedConstruct construct, String[] annots) {
private String getAnnotationString(AnnotationMirror annot) {
DeclaredType annotType = annot.getAnnotationType();
TypeElement type = (TypeElement) annotType.asElement();
StringBuffer buf = new StringBuffer("@" + type.getQualifiedName());
StringBuilder buf = new StringBuilder("@" + type.getQualifiedName());
Map<? extends ExecutableElement, ? extends AnnotationValue> values = annot.getElementValues();
Set<? extends ExecutableElement> keys = values.keySet();
buf.append('(');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void reportError(String msg) {
throw new AssertionFailedError(msg);
}
private String getExceptionStackTrace(Throwable t) {
StringBuffer buf = new StringBuffer(t.getMessage());
StringBuilder buf = new StringBuilder(t.getMessage());
StackTraceElement[] traces = t.getStackTrace();
for (int i = 0; i < traces.length; i++) {
StackTraceElement trace = traces[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class AnnotationProcessorTests extends TestCase {

public final class DiagnosticReport<S> implements DiagnosticListener<S> {
public int count;
public StringBuffer buffer;
public StringBuilder buffer;
private final List<Diagnostic<? extends S>> warnings = new ArrayList<>();
DiagnosticReport() {
this.count = 0;
this.buffer = new StringBuffer();
this.buffer = new StringBuilder();
}
@Override
public void report(Diagnostic<? extends S> diagnostic) {
Expand All @@ -61,7 +61,7 @@ public String toString() {
}
public void clear() {
this.count = 0;
this.buffer = new StringBuffer();
this.buffer = new StringBuilder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public class BatchTestUtils {
private static File _tmpGenDir;

public static final class DiagnosticReport<S> implements DiagnosticListener<S> {
public StringBuffer buffer;
public StringBuilder buffer;
private final List<Diagnostic<? extends S>> diagnostics = new ArrayList<>();
DiagnosticReport() {
this.buffer = new StringBuffer();
this.buffer = new StringBuilder();
}
public void report(Diagnostic<? extends S> diagnostic) {
diagnostics.add(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void internalTest(JavaCompiler compiler, String processorClass, String e

List<String> options = new ArrayList<String>();
options.add("-A" + processorClass);
final StringBuffer reported = new StringBuffer();
final StringBuilder reported = new StringBuilder();
BatchTestUtils.compileTree(compiler, options, targetFolder, new DiagnosticListener () {
@Override
public void report(Diagnostic diag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static File concatPath(String... names) {

public static String convertToIndependentLineDelimiter(String source) {
if (source.indexOf('\n') == -1 && source.indexOf('\r') == -1) return source;
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (int i = 0, length = source.length(); i < length; i++) {
char car = source.charAt(i);
if (car == '\r') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static class CompilerInvocationTestsArguments {
}
@Override
public String toString() {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (String option: this.options) {
result.append(option);
result.append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ public static byte[] read(java.io.File file) throws java.io.IOException {

public static String convertToIndependentLineDelimiter(String source) {
if (source.indexOf('\n') == -1 && source.indexOf('\r') == -1) return source;
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (int i = 0, length = source.length(); i < length; i++) {
char car = source.charAt(i);
if (car == '\r') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ private static String normalized(String s) {
public static String convertToIndependantLineDelimiter(String source) {
if (source == null) return "";
if (source.indexOf('\n') == -1 && source.indexOf('\r') == -1) return source;
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (int i = 0, length = source.length(); i < length; i++) {
char car = source.charAt(i);
if (car == '\r') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ public String toString() {
return "null"; //$NON-NLS-1$
} else if (this._value instanceof String) {
String value = (String) this._value;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('"');
for (int i = 0; i < value.length(); i++) {
Util.appendEscapedChar(sb, value.charAt(i), true);
}
sb.append('"');
return sb.toString();
} else if (this._value instanceof Character) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append('\'');
Util.appendEscapedChar(sb, ((Character) this._value).charValue(), false);
sb.append('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@ public boolean isType() {
return false;
}

public abstract StringBuffer print(int indent, StringBuffer output);
public abstract StringBuilder print(int indent, StringBuilder output);

public static StringBuffer printAnnotations(Annotation[] annotations, StringBuffer output) {
public static StringBuilder printAnnotations(Annotation[] annotations, StringBuilder output) {
int length = annotations.length;
for (int i = 0; i < length; i++) {
if (i > 0) {
Expand All @@ -681,13 +681,13 @@ public static StringBuffer printAnnotations(Annotation[] annotations, StringBuff
return output;
}

public static StringBuffer printIndent(int indent, StringBuffer output) {
public static StringBuilder printIndent(int indent, StringBuilder output) {

for (int i = indent; i > 0; i--) output.append(" "); //$NON-NLS-1$
return output;
}

public static StringBuffer printModifiers(int modifiers, StringBuffer output) {
public static StringBuilder printModifiers(int modifiers, StringBuilder output) {

if ((modifiers & ClassFileConstants.AccPublic) != 0)
output.append("public "); //$NON-NLS-1$
Expand Down Expand Up @@ -1497,7 +1497,7 @@ public int sourceEnd() {
@Override
public String toString() {

return print(0, new StringBuffer(30)).toString();
return print(0, new StringBuilder(30)).toString();
}

public void traverse(ASTVisitor visitor, BlockScope scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public boolean isStatic() {
public abstract void parseStatements(Parser parser, CompilationUnitDeclaration unit);

@Override
public StringBuffer print(int tab, StringBuffer output) {
public StringBuilder print(int tab, StringBuilder output) {

if (this.javadoc != null) {
this.javadoc.print(tab, output);
Expand Down Expand Up @@ -539,7 +539,7 @@ public StringBuffer print(int tab, StringBuffer output) {
return output;
}

public StringBuffer printBody(int indent, StringBuffer output) {
public StringBuilder printBody(int indent, StringBuilder output) {

if (isAbstract() || (this.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
return output.append(';');
Expand All @@ -556,7 +556,7 @@ public StringBuffer printBody(int indent, StringBuffer output) {
return output;
}

public StringBuffer printReturnType(int indent, StringBuffer output) {
public StringBuilder printReturnType(int indent, StringBuilder output) {

return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean isTypeAccess() {
}

@Override
public StringBuffer printStatement(int indent, StringBuffer output) {
public StringBuilder printStatement(int indent, StringBuilder output) {
printAsExpression(indent, output);
switch(getKind()) {
case ENUM_CONSTANT:
Expand All @@ -97,7 +97,7 @@ public StringBuffer printStatement(int indent, StringBuffer output) {
}
}

public StringBuffer printAsExpression(int indent, StringBuffer output) {
public StringBuilder printAsExpression(int indent, StringBuilder output) {
printIndent(indent, output);
printModifiers(this.modifiers, output);
if (this.annotations != null) {
Expand Down
Loading

0 comments on commit 1de7c8f

Please sign in to comment.