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 95dec14503c..d67880beecb 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 @@ -2382,7 +2382,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } IASTExpression condExpr= node.getConditionExpression(); - if (condExpr instanceof IASTProblemExpression) { + if (condExpr == null || condExpr instanceof IASTProblemExpression) { scribe.skipToToken(Token.tRPAREN); } else { condExpr.accept(this); @@ -2500,7 +2500,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { // destructor scribe.printNextToken(Token.tCOMPL, false); } - scribe.printNextToken(Token.tIDENTIFIER, false); + names[names.length-1].accept(this); return PROCESS_SKIP; } @@ -2519,10 +2519,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor { formatList(Arrays.asList(templateArguments), align, false, false); } scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments); - if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) { + 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 - int nextToken= peekNextToken(); if (nextToken != Token.tSTAR && nextToken != Token.tAMPER) { scribe.space(); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index 20c6b1fdfb7..ca00e95944d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -1618,6 +1618,14 @@ public class Scribe { } int braceLevel= 0; int parenLevel= 0; + switch (expectedTokenType) { + case Token.tRBRACE: + ++braceLevel; + break; + case Token.tRPAREN: + ++parenLevel; + break; + } while ((currentToken= scanner.nextToken()) != null) { switch (currentToken.type) { case Token.tLBRACE: 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 9ed82a8d44c..26812fccad0 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 @@ -760,4 +760,36 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //void A::a(C e) { if (D::iterator it = m.find (e)) m.erase(it);} + //T* A::b(T* t) { S::iterator it = m.find(t); if (!it) return NULL; else return *it; } + //M* A::c(M* tm) { N::iterator it = myN.find(tm); if (!it) return NULL; else return *it; } + + //void A::a(C e) { + // if (D::iterator it = m.find (e)) + // m.erase(it); + //} + //T* A::b(T* t) { + // S::iterator it = m.find(t); + // if (!it) + // return NULL; + // else + // return *it; + //} + //M* A::c(M* tm) { + // N::iterator it = myN.find(tm); + // if (!it) + // return NULL; + // else + // return *it; + //} + public void testHandleParsingProblemsInIfCondition_Bug240564() throws Exception { + assertFormatterResult(); + } + + //TestType1 > test_variable; + + //TestType1 > test_variable; + public void testNestedTemplatedArgument_Bug241058() throws Exception { + assertFormatterResult(); + } }