Skip to content

Commit

Permalink
Bug 574376 - [dogfooding][cleanup] Use new StringBuffer -> StringBuilder
Browse files Browse the repository at this point in the history
cleanup

Runs the new StringBuffer-> StringBuilder

This help to determine that it works correctly for clients we should run
it also on our own code base. This help to ensure that the cleanup works
fine and helps us to cleanup our own code base.

From the commit message of the cleanup:

- create a cleanup to replace usage of StringBuffer with
  StringBuilder.  The two are equivalent, but StringBuffer is
  thread-safe and synchronized which makes it slower than
  StringBuilder which was introduced in Java 1.5.


This uses the local variable change only.

Change-Id: Iec3f968dd879c63b3e108c31a5a6e8178b8617bf
Signed-off-by: Lars Vogel <[email protected]>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/182327
Tested-by: JDT Bot <[email protected]>
Reviewed-by: Jeff Johnston <[email protected]>
  • Loading branch information
vogella authored and jjohnstn committed Jun 29, 2021
1 parent 75d420c commit 0546fc5
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public static ChildListPropertyDescriptor getBodyDeclarationsProperty(ASTNode no
* @since 3.10
*/
public static String getTypeName(Type type) {
final StringBuffer buffer= new StringBuffer();
final StringBuilder buffer= new StringBuilder();
ASTVisitor visitor= new ASTVisitor() {
@Override
public boolean visit(PrimitiveType node) {
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public void endVisit(ArrayType node) {
* @since 3.10
*/
public static String getQualifiedTypeName(Type type) {
final StringBuffer buffer= new StringBuffer();
final StringBuilder buffer= new StringBuilder();
ASTVisitor visitor= new ASTVisitor() {
@Override
public boolean visit(SimpleType node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore
Expression rhs= oldAssignment.getRightHandSide();
// Ugly hack to tack on trailing comments
IBuffer buffer= cuRewrite.getCu().getBuffer();
StringBuffer b= new StringBuffer();
StringBuilder b= new StringBuilder();
b.append(buffer.getText(rhs.getStartPosition(), rhs.getLength()) + ";"); //$NON-NLS-1$
List<Comment> trailingComments= ASTNodes.getTrailingComments(oldExpStatement);
for (Comment comment : trailingComments) {
Expand All @@ -317,7 +317,7 @@ public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore
Assignment oldAssignment= (Assignment)oldExpStatement.getExpression();
Expression rhs= oldAssignment.getRightHandSide();
IBuffer buffer= cuRewrite.getCu().getBuffer();
StringBuffer b= new StringBuffer();
StringBuilder b= new StringBuilder();
List<Comment> leadingComments= ASTNodes.getLeadingComments(oldExpStatement);
for (Comment comment : leadingComments) {
b.append(buffer.getText(comment.getStartPosition(), comment.getLength()) + "\n"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ private void addCharacters(String string) throws SAXException {
* @since 3.6
*/
private static String escapeNonUnicodeChars(String string) {
StringBuffer buf= null;
StringBuilder buf= null;
for (int i= 0; i < string.length(); i++) {
char ch= string.charAt(i);
if (ch != 9 && ch != 10 && ch != 13 && ch < 32) {
if (buf == null) {
buf= new StringBuffer(string.substring(0, i));
buf= new StringBuilder(string.substring(0, i));
}
buf.append("\\u"); //$NON-NLS-1$
String hex= Integer.toHexString(ch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public void visitTreeEntry(ITestIdentifier identifier, boolean hasChildren, int
public static String escapeText(String s) {
if ((s.indexOf(',') < 0) && (s.indexOf('\\') < 0) && (s.indexOf('\r') < 0) && (s.indexOf('\n') < 0))
return s;
StringBuffer sb= new StringBuffer(s.length()+10);
StringBuilder sb= new StringBuilder(s.length()+10);
for (int i= 0; i < s.length(); i++) {
char c= s.charAt(i);
switch (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ private void appendTestMethodBody(StringBuffer buffer, ICompilationUnit targetCu

private void appendParameterNamesToMethodName(StringBuffer buffer, String[] parameters) {
for (String parameter : parameters) {
final StringBuffer buf= new StringBuffer(Signature.getSimpleName(Signature.toString(Signature.getElementType(parameter))));
final StringBuilder buf= new StringBuilder(Signature.getSimpleName(Signature.toString(Signature.getElementType(parameter))));
final char character= buf.charAt(0);
if (buf.length() > 0 && !Character.isUpperCase(character))
buf.setCharAt(0, Character.toUpperCase(character));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private IDocument getDocument(String name, String lineDelimiter) {

public static IDocument getRandomDocument(int size) {
final char[] characters= {'/', '*', '\'', '"', '\r', '\n', '\\'};
final StringBuffer buffer= new StringBuffer();
final StringBuilder buffer= new StringBuilder();

for (int i= 0; i < size; i++) {
final int randomIndex= (int) (Math.random() * characters.length);
Expand Down Expand Up @@ -165,7 +165,7 @@ private long getTime(IPartitionTokenScanner scanner, IDocument document, int cou

private void testConformance(final IDocument document) {

final StringBuffer message= new StringBuffer();
final StringBuilder message= new StringBuilder();

fReference.setRange(document, 0, document.getLength());
fTestee.setRange(document, 0, document.getLength());
Expand Down Expand Up @@ -215,7 +215,7 @@ private void assertTokenEquals(IToken expected, IToken actual) {
}

private static String extractString(IDocument document, int offset) {
final StringBuffer buffer= new StringBuffer();
final StringBuilder buffer= new StringBuilder();

try {
IRegion region= document.getLineInformationOfOffset(offset);
Expand Down Expand Up @@ -246,7 +246,7 @@ private static String extractString(IDocument document, int offset) {
* @return the escaped string
*/
public static String escape(String string) {
final StringBuffer buffer= new StringBuffer();
final StringBuilder buffer= new StringBuilder();

final int length= string.length();
for (int i= 0; i < length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void printNotLoaded() {

@Test
public void pluginsNotLoaded() {
StringBuffer buf= new StringBuffer();
StringBuilder buf= new StringBuilder();
for (String element : NOT_LOADED_BUNDLES) {
Bundle bundle= Platform.getBundle(element);
if (element.contains("org.junit"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private IRegion assembleMethodBodyTestCUExtractSelection(StringBuffer buffer, St
" }\n" +
fMembers +
"}\n";
StringBuffer lineBuffer= new StringBuffer(javadocLine);
StringBuilder lineBuffer= new StringBuilder(javadocLine);
int firstPipe= lineBuffer.indexOf(CARET);
int secondPipe;
if (firstPipe == -1) {
Expand Down Expand Up @@ -469,7 +469,7 @@ private IRegion assembleClassBodyTestCUExtractSelection(StringBuffer buffer, Str
"\n" +
fMembers +
"}\n";
StringBuffer lineBuffer= new StringBuffer(javadocLine);
StringBuilder lineBuffer= new StringBuilder(javadocLine);
int firstPipe= lineBuffer.indexOf(CARET);
int secondPipe;
if (firstPipe == -1) {
Expand Down Expand Up @@ -498,7 +498,7 @@ private IRegion assembleClassJavadocTestCUExtractSelection(StringBuffer buffer,
"\n" +
fMembers +
"}\n";
StringBuffer lineBuffer= new StringBuffer(javadocLine);
StringBuilder lineBuffer= new StringBuilder(javadocLine);
int firstPipe= lineBuffer.indexOf(CARET);
int secondPipe;
if (firstPipe == -1) {
Expand All @@ -525,7 +525,7 @@ private IRegion assembleMethodJavadocTestCUExtractSelection(StringBuffer buffer,
" */\n" +
fMembers +
"}\n";
StringBuffer lineBuffer= new StringBuffer(javadocLine);
StringBuilder lineBuffer= new StringBuilder(javadocLine);
int firstPipe= lineBuffer.indexOf(CARET);
int secondPipe;
if (firstPipe == -1) {
Expand Down
Loading

0 comments on commit 0546fc5

Please sign in to comment.