1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bugs 529299 and 491296. Fix indentation after 'noexcept'/'override'.

Change-Id: I3129e5f9fced4a27020f6ca27238bf5faf4df889
Signed-off-by: Davin McCall <davmac@davmac.org>
This commit is contained in:
Davin McCall 2017-12-30 23:12:38 +00:00 committed by Nathan Ridge
parent 1213755167
commit fc053e6124
4 changed files with 52 additions and 2 deletions

View file

@ -513,6 +513,43 @@ public class CAutoIndentTest extends AbstractAutoEditTest {
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()));

View file

@ -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$

View file

@ -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.

View file

@ -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;
}