Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2016-05-10 09:09:33 +0000
committerLars Vogel2016-09-09 12:09:34 +0000
commit19b9ebaeda8e44b887a21263df8c15d822cc3575 (patch)
tree4240f4968cc0d1cb0f7811edb2e0639da2f792c9
parentc26c83e44725f551e3fdeed4c36a2724001fbfb4 (diff)
downloadeclipse.platform.text-19b9ebaeda8e44b887a21263df8c15d822cc3575.tar.gz
eclipse.platform.text-19b9ebaeda8e44b887a21263df8c15d822cc3575.tar.xz
eclipse.platform.text-19b9ebaeda8e44b887a21263df8c15d822cc3575.zip
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>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java25
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java11
2 files changed, 20 insertions, 16 deletions
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 73522d819..4b1bc5164 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 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
* 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 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
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 1064840d8..5b88c9236 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 @@ public class OverviewRuler implements IOverviewRulerExtension, IOverviewRuler {
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 @@ public class OverviewRuler implements IOverviewRulerExtension, IOverviewRuler {
}
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());
}
/**

Back to the top