mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 02:05:39 +02:00
Fixed formatting of C++-style casts and template function calls.
This commit is contained in:
parent
20e305dee7
commit
2ce87d555e
2 changed files with 63 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue