mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 509150 - Formatter fails on nested template IDs
Fix for exception in deeply nested template IDs + test Change-Id: I0c158599c5b8c974823a400251d76ff441b795f3 Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
10428dd53a
commit
b9baf5b478
2 changed files with 74 additions and 15 deletions
|
@ -401,7 +401,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
private boolean fExpectSemicolonAfterDeclaration= true;
|
||||
|
||||
private MultiStatus fStatus;
|
||||
private int fOpenAngleBrackets;
|
||||
private IASTTranslationUnit ast;
|
||||
|
||||
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, int offset, int length) {
|
||||
|
@ -3470,7 +3469,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) {
|
||||
scribe.space();
|
||||
}
|
||||
int angleBrackets = fOpenAngleBrackets++;
|
||||
final IASTNode[] templateArguments= node.getTemplateArguments();
|
||||
if (templateArguments.length > 0) {
|
||||
final ListOptions options= new ListOptions(Alignment.M_COMPACT_SPLIT);
|
||||
|
@ -3480,20 +3478,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatList(Arrays.asList(templateArguments), options, false, false, null);
|
||||
}
|
||||
if (peekNextToken() == Token.tSHIFTR) {
|
||||
if (fOpenAngleBrackets == angleBrackets + 2) {
|
||||
fOpenAngleBrackets -= 2;
|
||||
scribe.printNextToken(Token.tSHIFTR, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
|
||||
} else {
|
||||
scribe.printComment();
|
||||
if (preferences.insert_space_before_closing_angle_bracket_in_template_arguments) {
|
||||
scribe.space();
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
scribe.printComment();
|
||||
if (preferences.insert_space_before_closing_angle_bracket_in_template_arguments) {
|
||||
scribe.space();
|
||||
}
|
||||
} else {
|
||||
--fOpenAngleBrackets;
|
||||
scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
|
||||
|
||||
int nextToken= peekNextToken();
|
||||
if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME || nextToken == Token.tGT) {
|
||||
if (nextToken == Token.tLPAREN) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2015 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2016 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -3130,4 +3130,70 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
public void testLineCommentAsBlocks8() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int>>>tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int>>>>tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>>tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>>>tpl6_int { };
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int>>> tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int>>>> tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>> tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>>> tpl6_int { };
|
||||
public void testNestedTemplates_509150() throws Exception {
|
||||
fOptions.put(
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TEMPLATE_ARGUMENTS,
|
||||
CCorePlugin.DO_NOT_INSERT);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int>>>tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int>>>>tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>>tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int>>>>>>tpl6_int { };
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int > > > tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int > > > > tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int > > > > > tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int > > > > > > tpl6_int { };
|
||||
public void testNestedTemplatesWithSpaces_509150() throws Exception {
|
||||
fOptions.put(
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TEMPLATE_ARGUMENTS,
|
||||
CCorePlugin.INSERT);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int>> > tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int>>> >tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int>> >> >tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int>>> >> >tpl6_int { };
|
||||
|
||||
//template<typename T>
|
||||
//struct Tpl {
|
||||
//};
|
||||
//Tpl<Tpl<Tpl<int>> > tpl3_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<int>>> > tpl4_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<int>> >> > tpl5_int { };
|
||||
//Tpl<Tpl<Tpl<Tpl<Tpl<Tpl<int>>> >> > tpl6_int { };
|
||||
public void testNestedTemplatesMixedSpacingUnchanged_509150() throws Exception {
|
||||
fOptions.put(
|
||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TEMPLATE_ARGUMENTS,
|
||||
CCorePlugin.DO_NOT_INSERT);
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue