diff --git a/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/After.cpp index f0a58f151a3..6ecb3013f3c 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/After.cpp @@ -2,9 +2,9 @@ const SimpleStruct simpleStruct = { - 1 - , "mySimple" - , 0.1232 + 1, + "mySimple", + 0.1232 }; #define SIZEOF( A, B ) sizeof( A.B ) @@ -20,19 +20,19 @@ const OtherStruct array[] = { { #if FOO - "foo" + "foo" # else - "bar" + "bar" #endif - , SIZEOF( simpleStruct, num ) - , &t_int - , 0 + , SIZEOF( simpleStruct, num ) + , &t_int + , 0 } , { - "name" - , SIZEOF( simpleStruct, floatnum ) - , &t_float - , 1 + "name" + , SIZEOF( simpleStruct, floatnum ) + , &t_float + , 1 } }; diff --git a/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/Before.cpp b/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/Before.cpp index aa131f0da36..c1f5449b7ac 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/Before.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/indentation/sample/Before.cpp @@ -2,9 +2,9 @@ const SimpleStruct simpleStruct = { - 1 - , "mySimple" - , 0.1232 + 1, +"mySimple", +0.1232 }; #define SIZEOF( A, B ) sizeof( A.B ) 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 a9be1a03e33..410726c0713 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 @@ -227,7 +227,53 @@ public class CIndenterTest extends BaseUITestCase { // } // } //} -public void testIndentationOfCaseBlockAfterCharLiteral_Bug194710() throws Exception { + public void testIndentationOfCaseBlockAfterCharLiteral_Bug194710() throws Exception { + assertIndenterResult(); + } + + //int a[]= + //{ + //1, + //2 + //}; + + //int a[]= + //{ + // 1, + // 2 + //}; + public void testIndentationOfInitializerLists_Bug194585() throws Exception { + assertIndenterResult(); + } + + //struct_t a[]= + //{ + //{ + //1, + //2, + //{ 1,2,3 } + //}, + //{ + //1, + //2, + //{ 1,2,3 } + //} + //}; + + //struct_t a[]= + //{ + // { + // 1, + // 2, + // { 1,2,3 } + // }, + // { + // 1, + // 2, + // { 1,2,3 } + // } + //}; + public void testIndentationOfNestedInitializerLists_Bug194585() 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 e2fa956f7e3..1ca0c439f28 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 @@ -1502,9 +1502,10 @@ public final class CIndenter { case Symbols.TokenLBRACE: pos= fPosition; // store - + + final boolean looksLikeArrayInitializerIntro= looksLikeArrayInitializerIntro(); // special: array initializer - if (looksLikeArrayInitializerIntro()) { + if (looksLikeArrayInitializerIntro) { if (fPrefs.prefArrayDeepIndent) return setFirstElementAlignment(pos, bound); else @@ -1517,8 +1518,7 @@ public final class CIndenter { // normal: skip to the statement start before the scope introducer // opening braces are often on differently ending indents than e.g. a method definition - if (looksLikeArrayInitializerIntro() && !fPrefs.prefIndentBracesForArrays - || !fPrefs.prefIndentBracesForBlocks) { + if (!looksLikeArrayInitializerIntro && !fPrefs.prefIndentBracesForBlocks) { fPosition= pos; // restore return skipToStatementStart(true, true); // set to true to match the first if } else { @@ -1564,13 +1564,27 @@ public final class CIndenter { /** * Returns true if the next token received after calling - * nextToken is either an equal sign or an array designator ('[]'). + * nextToken is either an equal sign, an opening brace, + * a comma or an array designator ('[]'). * * @return true if the next elements look like the start of an array definition */ private boolean looksLikeArrayInitializerIntro() { + int pos= fPosition; nextToken(); - if (fToken == Symbols.TokenEQUAL || skipBrackets()) { + switch (fToken) { + case Symbols.TokenEQUAL: + return true; + case Symbols.TokenRBRACKET: + return skipBrackets(); + case Symbols.TokenLBRACE: + if (looksLikeArrayInitializerIntro()) { + fPosition= pos; + return true; + } + return false; + case Symbols.TokenCOMMA: + fPosition= pos; return true; } return false;