Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-03-09 12:07:08 -0500
committerJonah Graham2019-04-08 12:52:36 -0400
commitd1bd979a00673bcb6fcaa001200ee32cf3def041 (patch)
tree38f7fdc2da815bca4de6c9847edf9dd53c5cd215 /core/org.eclipse.cdt.core
parent280c0190d2e4ff33ed35135a011d934e15cb1c64 (diff)
downloadorg.eclipse.cdt-d1bd979a00673bcb6fcaa001200ee32cf3def041.tar.gz
org.eclipse.cdt-d1bd979a00673bcb6fcaa001200ee32cf3def041.tar.xz
org.eclipse.cdt-d1bd979a00673bcb6fcaa001200ee32cf3def041.zip
Bug 361768 - Fix formatting of multiple empty macros
Change-Id: I9ba68533ce65de3309eb8d2186b2488985f457d2 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index 20350cc9f6..78dca997d4 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -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();
}

Back to the top