Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-03-09 17:07:08 +0000
committerJonah Graham2019-04-08 16:52:36 +0000
commitd1bd979a00673bcb6fcaa001200ee32cf3def041 (patch)
tree38f7fdc2da815bca4de6c9847edf9dd53c5cd215
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>
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java12
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java19
2 files changed, 30 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 20350cc9f63..78dca997d49 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();
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index b4121dbfc3f..31745c52ec3 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -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();

Back to the top