Bug 493301 - Remove method concatenates strings using + in a loop
warnings reported by Sonar (non test code)
Change-Id: I6efd2ee63c04a596c7cd04a90784f67e6919fd3e
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
index 73522d8..4b1bc51 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
@@ -115,7 +115,7 @@
* the viewer).
* added controls how many lines are added - added lines are
*/
- String text= ""; //$NON-NLS-1$
+ StringBuffer text = new StringBuffer();
int added= 0;
for (Iterator<? extends ILineDiffInfo> it= diffInfos.iterator(); it.hasNext();) {
ILineDiffInfo info= it.next();
@@ -125,26 +125,29 @@
if (type == ILineDiffInfo.ADDED)
added++;
else if (type == ILineDiffInfo.CHANGED) {
- text += "> " + (original.length > 0 ? original[i++] : ""); //$NON-NLS-1$ //$NON-NLS-2$
+ text.append("> ").append(original.length > 0 ? original[i++] : ""); //$NON-NLS-1$ //$NON-NLS-2$
maxLines--;
} else if (type == ILineDiffInfo.UNCHANGED) {
maxLines++;
}
if (maxLines == 0)
- return trimTrailing(text);
+ return trimTrailing(text.toString());
for (; i < original.length; i++) {
- text += "- " + original[i]; //$NON-NLS-1$
+ text.append("- ").append( original[i]); //$NON-NLS-1$
added--;
if (--maxLines == 0)
- return trimTrailing(text);
+ return trimTrailing(text.toString());
}
}
- text= text.trim();
- if (text.length() == 0 && added-- > 0 && maxLines-- > 0)
- text += "+ "; //$NON-NLS-1$
- while (added-- > 0 && maxLines-- > 0)
- text += "\n+ "; //$NON-NLS-1$
- return text;
+
+ text = new StringBuffer(text.toString().trim());
+ if (text.length() == 0 && added-- > 0 && maxLines-- > 0) {
+ text.append("+ ");//$NON-NLS-1$
+ }
+ while (added-- > 0 && maxLines-- > 0) {
+ text.append("\n+ "); //$NON-NLS-1$
+ }
+ return text.toString();
}
/**
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
index 1064840..5b88c92 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
@@ -1505,7 +1505,7 @@
if (fHeader.getToolTipText() != null)
return;
- String overview= ""; //$NON-NLS-1$
+ StringBuffer overview = new StringBuffer();
for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) {
@@ -1528,14 +1528,15 @@
}
if (annotationTypeLabel != null) {
- if (overview.length() > 0)
- overview += "\n"; //$NON-NLS-1$
- overview += JFaceTextMessages.getFormattedString("OverviewRulerHeader.toolTipTextEntry", new Object[] {annotationTypeLabel, new Integer(count)}); //$NON-NLS-1$
+ if (overview.length() > 0) {
+ overview.append("\n"); //$NON-NLS-1$
+ }
+ overview.append(JFaceTextMessages.getFormattedString("OverviewRulerHeader.toolTipTextEntry", new Object[] {annotationTypeLabel, Integer.valueOf(count)})); //$NON-NLS-1$
}
}
if (overview.length() > 0)
- fHeader.setToolTipText(overview);
+ fHeader.setToolTipText(overview.toString());
}
/**