Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrey Mozzhuhin2020-04-15 20:24:44 +0000
committerMarco Stornelli2020-04-16 13:28:55 +0000
commitf4f9785b87bf0294c92096ee58ab691359068677 (patch)
tree4a7106583e2225e3e10e0b0825d8c04674198a9a /core
parentcab5fc1752f9b0578e250a194e312a59b7252802 (diff)
downloadorg.eclipse.cdt-f4f9785b87bf0294c92096ee58ab691359068677.tar.gz
org.eclipse.cdt-f4f9785b87bf0294c92096ee58ab691359068677.tar.xz
org.eclipse.cdt-f4f9785b87bf0294c92096ee58ab691359068677.zip
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>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java19
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java5
2 files changed, 24 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
index a9a4a9c3841..15ca7f6c2fa 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
@@ -1082,4 +1082,23 @@ public class CIndenterTest extends BaseUITestCase {
public void testIndentationAfterFunctionCallWithQualifier_Bug562125() throws Exception {
assertIndenterResult();
}
+
+ //class Test
+ //{
+ //public:
+ //Test()
+ //{
+ //}
+ //};
+
+ //class Test
+ //{
+ //public:
+ // Test()
+ // {
+ // }
+ //};
+ public void testIndentationAfterContructorWithAccessSpecifier_Bug562181() throws Exception {
+ assertIndenterResult();
+ }
}
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 03fb9d8825a..069e46198a9 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
@@ -2245,10 +2245,12 @@ public final class CIndenter {
case Symbols.TokenSEMICOLON:
case Symbols.TokenRBRACE:
fPosition = pos;
+ fToken = Symbols.TokenIDENT;
return true;
case Symbols.TokenLBRACE:
if (fScanner.looksLikeCompositeTypeDefinitionBackward(fPosition, CHeuristicScanner.UNBOUND)) {
fPosition = pos;
+ fToken = Symbols.TokenIDENT;
return true;
}
break;
@@ -2268,11 +2270,13 @@ public final class CIndenter {
case Symbols.TokenPROTECTED:
case Symbols.TokenPRIVATE:
fPosition = pos;
+ fToken = Symbols.TokenIDENT;
return true;
case Symbols.TokenRPAREN:
// constructor initializer
if (skipScope()) {
pos = fPosition;
+ int token = fToken;
nextToken();
// optional throw
if (fToken == Symbols.TokenTHROW) {
@@ -2282,6 +2286,7 @@ public final class CIndenter {
}
} else {
fPosition = pos;
+ fToken = token;
}
return looksLikeMethodDecl();
}

Back to the top