Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2010-01-15 11:37:13 +0000
committerAnton Leherbauer2010-01-15 11:37:13 +0000
commit30815580cde9fd26554f4c90111e288a8992bebd (patch)
treedc3c263f1747e3f92489ebef7b62a443dd295721
parentd49468089ed6ba355c59d49aac8b905f01fe8578 (diff)
downloadorg.eclipse.cdt-30815580cde9fd26554f4c90111e288a8992bebd.tar.gz
org.eclipse.cdt-30815580cde9fd26554f4c90111e288a8992bebd.tar.xz
org.eclipse.cdt-30815580cde9fd26554f4c90111e288a8992bebd.zip
Bug 285901 - Format function does not work properly when define constant to type cast
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java11
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java9
2 files changed, 18 insertions, 2 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 3f6c4798411..a3715705091 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
@@ -1892,8 +1892,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.space();
}
node.getTypeId().accept(this);
- scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast);
- if (preferences.insert_space_after_closing_paren_in_cast) {
+ try {
+ if (node.getTypeId().getTrailingSyntax().getType() == IToken.tRPAREN) {
+ scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_cast);
+ if (preferences.insert_space_after_closing_paren_in_cast) {
+ scribe.space();
+ }
+ }
+ } catch (UnsupportedOperationException exc) {
+ } catch (ExpansionOverlapsBoundaryException exc) {
scribe.space();
}
// operand
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 f269a610ed2..e0242f1543c 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
@@ -1265,4 +1265,13 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testWideStringLiteral_Bug292626() throws Exception {
assertFormatterResult();
}
+
+ //#define INT (int)
+ //int i = INT 1;
+
+ //#define INT (int)
+ //int i = INT 1;
+ public void testCastAsMacro_Bug285901() throws Exception {
+ assertFormatterResult();
+ }
}

Back to the top