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:
parent
a0140348f1
commit
8ecd3b539e
4 changed files with 82 additions and 22 deletions
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
const SimpleStruct simpleStruct =
|
const SimpleStruct simpleStruct =
|
||||||
{
|
{
|
||||||
1
|
1,
|
||||||
, "mySimple"
|
"mySimple",
|
||||||
, 0.1232
|
0.1232
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SIZEOF( A, B ) sizeof( A.B )
|
#define SIZEOF( A, B ) sizeof( A.B )
|
||||||
|
@ -20,19 +20,19 @@ const OtherStruct array[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
#if FOO
|
#if FOO
|
||||||
"foo"
|
"foo"
|
||||||
# else
|
# else
|
||||||
"bar"
|
"bar"
|
||||||
#endif
|
#endif
|
||||||
, SIZEOF( simpleStruct, num )
|
, SIZEOF( simpleStruct, num )
|
||||||
, &t_int
|
, &t_int
|
||||||
, 0
|
, 0
|
||||||
}
|
}
|
||||||
, {
|
, {
|
||||||
"name"
|
"name"
|
||||||
, SIZEOF( simpleStruct, floatnum )
|
, SIZEOF( simpleStruct, floatnum )
|
||||||
, &t_float
|
, &t_float
|
||||||
, 1
|
, 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
const SimpleStruct simpleStruct =
|
const SimpleStruct simpleStruct =
|
||||||
{
|
{
|
||||||
1
|
1,
|
||||||
, "mySimple"
|
"mySimple",
|
||||||
, 0.1232
|
0.1232
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SIZEOF( A, B ) sizeof( A.B )
|
#define SIZEOF( A, B ) sizeof( A.B )
|
||||||
|
|
|
@ -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();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1502,9 +1502,10 @@ public final class CIndenter {
|
||||||
|
|
||||||
case Symbols.TokenLBRACE:
|
case Symbols.TokenLBRACE:
|
||||||
pos= fPosition; // store
|
pos= fPosition; // store
|
||||||
|
|
||||||
|
final boolean looksLikeArrayInitializerIntro= looksLikeArrayInitializerIntro();
|
||||||
// special: array initializer
|
// special: array initializer
|
||||||
if (looksLikeArrayInitializerIntro()) {
|
if (looksLikeArrayInitializerIntro) {
|
||||||
if (fPrefs.prefArrayDeepIndent)
|
if (fPrefs.prefArrayDeepIndent)
|
||||||
return setFirstElementAlignment(pos, bound);
|
return setFirstElementAlignment(pos, bound);
|
||||||
else
|
else
|
||||||
|
@ -1517,8 +1518,7 @@ public final class CIndenter {
|
||||||
|
|
||||||
// normal: skip to the statement start before the scope introducer
|
// normal: skip to the statement start before the scope introducer
|
||||||
// opening braces are often on differently ending indents than e.g. a method definition
|
// opening braces are often on differently ending indents than e.g. a method definition
|
||||||
if (looksLikeArrayInitializerIntro() && !fPrefs.prefIndentBracesForArrays
|
if (!looksLikeArrayInitializerIntro && !fPrefs.prefIndentBracesForBlocks) {
|
||||||
|| !fPrefs.prefIndentBracesForBlocks) {
|
|
||||||
fPosition= pos; // restore
|
fPosition= pos; // restore
|
||||||
return skipToStatementStart(true, true); // set to true to match the first if
|
return skipToStatementStart(true, true); // set to true to match the first if
|
||||||
} else {
|
} else {
|
||||||
|
@ -1564,13 +1564,27 @@ public final class CIndenter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the next token received after calling
|
* 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
|
* @return <code>true</code> if the next elements look like the start of an array definition
|
||||||
*/
|
*/
|
||||||
private boolean looksLikeArrayInitializerIntro() {
|
private boolean looksLikeArrayInitializerIntro() {
|
||||||
|
int pos= fPosition;
|
||||||
nextToken();
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue