Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-03-15 18:34:29 -0400
committerSergey Prigogin2011-03-15 18:34:29 -0400
commit2ce87d555ec826063e72467a0293742981d7f74a (patch)
tree1b41b7cead5af111ff2affb39f800c16c598e67f
parent20e305dee7bd9881e989be3743a7117900cb007a (diff)
downloadorg.eclipse.cdt-2ce87d555ec826063e72467a0293742981d7f74a.tar.gz
org.eclipse.cdt-2ce87d555ec826063e72467a0293742981d7f74a.tar.xz
org.eclipse.cdt-2ce87d555ec826063e72467a0293742981d7f74a.zip
Fixed formatting of C++-style casts and template function calls.
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java16
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java54
2 files changed, 63 insertions, 7 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 16fcb75356..5cc81b81fd 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
@@ -2314,7 +2314,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
node.getTypeId().accept(this);
scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
- if (preferences.insert_space_after_closing_angle_bracket_in_template_arguments) {
+ if (preferences.insert_space_before_opening_paren_in_method_invocation) {
scribe.space();
}
// operand
@@ -3235,8 +3235,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
int nextToken= peekNextToken();
if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME || nextToken == Token.tGT) {
- if (preferences.insert_space_after_closing_angle_bracket_in_template_arguments) {
- // avoid explicit space if followed by pointer operator
+ if (node.getParent().getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME &&
+ preferences.insert_space_before_opening_paren_in_method_invocation) {
+ scribe.space();
+ } else if (node.getParent().getPropertyInParent() != IASTFunctionCallExpression.FUNCTION_NAME &&
+ preferences.insert_space_after_closing_angle_bracket_in_template_arguments) {
+ // Avoid explicit space if followed by '*' or '&'.
if (nextToken != Token.tSTAR && nextToken != Token.tAMPER) {
scribe.space();
}
@@ -3253,12 +3257,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printNextToken(Token.t_return);
final IASTExpression expression = node.getReturnValue();
if (expression != null) {
-// if (peekNextToken() != Token.tLPAREN) {
- scribe.space();
-// }
+ scribe.space();
expression.accept(this);
}
- // sometimes the return expression is null, when it should not
+ // Sometimes the return expression is null, when it should not be.
if (expression == null && Token.tSEMI != peekNextToken()) {
scribe.skipToToken(Token.tSEMI);
}
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 b0a1b5b7e8..575456c313 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
@@ -1079,6 +1079,60 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
+ //int x=static_cast < int > ( 0 ) ;
+
+ //int x = static_cast<int>(0);
+ public void testCppCast_1() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
+ assertFormatterResult();
+ }
+
+ //int x=static_cast < int >( 0 ) ;
+
+ //int x = static_cast<int> (0);
+ public void testCppCast_2() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_INVOCATION, CCorePlugin.INSERT);
+ assertFormatterResult();
+ }
+
+ //template < typename T >
+ //void foo ( T t ) ;
+ //
+ //void test() {
+ //foo < const char* > ( "" ) ;
+ //}
+
+ //template<typename T>
+ //void foo(T t);
+ //
+ //void test() {
+ // foo<const char*>("");
+ //}
+ public void testTemplateFunctionCall_1() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
+ assertFormatterResult();
+ }
+
+ //template < typename T >
+ //void foo ( T t ) ;
+ //
+ //void test() {
+ //foo < const char* >( "" ) ;
+ //}
+
+ //template<typename T>
+ //void foo(T t);
+ //
+ //void test() {
+ // foo<const char*> ("");
+ //}
+ public void testTemplateFunctionCall_2() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_INVOCATION, CCorePlugin.INSERT);
+ assertFormatterResult();
+ }
+
//#define MY_MACRO int a; \
// int b; \
// int c();

Back to the top