1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Fix for 194585: [Indentation] of nested brackets inside an array declaration > inside an array declaration.

This commit is contained in:
Anton Leherbauer 2007-07-04 13:12:56 +00:00
parent a0140348f1
commit 8ecd3b539e
4 changed files with 82 additions and 22 deletions

View file

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

View file

@ -2,9 +2,9 @@
const SimpleStruct simpleStruct =
{
1
, "mySimple"
, 0.1232
1,
"mySimple",
0.1232
};
#define SIZEOF( A, B ) sizeof( A.B )

View file

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

View file

@ -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 <code>true</code> if the next token received after calling
* <code>nextToken</code> is either an equal sign or an array designator ('[]').
* <code>nextToken</code> is either an equal sign, an opening brace,
* a comma or an array designator ('[]').
*
* @return <code>true</code> 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;