Skip to content

Commit

Permalink
Use StringBuilder instead of StringBuffer for ASTNode.print*()
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Sep 20, 2023
1 parent bdffbf0 commit 1233925
Show file tree
Hide file tree
Showing 200 changed files with 246 additions and 246 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo f
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
if (this.type != null) { // type null for enum constant initializations
output.append("new "); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ public boolean isRuntimeVisible() {
public abstract MemberValuePair[] memberValuePairs();

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
output.append('@');
this.type.printExpression(0, output);
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
}

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

printIndent(tab, output);
printModifiers(this.modifiers, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public boolean hasNullTypeAnnotation(AnnotationPosition position) {
}

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

printIndent(indent, output);
printModifiers(this.modifiers, output);
Expand All @@ -197,7 +197,7 @@ public StringBuffer print(int indent, StringBuffer output) {
}

@Override
public StringBuffer printStatement(int indent, StringBuffer output) {
public StringBuilder printStatement(int indent, StringBuilder output) {

return print(indent, output).append(';');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolea


@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
output.append("new "); //$NON-NLS-1$
this.type.print(0, output);
for (int i = 0; i < this.dimensions.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void generateCode(TypeReference typeReference, ArrayAllocationExpression
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {

output.append('{');
if (this.expressions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected TypeBinding internalResolveType(Scope scope, int location) {
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output){
public StringBuilder printExpression(int indent, StringBuilder output){

super.printExpression(indent, output);
if ((this.bits & IsVarArgs) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
this.receiver.printExpression(0, output).append('[');
return this.position.printExpression(0, output).append(']');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected TypeBinding getTypeBinding(Scope scope) {
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output){
public StringBuilder printExpression(int indent, StringBuilder output){

super.printExpression(indent, output);
if ((this.bits & IsVarArgs) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo f
}

@Override
public StringBuffer printStatement(int tab, StringBuffer output) {
public StringBuilder printStatement(int tab, StringBuilder output) {
printIndent(tab, output);
output.append("assert "); //$NON-NLS-1$
this.assertExpression.printExpression(0, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,25 @@ public int nullStatus(FlowInfo flowInfo, FlowContext flowContext) {
}

@Override
public StringBuffer print(int indent, StringBuffer output) {
public StringBuilder print(int indent, StringBuilder output) {
//no () when used as a statement
printIndent(indent, output);
return printExpressionNoParenthesis(indent, output);
}
@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
//subclass redefine printExpressionNoParenthesis()
output.append('(');
return printExpressionNoParenthesis(0, output).append(')');
}

public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) {
public StringBuilder printExpressionNoParenthesis(int indent, StringBuilder output) {
this.lhs.printExpression(indent, output).append(" = "); //$NON-NLS-1$
return this.expression.printExpression(0, output);
}

@Override
public StringBuffer printStatement(int indent, StringBuffer output) {
public StringBuilder printStatement(int indent, StringBuilder output) {
//no () when used as a statement
return print(indent, output).append(';');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ public void optimizedBooleanConstant(int leftId, int operator, int rightId) {
}

@Override
public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) {
public StringBuilder printExpressionNoParenthesis(int indent, StringBuilder output) {
// keep implementation in sync with
// CombinedBinaryExpression#printExpressionNoParenthesis
this.left.printExpression(indent, output).append(' ').append(operatorToString()).append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public boolean isEmptyBlock() {
return this.statements == null;
}

public StringBuffer printBody(int indent, StringBuffer output) {
public StringBuilder printBody(int indent, StringBuilder output) {
if (this.statements == null) return output;
for (int i = 0; i < this.statements.length; i++) {
this.statements[i].printStatement(indent + 1, output);
Expand All @@ -109,7 +109,7 @@ public StringBuffer printBody(int indent, StringBuffer output) {
}

@Override
public StringBuffer printStatement(int indent, StringBuffer output) {
public StringBuilder printStatement(int indent, StringBuilder output) {
printIndent(indent, output);
output.append("{\n"); //$NON-NLS-1$
printBody(indent, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
}

@Override
public StringBuffer printStatement(int tab, StringBuffer output) {
public StringBuilder printStatement(int tab, StringBuilder output) {
printIndent(tab, output).append("break"); //$NON-NLS-1$
if (this.label != null) output.append(' ').append(this.label);
return output.append(';');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean containsPatternVariable() {
return false;
}
@Override
public StringBuffer printStatement(int tab, StringBuffer output) {
public StringBuilder printStatement(int tab, StringBuilder output) {
printIndent(tab, output);
if (this.constantExpressions == null) {
output.append("default "); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public Constant optimizedBooleanConstant() {
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {
int parenthesesCount = (this.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
String suffix = ""; //$NON-NLS-1$
for(int i = 0; i < parenthesesCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void generateCode(
}

@Override
public StringBuffer printExpression(int indent, StringBuffer output) {
public StringBuilder printExpression(int indent, StringBuilder output) {

return this.type.print(0, output).append(".class"); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
}

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

printIndent(tab, output).append("<clinit>()"); //$NON-NLS-1$
printBody(tab + 1, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ private void initArity(Expression expression, int value) {
}

@Override
public StringBuffer printExpressionNoParenthesis(int indent,
StringBuffer output) {
public StringBuilder printExpressionNoParenthesis(int indent,
StringBuilder output) {
// keep implementation in sync with
// BinaryExpression#printExpressionNoParenthesis and
// OperatorExpression#printExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public boolean hasErrors() {
}

@Override
public StringBuffer print(int indent, StringBuffer output) {
public StringBuilder print(int indent, StringBuilder output) {
if (this.currentPackage != null) {
printIndent(indent, output).append("package "); //$NON-NLS-1$
this.currentPackage.print(0, output, false).append(";\n"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public String operatorToString() {
}

@Override
public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) {
public StringBuilder printExpressionNoParenthesis(int indent, StringBuilder output) {

this.lhs.printExpression(indent, output).append(' ').append(operatorToString()).append(' ');
return this.expression.printExpression(0, output) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public Constant optimizedBooleanConstant() {
}

@Override
public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) {
public StringBuilder printExpressionNoParenthesis(int indent, StringBuilder output) {

this.condition.printExpression(indent, output).append(" ? "); //$NON-NLS-1$
this.valueIfTrue.printExpression(0, output).append(" : "); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
}

@Override
public StringBuffer printBody(int indent, StringBuffer output) {
public StringBuilder printBody(int indent, StringBuilder output) {
output.append(" {"); //$NON-NLS-1$
if (this.constructorCall != null) {
output.append('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
}

@Override
public StringBuffer printStatement(int tab, StringBuffer output) {
public StringBuilder printStatement(int tab, StringBuilder output) {
printIndent(tab, output).append("continue "); //$NON-NLS-1$
if (this.label != null) output.append(this.label);
return output.append(';');
Expand Down
Loading

0 comments on commit 1233925

Please sign in to comment.