Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java53
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java4
2 files changed, 52 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
index 270b9573d3..8ab9167eeb 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 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
@@ -12,13 +12,18 @@
package org.eclipse.cdt.ui.tests.text;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentCommand;
@@ -28,6 +33,7 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
@@ -40,7 +46,7 @@ import org.eclipse.cdt.internal.ui.text.CTextTools;
/**
* Testing the auto indent strategies.
*/
-public class CAutoIndentTest extends TestCase {
+public class CAutoIndentTest extends BaseTestCase {
/**
* Helper class to test the auto-edit strategies on a document.
@@ -230,6 +236,8 @@ public class CAutoIndentTest extends TestCase {
}
private HashMap fOptions;
+ private List fStatusLog;
+ private ILogListener fLogListener;
/**
@@ -249,12 +257,29 @@ public class CAutoIndentTest extends TestCase {
// shell.forceActive();
// shell.forceFocus();
fOptions= CCorePlugin.getOptions();
- }
+
+ fStatusLog= Collections.synchronizedList(new ArrayList());
+ fLogListener= new ILogListener() {
+ public void logging(IStatus status, String plugin) {
+ if(!status.isOK()) {
+ fStatusLog.add(status);
+ }
+ }
+ };
+ final Plugin plugin = CUIPlugin.getDefault();
+ if (plugin != null) {
+ plugin.getLog().addLogListener(fLogListener);
+ }
+}
/*
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
+ final Plugin plugin = CUIPlugin.getDefault();
+ if (plugin != null) {
+ plugin.getLog().removeLogListener(fLogListener);
+ }
CCorePlugin.setOptions(fOptions);
super.tearDown();
}
@@ -552,5 +577,25 @@ public class CAutoIndentTest extends TestCase {
assertEquals("\t", tester.getLine());
assertEquals(1, tester.getCaretColumn());
}
+
+ public void testSmartPaste_Bug215310() throws Exception {
+ AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$
+
+ tester.type("#define S \\ \n");
+ tester.type("d\n");
+ tester.paste(
+ "class B : private A \n" +
+ "{\n" +
+ "};\n"
+ );
+
+ assertNoError();
+ }
+
+ private void assertNoError() {
+ if (!fStatusLog.isEmpty()) {
+ fail(fStatusLog.get(0).toString());
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java
index 9cec200aa1..aa60713d07 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 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
@@ -546,6 +546,8 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
return;
int peerOffset= getPeerPosition(document, command);
peerOffset= indenter.findReferencePosition(peerOffset);
+ if (peerOffset == CHeuristicScanner.NOT_FOUND)
+ return;
refOffset= Math.min(refOffset, peerOffset);
// eat any WS before the insertion to the beginning of the line

Back to the top