1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Bug 562181: Fix auto indent after constructor with access specifiers

Some heuristics in skipToStatementStart require knowledge of previous
token. It is initialized with value from a fToken, but it current value
may be invalid because looksLikeMethodDecl changes fPossition value
without adjusting a fToken. Using invalid value may lead to false
triggering of heuristics. Restore fToken value when change fPossition in
looksLikeMethodDecl to prevent this.

Change-Id: If0c2c0577c89a983e1479587409f293c3d0db7be
Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
This commit is contained in:
Andrey Mozzhuhin 2020-04-15 23:24:44 +03:00 committed by Marco Stornelli
parent cab5fc1752
commit f4f9785b87
2 changed files with 24 additions and 0 deletions

View file

@ -1082,4 +1082,23 @@ public class CIndenterTest extends BaseUITestCase {
public void testIndentationAfterFunctionCallWithQualifier_Bug562125() throws Exception { public void testIndentationAfterFunctionCallWithQualifier_Bug562125() throws Exception {
assertIndenterResult(); assertIndenterResult();
} }
//class Test
//{
//public:
//Test()
//{
//}
//};
//class Test
//{
//public:
// Test()
// {
// }
//};
public void testIndentationAfterContructorWithAccessSpecifier_Bug562181() throws Exception {
assertIndenterResult();
}
} }

View file

@ -2245,10 +2245,12 @@ public final class CIndenter {
case Symbols.TokenSEMICOLON: case Symbols.TokenSEMICOLON:
case Symbols.TokenRBRACE: case Symbols.TokenRBRACE:
fPosition = pos; fPosition = pos;
fToken = Symbols.TokenIDENT;
return true; return true;
case Symbols.TokenLBRACE: case Symbols.TokenLBRACE:
if (fScanner.looksLikeCompositeTypeDefinitionBackward(fPosition, CHeuristicScanner.UNBOUND)) { if (fScanner.looksLikeCompositeTypeDefinitionBackward(fPosition, CHeuristicScanner.UNBOUND)) {
fPosition = pos; fPosition = pos;
fToken = Symbols.TokenIDENT;
return true; return true;
} }
break; break;
@ -2268,11 +2270,13 @@ public final class CIndenter {
case Symbols.TokenPROTECTED: case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE: case Symbols.TokenPRIVATE:
fPosition = pos; fPosition = pos;
fToken = Symbols.TokenIDENT;
return true; return true;
case Symbols.TokenRPAREN: case Symbols.TokenRPAREN:
// constructor initializer // constructor initializer
if (skipScope()) { if (skipScope()) {
pos = fPosition; pos = fPosition;
int token = fToken;
nextToken(); nextToken();
// optional throw // optional throw
if (fToken == Symbols.TokenTHROW) { if (fToken == Symbols.TokenTHROW) {
@ -2282,6 +2286,7 @@ public final class CIndenter {
} }
} else { } else {
fPosition = pos; fPosition = pos;
fToken = token;
} }
return looksLikeMethodDecl(); return looksLikeMethodDecl();
} }