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 0e96290ebe9..5a7f8865c06 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 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2007 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
@@ -26,12 +26,13 @@ import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
+
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CCommentAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CTextTools;
@@ -228,6 +229,8 @@ public class CAutoIndentTest extends TestCase {
}
}
+ private HashMap fOptions;
+
/**
* @param name
@@ -242,21 +245,28 @@ public class CAutoIndentTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- shell.forceActive();
- shell.forceFocus();
+// Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+// shell.forceActive();
+// shell.forceFocus();
+ fOptions= CCorePlugin.getOptions();
}
+ /*
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ CCorePlugin.setOptions(fOptions);
+ super.tearDown();
+ }
+
private AutoEditTester createAutoEditTester() {
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
IDocument doc = new Document();
textTools.setupCDocument(doc);
- AutoEditTester tester = new AutoEditTester(doc, textTools.getDocumentPartitioning());
- tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE,
- new CAutoIndentStrategy(textTools.getDocumentPartitioning(), null));
+ AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
+ tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new CCommentAutoIndentStrategy());
- tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR,
- new CAutoIndentStrategy(textTools.getDocumentPartitioning(), null));
+ tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
return tester;
}
@@ -487,5 +497,22 @@ public class CAutoIndentTest extends TestCase {
tester.type("for (;;) /*class*/ {\n"); //$NON-NLS-1$
assertEquals("for (;;) /*class*/ {\n\t\r\n}", tester.fDoc.get()); //$NON-NLS-1$
}
+
+ public void testSmartPasteWhitesmiths_Bug180531() throws Exception {
+ DefaultCodeFormatterOptions whitesmiths= DefaultCodeFormatterOptions.getWhitesmithsSettings();
+ CCorePlugin.setOptions(new HashMap(whitesmiths.getMap()));
+ AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$
+
+ tester.type("A::~A()\n{");
+ assertEquals("A::~A()\n {", tester.fDoc.get());
+ tester.type("\ndelete x;");
+ assertEquals("A::~A()\n {\n delete x;\n }", tester.fDoc.get());
+
+ tester.setCaretOffset(tester.fDoc.getLength());
+ tester.type('\n');
+ String copy= tester.fDoc.get();
+ tester.paste(copy);
+ assertEquals(copy+copy, tester.fDoc.get());
+ }
}
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 9aed3051335..dfb41038cc2 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
@@ -213,11 +213,11 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
scanner = new CHeuristicScanner(d, fPartitioning, ICPartitions.C_PREPROCESSOR);
}
// current line
- int line = d.getLineOfOffset(p);
+ int line = d.getLineOfOffset(c.offset);
int lineOffset = d.getLineOffset(line);
// make sure we don't have any leading comments etc.
- if (d.get(lineOffset, p - lineOffset).trim().length() != 0)
+ if (d.get(lineOffset, c.offset - lineOffset).trim().length() != 0)
return;
// Line of last C code
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
index 4a7d78e4368..4f1bfb5e7ea 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
@@ -60,6 +60,7 @@ public final class CHeuristicScanner implements Symbols {
private static final char RANGLE= '>';
private static final char DOT= '.';
private static final char MINUS= '-';
+ private static final char TILDE= '~';
/**
* Specifies the stop condition, upon which the scanXXX
methods will decide whether
@@ -407,6 +408,8 @@ public final class CHeuristicScanner implements Symbols {
return TokenDOT;
case MINUS:
return TokenMINUS;
+ case TILDE:
+ return TokenTILDE;
}
// else
@@ -754,8 +757,8 @@ public final class CHeuristicScanner implements Symbols {
/**
* Finds the highest position in fDocument
such that the position is <= position
- * and > bound
and fDocument.getChar(position) == ch
evaluates to true
for at least one
- * ch in chars
and the position is in the default partition.
+ * and > bound
and fDocument.getChar(position) == ch
evaluates to true
+ * and the position is in the default partition.
*
* @param position the first character position in fDocument
to be considered
* @param bound the first position in fDocument
to not consider any more, with bound
< position
, or UNBOUND
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
index afde1d9d029..214498edc62 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 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
@@ -220,7 +220,7 @@ public final class CIndenter {
// ignore and return default
}
- return true;
+ return false;
}
private int prefMethodDeclIndent() {
@@ -883,8 +883,8 @@ public final class CIndenter {
return matchCaseAlignment();
}
- // the only reliable way to get case labels aligned (due to many different styles of using braces in a block)
- // is to go for another case statement, or the scope opening brace
+ // the only reliable way to get access specifiers aligned (due to many different styles of using braces in a block)
+ // is to go for another access specifier, or the scope opening brace
if (matchAccessSpecifier) {
return matchAccessSpecifierAlignment();
}
@@ -1194,8 +1194,9 @@ public final class CIndenter {
}
/**
- * Returns as a reference any previous switch
labels (case
- * or default
) or the offset of the brace that scopes the class body.
+ * Returns as a reference any previous access specifiers (public
,
+ * protected
or default
) or the offset of the brace that
+ * scopes the class body.
* Sets fIndent
to prefAccessSpecifierIndent
upon
* a match.
*
@@ -1205,7 +1206,7 @@ public final class CIndenter {
while (true) {
nextToken();
switch (fToken) {
- // invalid cases: another case label or an LBRACE must come before a case
+ // invalid cases: another access specifier or an LBRACE must come before an access specifier
// -> bail out with the current position
case Symbols.TokenLPAREN:
case Symbols.TokenLBRACKET:
@@ -1213,14 +1214,14 @@ public final class CIndenter {
return fPosition;
case Symbols.TokenLBRACE:
- // opening brace of switch statement
+ // opening brace of class body
fIndent= fPrefs.prefAccessSpecifierIndent;
return fPosition;
case Symbols.TokenPUBLIC:
case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE:
- // align with previous label
+ // align with previous access specifier
fIndent= 0;
return fPosition;
@@ -1634,9 +1635,7 @@ public final class CIndenter {
* Returns true
if the current tokens look like a method
* declaration header (i.e. only the return type and method name). The
* heuristic calls nextToken
and expects an identifier
- * (method name) and a type declaration (an identifier with optional
- * brackets) which also covers the visibility modifier of constructors; it
- * does not recognize package visible constructors.
+ * (method name) and an optional retrun type declaration.
*
* @return true
if the current position looks like a method
* declaration header.
@@ -1644,10 +1643,19 @@ public final class CIndenter {
private boolean looksLikeMethodDecl() {
nextToken();
if (fToken == Symbols.TokenIDENT) { // method name
- do nextToken();
- while (skipBrackets() || skipQualifiers()); // optional brackets for array valued return types
-
- return fToken == Symbols.TokenIDENT; // return type name
+ nextToken();
+ // check destructor tilde
+ if (fToken == Symbols.TokenTILDE) {
+ return true;
+ }
+ if (skipQualifiers()) {
+ return true;
+ }
+ // optional brackets for array valued return types
+ while (skipBrackets()) {
+ nextToken();
+ }
+ return fToken == Symbols.TokenIDENT;
}
return false;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
index a4ad2275e76..97774ddfa3a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
@@ -33,6 +33,7 @@ public interface Symbols {
int TokenGREATERTHAN= 14;
int TokenDOT= 15;
int TokenMINUS= 16;
+ int TokenTILDE= 17;
int TokenIF= 109;
int TokenDO= 1010;
int TokenFOR= 1011;