Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blewitt2016-04-22 23:00:51 +0000
committerSergey Prigogin2016-04-25 16:38:47 +0000
commit6bdca5f4a2598b1206d51a59b720314a2f7aa3c1 (patch)
tree6c94852b1cf0abc24dcb1af3ef1526e89314bbe2 /build/org.eclipse.cdt.autotools.ui
parente21fc12f9052e99dcf545df4a2ae2aba1c90c1cc (diff)
downloadorg.eclipse.cdt-6bdca5f4a2598b1206d51a59b720314a2f7aa3c1.tar.gz
org.eclipse.cdt-6bdca5f4a2598b1206d51a59b720314a2f7aa3c1.tar.xz
org.eclipse.cdt-6bdca5f4a2598b1206d51a59b720314a2f7aa3c1.zip
Bug 492230 - Replace buffer.append(a+b) calls
When using a `StringBuilder` or `StringBuffer` to create a string message, using implicit string concatenation inside an `.append()` call will create a nested StringBuilder for the purposes of creating the arguments, which will subsequently be converted to a String and then passed to the outer StringBuilder. Skip the creation of the intermediate object and String by simply replacing such calls with `buffer.append(a).append(b)`. Where values are compile time String constants, leave as is so that the javac compiler can perform compile-time String concatenation. Ensure that NEWLINE isn't appended in such a way since it is not a compile time constant `System.getProperty("line.separator")` Change-Id: I4126aefb2272f06b08332e004d7ea76b6f02cdba Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com>
Diffstat (limited to 'build/org.eclipse.cdt.autotools.ui')
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfPartitioner.java14
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java6
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeTextHover.java4
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/text/hover/AutoconfTextHover.java15
4 files changed, 19 insertions, 20 deletions
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfPartitioner.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfPartitioner.java
index 4de4a5257e7..000f36ca68d 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfPartitioner.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfPartitioner.java
@@ -41,25 +41,21 @@ public class AutoconfPartitioner extends FastPartitioner {
public void printPartitions(ITypedRegion[] partitions)
{
- StringBuilder buffer = new StringBuilder();
-
for (int i = 0; i < partitions.length; i++)
{
try
{
- buffer.append("Partition type: " + partitions[i].getType() //$NON-NLS-1$
+ System.out.print("Partition type: " + partitions[i].getType() //$NON-NLS-1$
+ ", offset: " + partitions[i].getOffset() //$NON-NLS-1$
- + ", length: " + partitions[i].getLength()); //$NON-NLS-1$
- buffer.append("\n"); //$NON-NLS-1$
- buffer.append("Text:\n"); //$NON-NLS-1$
- buffer.append(super.fDocument.get(partitions[i].getOffset(), partitions[i].getLength()));
- buffer.append("\n---------------------------\n\n\n"); //$NON-NLS-1$
+ + ", length: " + partitions[i].getLength() //$NON-NLS-1$
+ +"\nText:\n" //$NON-NLS-1$
+ + super.fDocument.get(partitions[i].getOffset(), partitions[i].getLength())
+ + "\n---------------------------\n\n\n"); //$NON-NLS-1$
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
- System.out.print(buffer);
}
}
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
index 82ddf6719de..1de726c5ae2 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java
@@ -130,7 +130,7 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
if (currentWord.startsWith("'")) { //$NON-NLS-1$
StringBuilder tmpTarget = new StringBuilder();
while (!currentWord.endsWith("'")) { //$NON-NLS-1$
- tmpTarget.append(currentWord + " "); //$NON-NLS-1$
+ tmpTarget.append(currentWord).append(' ');
if (!st.hasMoreTokens()) {
// quote not closed properly, so return null
return null;
@@ -146,7 +146,7 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
if (currentWord.startsWith("\"")) { //$NON-NLS-1$
StringBuilder tmpTarget = new StringBuilder();
while (!currentWord.endsWith("\"")) { //$NON-NLS-1$
- tmpTarget.append(currentWord + " "); //$NON-NLS-1$
+ tmpTarget.append(currentWord).append(' ');
if (!st.hasMoreTokens()) {
// double quote not closed properly, so return null
return null;
@@ -340,7 +340,7 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
// POSIX-compliant shells.
StringBuilder command1 = new StringBuilder(strippedCommand);
for (String arg : argumentList) {
- command1.append(" " + arg);
+ command1.append(' ').append(arg);
}
newArgumentList = new String[] { "-c", command1.toString() };
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeTextHover.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeTextHover.java
index 86bb102ba7c..74b124508e6 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeTextHover.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeTextHover.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 Red Hat Inc..
+ * Copyright (c) 2006, 2016 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -76,7 +76,7 @@ public class AutomakeTextHover implements ITextHover, ITextHoverExtension {
StringBuilder toReturn = new StringBuilder();
toReturn.append(preReqs[0]);
for (int i = 1; i < preReqs.length; i++) {
- toReturn.append(" " + preReqs[i]);
+ toReturn.append(' ').append(preReqs[i]);
}
return toReturn.toString();
}
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/text/hover/AutoconfTextHover.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/text/hover/AutoconfTextHover.java
index c6e37a7a4de..a1891e7a52a 100644
--- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/text/hover/AutoconfTextHover.java
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/text/hover/AutoconfTextHover.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 Red Hat, Inc.
+ * Copyright (c) 2006, 2016 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -294,7 +294,7 @@ public class AutoconfTextHover implements ITextHover, ITextHoverExtension {
Element elem = document.getElementById(name);
if (null != elem) {
int prototypeCount = 0;
- buffer.append("<B>Macro:</B> " + name);
+ buffer.append("<B>Macro:</B> ").append(name);
NodeList nl = elem.getChildNodes();
for (int i = 0; i < nl.getLength(); ++i) {
Node n = nl.item(i);
@@ -304,8 +304,11 @@ public class AutoconfTextHover implements ITextHover, ITextHoverExtension {
++prototypeCount;
if (prototypeCount == 1) {
buffer.append(" (");
- } else
- buffer.append(" <B>or</B> " + name + " (<I>"); //$NON-NLS-2$
+ } else {
+ buffer.append(" <B>or</B> "); //$NON-NLS-2$
+ buffer.append(name);
+ buffer.append(" (<I>"); //$NON-NLS-2$
+ }
NodeList varList = n.getChildNodes();
for (int j = 0; j < varList.getLength(); ++j) {
Node v = varList.item(j);
@@ -317,10 +320,10 @@ public class AutoconfTextHover implements ITextHover, ITextHoverExtension {
if (prototype.length() == 0)
prototype.append(parm);
else
- prototype.append(", " + parm);
+ prototype.append(", ").append(parm);
}
}
- buffer.append(prototype.toString() + "</I>)<br>"); //$NON-NLS-1$
+ buffer.append(prototype).append("</I>)<br>"); //$NON-NLS-1$
}
if (nodeName.equals("synopsis")) { //$NON-NLS-1$
Node textNode = n.getLastChild();

Back to the top