Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDavin McCall2017-12-30 23:12:38 +0000
committerNathan Ridge2018-01-03 20:39:11 +0000
commitfc053e612491385bbd788c216936865b660bb9be (patch)
tree997c7aec9021555ee3c9cd749bc9a753df849c47 /core
parent1213755167106193fa9e1389caa22d3ab2a2b607 (diff)
downloadorg.eclipse.cdt-fc053e612491385bbd788c216936865b660bb9be.tar.gz
org.eclipse.cdt-fc053e612491385bbd788c216936865b660bb9be.tar.xz
org.eclipse.cdt-fc053e612491385bbd788c216936865b660bb9be.zip
Bugs 529299 and 491296. Fix indentation after 'noexcept'/'override'.
Change-Id: I3129e5f9fced4a27020f6ca27238bf5faf4df889 Signed-off-by: Davin McCall <davmac@davmac.org>
Diffstat (limited to 'core')
-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 663c5fa9513..5a635a71449 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 db8e3f30b1c..838f869c19e 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 5aa530dafa8..8b53016573b 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 ec2e89e6066..45493dbceb7 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