Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavin McCall2017-12-30 23:12:38 +0000
committerNathan Ridge2018-01-10 05:08:49 +0000
commita2930329383f8be84fa9ee74e8c9eef48a30e03c (patch)
treeef90851c94cb2491771bb5b88fb10588248620db
parent0a639043fab2aac450e778a86ed3c45fa034d0d6 (diff)
downloadorg.eclipse.cdt-a2930329383f8be84fa9ee74e8c9eef48a30e03c.tar.gz
org.eclipse.cdt-a2930329383f8be84fa9ee74e8c9eef48a30e03c.tar.xz
org.eclipse.cdt-a2930329383f8be84fa9ee74e8c9eef48a30e03c.zip
Bugs 529299 and 491296. Fix indentation after 'noexcept'/'override'.
Change-Id: I3129e5f9fced4a27020f6ca27238bf5faf4df889 Signed-off-by: Davin McCall <davmac@davmac.org>
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java2
4 files changed, 52 insertions, 2 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 663c5fa951..5a635a7144 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 @@ public class CAutoIndentTest extends AbstractAutoEditTest {
// 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 db8e3f30b1..838f869c19 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 @@ public final class CHeuristicScanner implements Symbols {
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 5aa530dafa..8b53016573 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 @@ public final class CIndenter {
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 @@ public final class CIndenter {
// 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 ec2e89e606..45493dbceb 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 @@ public interface Symbols {
int TokenUSING= 1039;
int TokenTEMPLATE= 1040;
int TokenTYPENAME= 1041;
+ int TokenNOEXCEPT= 1042;
+ int TokenOVERRIDE= 1043;
int TokenIDENT= 2000;
}

Back to the top