mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 350816 - [formatter] Fixed size array declaration formats wrong
This commit is contained in:
parent
b7382e51f1
commit
0ab89e9c79
2 changed files with 23 additions and 2 deletions
|
@ -1603,8 +1603,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
private int visit(IASTArrayDeclarator node) {
|
private int visit(IASTArrayDeclarator node) {
|
||||||
IASTArrayModifier[] arrayModifiers= node.getArrayModifiers();
|
IASTArrayModifier[] arrayModifiers= node.getArrayModifiers();
|
||||||
if (arrayModifiers != null) {
|
if (arrayModifiers != null) {
|
||||||
for (IASTArrayModifier arrayModifier2 : arrayModifiers) {
|
for (IASTArrayModifier arrayModifier : arrayModifiers) {
|
||||||
IASTArrayModifier arrayModifier = arrayModifier2;
|
|
||||||
scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket);
|
scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket);
|
||||||
boolean emptyBrackets= arrayModifier.getConstantExpression() == null
|
boolean emptyBrackets= arrayModifier.getConstantExpression() == null
|
||||||
&& !(arrayModifier instanceof ICASTArrayModifier);
|
&& !(arrayModifier instanceof ICASTArrayModifier);
|
||||||
|
@ -1625,10 +1624,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||||
try {
|
try {
|
||||||
arrayModifier.accept(this);
|
arrayModifier.accept(this);
|
||||||
} catch (ASTProblemException e) {
|
} catch (ASTProblemException e) {
|
||||||
scribe.skipToToken(Token.tRBRACKET);
|
scribe.skipToToken(Token.tRBRACKET);
|
||||||
|
} finally {
|
||||||
|
scribe.setTailFormatter(tailFormatter);
|
||||||
}
|
}
|
||||||
boolean insertSpace= emptyBrackets ?
|
boolean insertSpace= emptyBrackets ?
|
||||||
preferences.insert_space_between_empty_brackets :
|
preferences.insert_space_between_empty_brackets :
|
||||||
|
|
|
@ -2518,4 +2518,23 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
String expected= before;
|
String expected= before;
|
||||||
assertFormatterResult(before, expected);
|
assertFormatterResult(before, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#define SIZE 5
|
||||||
|
//char s0[5];
|
||||||
|
//char s1[1+1];
|
||||||
|
//char s2[SIZE];
|
||||||
|
//char s3[SIZE+1];
|
||||||
|
//char s4[SIZE+SIZE];
|
||||||
|
//char s5[1+SIZE];
|
||||||
|
|
||||||
|
//#define SIZE 5
|
||||||
|
//char s0[5];
|
||||||
|
//char s1[1 + 1];
|
||||||
|
//char s2[SIZE];
|
||||||
|
//char s3[SIZE + 1];
|
||||||
|
//char s4[SIZE + SIZE];
|
||||||
|
//char s5[1 + SIZE];
|
||||||
|
public void testExpressionInArrayDeclarator_Bug350816() throws Exception {
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue