Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java28
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java68
2 files changed, 87 insertions, 9 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 55a12ef109..1e402ba02b 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
@@ -1784,10 +1784,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
options.fSpaceBeforeSeparator = preferences.insert_space_before_comma_in_template_parameters;
formatList(Arrays.asList(templateParameters), options, false, false, null);
}
- scribe.printNextToken(new int[] { Token.tGT, Token.tSHIFTR },
- preferences.insert_space_before_closing_angle_bracket_in_template_parameters);
- if (preferences.insert_space_after_closing_angle_bracket_in_template_parameters) {
- scribe.space();
+ int nextToken = peekNextToken();
+ if (nextToken == Token.tGT || nextToken == Token.tSHIFTR) {
+ scribe.printNextToken(new int[] { Token.tGT, Token.tSHIFTR },
+ preferences.insert_space_before_closing_angle_bracket_in_template_parameters);
+ if (preferences.insert_space_after_closing_angle_bracket_in_template_parameters) {
+ scribe.space();
+ }
}
// Declaration
@@ -3566,9 +3569,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(ICPPASTTemplateId node) {
IASTName name = node.getTemplateName();
name.accept(this);
- scribe.printNextToken(Token.tLT, preferences.insert_space_before_opening_angle_bracket_in_template_arguments);
- if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) {
- scribe.space();
+ if (peekNextToken() == Token.tLT) {
+ scribe.printNextToken(Token.tLT,
+ preferences.insert_space_before_opening_angle_bracket_in_template_arguments);
+ if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) {
+ scribe.space();
+ }
}
final IASTNode[] templateArguments = node.getTemplateArguments();
if (templateArguments.length > 0) {
@@ -3586,9 +3592,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP;
}
- scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
-
int nextToken = peekNextToken();
+
+ if (nextToken == Token.tGT)
+ scribe.printNextToken(Token.tGT,
+ preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
+
+ nextToken = peekNextToken();
if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME || nextToken == Token.tGT) {
if (nextToken == Token.tLPAREN) {
if (preferences.insert_space_before_opening_paren_in_method_invocation)
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 6281ffe14f..d17b169fa6 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
@@ -3690,4 +3690,72 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDoeNotFormatInactiveCodeEntireFile() throws Exception {
assertFormatterResult();
}
+
+ //#define MYTMPL template<typename T>
+ //MYTMPL
+ //class Foo {
+ //};
+
+ //#define MYTMPL template<typename T>
+ //MYTMPL
+ //class Foo {
+ //};
+ public void testTemplateIdWithMacro1_Bug462566() throws Exception {
+ assertFormatterResult();
+ }
+
+ //template<typename T>
+ //struct myvec {
+ //};
+ //#define vi myvec<int>
+ //vi v;
+
+ //template<typename T>
+ //struct myvec {
+ //};
+ //#define vi myvec<int>
+ //vi v;
+ public void testTemplateIdWithMacro2_Bug462566() throws Exception {
+ assertFormatterResult();
+ }
+
+ //#define FOREACH_BAD for( Foreach_bad<int> fe; fe.i; ++fe.i )
+ //void bar() {
+ // FOREACH_BAD
+ // {
+ // printf("loop body\n");
+ // }
+ //}
+
+ //#define FOREACH_BAD for( Foreach_bad<int> fe; fe.i; ++fe.i )
+ //void bar() {
+ // FOREACH_BAD
+ // {
+ // printf("loop body\n");
+ // }
+ //}
+ public void testTemplateIdWithMacro3_Bug406231() throws Exception {
+ assertFormatterResult();
+ }
+
+ //#define ForIndex(I,N) for (int I=0;I<int(N);I++)
+ //int foo() {
+ // int s = 0;
+ // ForIndex(i, 10)
+ // {
+ // s += i;
+ // }
+ //}
+
+ //#define ForIndex(I,N) for (int I=0;I<int(N);I++)
+ //int foo() {
+ // int s = 0;
+ // ForIndex(i, 10)
+ // {
+ // s += i;
+ // }
+ //}
+ public void testTemplateIdWithMacro4_Bug406231() throws Exception {
+ assertFormatterResult();
+ }
}

Back to the top