Bugs 529299 and 491296. Fix indentation after 'noexcept'/'override'.
Change-Id: I3129e5f9fced4a27020f6ca27238bf5faf4df889
Signed-off-by: Davin McCall <davmac@davmac.org>
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 663c5fa..5a635a7 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
@@ -512,7 +512,44 @@
// The brace was closed automatically.
assertEquals("}", tester.getLine(1)); //$NON-NLS-1$
}
-
+
+ public void testSmartIndentAfterNoexcept_Bug529299() throws Exception {
+ AutoEditTester tester = createAutoEditTester();
+
+ tester.type("void f() noexcept\n"); //$NON-NLS-1$
+ assertEquals(1, tester.getCaretLine());
+ tester.type('{');
+ // Brace is not indented
+ assertEquals(1, tester.getCaretColumn());
+ tester.type('\n');
+ // The brace was closed automatically.
+ assertEquals("}", tester.getLine(1)); //$NON-NLS-1$
+
+ tester.reset();
+ tester.type("void f() noexcept(true)\n"); //$NON-NLS-1$
+ assertEquals(1, tester.getCaretLine());
+ tester.type('{');
+ // Brace is not indented
+ assertEquals(1, tester.getCaretColumn());
+ tester.type('\n');
+ // The brace was closed automatically.
+ assertEquals("}", tester.getLine(1)); //$NON-NLS-1$
+ }
+
+ public void testSmartIndentAfterOverride_Bug491296() throws Exception {
+ AutoEditTester tester = createAutoEditTester();
+
+ tester.reset();
+ tester.type("void f() override\n"); //$NON-NLS-1$
+ assertEquals(1, tester.getCaretLine());
+ tester.type('{');
+ // Brace is not indented
+ assertEquals(1, tester.getCaretColumn());
+ tester.type('\n');
+ // The brace was closed automatically.
+ assertEquals("}", tester.getLine(1)); //$NON-NLS-1$
+ }
+
public void testSkipToStatementStartWhitesmiths_Bug311018() throws Exception {
DefaultCodeFormatterOptions whitesmiths= DefaultCodeFormatterOptions.getWhitesmithsSettings();
CCorePlugin.setOptions(new HashMap<String, String>(whitesmiths.getMap()));
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 db8e3f3..838f869 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
@@ -630,6 +630,10 @@
return TokenTEMPLATE;
if ("typename".equals(s)) //$NON-NLS-1$
return TokenTYPENAME;
+ if ("noexcept".equals(s)) //$NON-NLS-1$
+ return TokenNOEXCEPT;
+ if ("override".equals(s)) //$NON-NLS-1$
+ return TokenOVERRIDE;
break;
case 9:
if ("namespace".equals(s)) //$NON-NLS-1$
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 5aa530d..8b53016 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
@@ -1123,7 +1123,9 @@
return fPosition;
}
fPosition= scope;
- if (looksLikeMethodDecl()) {
+ // "noexcept" at this point would be a noexcept-with-argument, which should be
+ // attached to a method declaration:
+ if (looksLikeMethodDecl() || fToken == Symbols.TokenNOEXCEPT) {
return skipToStatementStart(danglingElse, false);
}
if (fToken == Symbols.TokenCATCH) {
@@ -1140,6 +1142,11 @@
// else: fall through to default
return skipToPreviousListItemOrListStart();
+ case Symbols.TokenNOEXCEPT:
+ case Symbols.TokenOVERRIDE:
+ // Method declaration
+ return skipToStatementStart(danglingElse, false);
+
case Symbols.TokenCOMMA:
// Inside a list of some type.
// Easy if there is already a list item before with its own indentation - we just align.
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 ec2e89e..45493db 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
@@ -72,5 +72,7 @@
int TokenUSING= 1039;
int TokenTEMPLATE= 1040;
int TokenTYPENAME= 1041;
+ int TokenNOEXCEPT= 1042;
+ int TokenOVERRIDE= 1043;
int TokenIDENT= 2000;
}