mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Bug 328356 - [C++0x] Editor support for range-based for
This commit is contained in:
parent
e5328c3106
commit
679eb0d976
3 changed files with 47 additions and 2 deletions
|
@ -117,6 +117,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
|
@ -622,6 +623,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
visit((IASTDeclarationStatement)node);
|
||||
} else if (node instanceof IASTForStatement) {
|
||||
visit((IASTForStatement)node);
|
||||
} else if (node instanceof ICPPASTRangeBasedForStatement) {
|
||||
visit((ICPPASTRangeBasedForStatement) node);
|
||||
} else if (node instanceof IASTIfStatement) {
|
||||
visit((IASTIfStatement)node);
|
||||
} else if (node instanceof ICPPASTCatchHandler) {
|
||||
|
@ -2489,6 +2492,34 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatAction(line, node.getBody(), preferences.brace_position_for_block);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private int visit(ICPPASTRangeBasedForStatement node) {
|
||||
scribe.printNextToken(Token.t_for);
|
||||
final int line = scribe.line;
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
|
||||
fInsideFor= true;
|
||||
try {
|
||||
if (preferences.insert_space_after_opening_paren_in_for) {
|
||||
scribe.space();
|
||||
}
|
||||
IASTDeclaration declaration = node.getDeclaration();
|
||||
declaration.accept(this);
|
||||
scribe.printNextToken(Token.tCOLON, true /* preferences.insert_space_before_colon_in_for */);
|
||||
final IASTInitializerClause initializer = node.getInitializerClause();
|
||||
if (true /*preferences.insert_space_after_colon_in_for*/) {
|
||||
scribe.space();
|
||||
}
|
||||
initializer.accept(this);
|
||||
} finally {
|
||||
fInsideFor= false;
|
||||
}
|
||||
if (peekNextToken() == Token.tRPAREN) {
|
||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
|
||||
}
|
||||
|
||||
formatAction(line, node.getBody(), preferences.brace_position_for_block);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private int visit(IASTIfStatement node) {
|
||||
scribe.printNextToken(Token.t_if);
|
||||
|
|
|
@ -1396,4 +1396,16 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {int array[5] = { 1, 2, 3, 4, 5 };for (int& x:array) x *= 2;}
|
||||
|
||||
//void f() {
|
||||
// int array[5] = { 1, 2, 3, 4, 5 };
|
||||
// for (int& x : array)
|
||||
// x *= 2;
|
||||
//}
|
||||
public void testRangeBasedFor_Bug328472() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2010 IBM Corporation 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
|
||||
|
@ -77,6 +77,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -211,7 +212,8 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
if (statement instanceof IASTForStatement
|
||||
|| statement instanceof IASTWhileStatement
|
||||
|| statement instanceof IASTDoStatement
|
||||
|| statement instanceof IASTSwitchStatement) {
|
||||
|| statement instanceof IASTSwitchStatement
|
||||
|| statement instanceof ICPPASTRangeBasedForStatement) {
|
||||
fl = statement.getFileLocation();
|
||||
mr.setLength(fl.getNodeLength());
|
||||
mr.setOffset(fl.getNodeOffset());
|
||||
|
|
Loading…
Add table
Reference in a new issue