mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 361768 - Fix formatting of multiple empty macros
Change-Id: I9ba68533ce65de3309eb8d2186b2488985f457d2 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
280c0190d2
commit
d1bd979a00
2 changed files with 30 additions and 1 deletions
|
@ -4175,6 +4175,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isEmptyStatement(IASTNode node) {
|
||||
IASTNodeLocation[] locations = node.getNodeLocations();
|
||||
if (locations.length == 1 && node instanceof ASTNode) {
|
||||
ASTNode statement = (ASTNode) node;
|
||||
IASTFileLocation fileLocation = locations[0].asFileLocation();
|
||||
return fileLocation.getNodeLength() == 1 && fileLocation.getNodeOffset() == statement.getOffset();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean startsWithMacroExpansion(IASTNode node) {
|
||||
if (fInsideMacroArguments)
|
||||
return false;
|
||||
|
@ -4388,7 +4398,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
final int indentLevel = scribe.indentationLevel;
|
||||
for (int i = 1; i < statementsLength - 1; i++) {
|
||||
final IASTStatement statement = statements.get(i);
|
||||
if (!(statement instanceof IASTNullStatement)
|
||||
if ((!(statement instanceof IASTNullStatement) || isEmptyStatement(statement))
|
||||
&& !doNodeLocationsOverlap(statement, statements.get(i - 1))) {
|
||||
scribe.startNewLine();
|
||||
}
|
||||
|
|
|
@ -3891,6 +3891,25 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//#define EMPTY1(x)
|
||||
//#define EMPTY2(x)
|
||||
//int main() {
|
||||
// EMPTY1(bool x = true);
|
||||
// EMPTY2(bool x = true);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
//#define EMPTY1(x)
|
||||
//#define EMPTY2(x)
|
||||
//int main() {
|
||||
// EMPTY1(bool x = true);
|
||||
// EMPTY2(bool x = true);
|
||||
// return 0;
|
||||
//}
|
||||
public void testEmptyMacros_Bug361768() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//#define START_SECTION() do { int a = 0; } while (0)
|
||||
//void code() {
|
||||
// START_SECTION();
|
||||
|
|
Loading…
Add table
Reference in a new issue