Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-25 15:17:13 +0000
committerMarkus Schorn2008-02-25 15:17:13 +0000
commit517100139327cecd34a081c6761eadbd358cfc2e (patch)
tree5d48adc4db415726cf2eb38080fde81f85fffc22
parenteda39314e74d34ae1b22ef9cd68e8de510303837 (diff)
downloadorg.eclipse.cdt-517100139327cecd34a081c6761eadbd358cfc2e.tar.gz
org.eclipse.cdt-517100139327cecd34a081c6761eadbd358cfc2e.tar.xz
org.eclipse.cdt-517100139327cecd34a081c6761eadbd358cfc2e.zip
Avoid calling StringBuffer.append(CharSequence s) with a StringBuffer as argument, bug 220158.
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/StringBuilderTest.java41
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java5
3 files changed, 48 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/StringBuilderTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/StringBuilderTest.java
new file mode 100644
index 00000000000..6abf500dbcf
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/tests/StringBuilderTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.internal.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class StringBuilderTest extends TestCase {
+ public static Test suite() {
+ return new TestSuite(StringBuilderTest.class, "StringBuilderTest");
+ }
+
+ public void testSafe() {
+ StringBuilder b1= new StringBuilder();
+ StringBuilder b2= new StringBuilder();
+ b1.append("a");
+ b2.append("b");
+ CharSequence cs= b2;
+ b1.append(cs);
+ assertEquals("ab", b1.toString());
+ }
+
+ public void testBug220158() {
+ StringBuilder b1= new StringBuilder();
+ StringBuilder b2= new StringBuilder();
+ b1.append("a");
+ b2.append("b");
+ b1.append(b2);
+ assertEquals("ab", b1.toString());
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index fbf3420192a..8836477f7b2 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 IBM Corporation 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
@@ -24,6 +24,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTests;
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
+import org.eclipse.cdt.core.internal.tests.StringBuilderTest;
import org.eclipse.cdt.core.language.AllLanguageTests;
import org.eclipse.cdt.core.model.tests.AllCoreTests;
import org.eclipse.cdt.core.model.tests.BinaryTests;
@@ -68,6 +69,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(ElementDeltaTests.suite());
suite.addTest(WorkingCopyTests.suite());
suite.addTest(PositionTrackerTests.suite());
+ suite.addTest(StringBuilderTest.suite());
suite.addTest(AllLanguageTests.suite());
// Add in PDOM tests
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
index f3d93e07bbf..fd398014a1d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
@@ -124,7 +124,10 @@ public class MacroExpansionTracker {
StringBuilder after= new StringBuilder();
toString(result, lexInput, before, replace, after);
int offset= before.length();
- before.append(replace).append(after);
+ // workaround bug 220158
+ final CharSequence csr= replace;
+ final CharSequence csa= after;
+ before.append(csr).append(csa);
before.append(lexInput, endOffset, lexInput.length-endOffset);
fPreStep= before.toString();
fReplacement= new ReplaceEdit(offset, replace.length(), fReplacementText);

Back to the top