From 05c1dee1bcea24dd333fd87883ffa22a1024f65b Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 29 Jun 2007 11:26:44 +0000 Subject: [PATCH] Fix for 194710: [Indent] Issue when case statement has a 'char' --- .../cdt/ui/tests/text/CIndenterTest.java | 25 +++++++++++++++++++ .../cdt/internal/ui/text/CIndenter.java | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) 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 7b148112a47..a9be1a03e33 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 @@ -205,4 +205,29 @@ public class CIndenterTest extends BaseUITestCase { public void testIndentationOfConstructorBodyWithInitializer_Bug194586() throws Exception { assertIndenterResult(); } + + //void f() { + //switch(c) { + //case 'a': + //{ + //} + //case 1: + //{ + //} + //} + //} + + //void f() { + // switch(c) { + // case 'a': + // { + // } + // case 1: + // { + // } + // } + //} +public void testIndentationOfCaseBlockAfterCharLiteral_Bug194710() 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 e4dbc3900d0..e2fa956f7e3 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 @@ -785,7 +785,9 @@ public final class CIndenter { case Symbols.TokenLBRACE: // for opening-brace-on-new-line style if (bracelessBlockStart && !fPrefs.prefIndentBracesForBlocks) unindent= true; - else if ((prevToken == Symbols.TokenCOLON || prevToken == Symbols.TokenEQUAL || prevToken == Symbols.TokenRBRACKET) && !fPrefs.prefIndentBracesForArrays) + else if (prevToken == Symbols.TokenCOLON && !fPrefs.prefIndentBracesForBlocks) + unindent= true; + else if ((prevToken == Symbols.TokenEQUAL || prevToken == Symbols.TokenRBRACKET) && !fPrefs.prefIndentBracesForArrays) unindent= true; else if (!bracelessBlockStart && fPrefs.prefIndentBracesForMethods) indent= true; @@ -1004,6 +1006,9 @@ public final class CIndenter { private boolean looksLikeCaseStatement() { nextToken(); switch (fToken) { + case Symbols.TokenCASE: + // char literal got skipped + return true; case Symbols.TokenIDENT: nextToken(); while (skipQualifiers()) {