mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
Refurbished change generator tests:
- Moved tests from separate files to categorized files. - Introduced node factory in base class. - Removed use of specific classes, replaced with interaces. - Moved some tests to apropriate suites. Change-Id: I71557c0132b888bdc22788f545fec3b03aa732c2 Signed-off-by: Thomas Corbat <tcorbat@hsr.ch> Reviewed-on: https://git.eclipse.org/r/32251 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
67a5a4b31f
commit
18bbc00489
66 changed files with 2047 additions and 4127 deletions
|
@ -20,10 +20,6 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests,
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite,
|
org.eclipse.cdt.core.parser.tests.rewrite,
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.astwriter,
|
org.eclipse.cdt.core.parser.tests.rewrite.astwriter,
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator,
|
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator,
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append,
|
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore,
|
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove,
|
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace,
|
|
||||||
org.eclipse.cdt.core.parser.tests.rewrite.comenthandler,
|
org.eclipse.cdt.core.parser.tests.rewrite.comenthandler,
|
||||||
org.eclipse.cdt.core.parser.tests.scanner,
|
org.eclipse.cdt.core.parser.tests.scanner,
|
||||||
org.eclipse.cdt.core.resources.tests,
|
org.eclipse.cdt.core.resources.tests,
|
||||||
|
|
|
@ -0,0 +1,504 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
|
* Rapperswil, University of applied sciences 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Institute for Software - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
|
|
||||||
|
import static org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind.APPEND_CHILD;
|
||||||
|
import static org.eclipse.cdt.core.dom.ast.IASTLiteralExpression.lk_integer_constant;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||||
|
|
||||||
|
public class AppendTests extends ChangeGeneratorTest {
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return new TestSuite(AppendTests.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *pi[5];
|
||||||
|
|
||||||
|
//int *pi[5][3];
|
||||||
|
public void testArrayModifier() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof IASTArrayDeclarator) {
|
||||||
|
IASTExpression expr = factory.newLiteralExpression(lk_integer_constant, "3");
|
||||||
|
IASTArrayModifier newModifier = factory.newArrayModifier(expr);
|
||||||
|
addModification(null, APPEND_CHILD, declarator, newModifier);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *values = new int[6];
|
||||||
|
|
||||||
|
//int *values = new int[6][5];
|
||||||
|
public void testArraySizeExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTTypeId id = newExpression.getTypeId();
|
||||||
|
IASTArrayDeclarator dtor = (IASTArrayDeclarator) id.getAbstractDeclarator();
|
||||||
|
IASTArrayModifier[] mods = dtor.getArrayModifiers();
|
||||||
|
IASTExpression expr = factory.newLiteralExpression(lk_integer_constant, "5");
|
||||||
|
IASTArrayModifier add = factory.newArrayModifier(expr);
|
||||||
|
addModification(null, APPEND_CHILD, dtor, add);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a, int b) :
|
||||||
|
// beta(b) {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a, int b) :
|
||||||
|
// beta(b), alpha(a) {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
public void testCtorChainInitializer() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclaration decl) {
|
||||||
|
if (decl instanceof ICPPASTFunctionDefinition) {
|
||||||
|
IASTIdExpression idExpression = factory.newIdExpression(factory.newName("a".toCharArray()));
|
||||||
|
IASTInitializer initExpr = factory.newConstructorInitializer(new IASTInitializerClause[] { idExpression });
|
||||||
|
IASTName initName = factory.newName("alpha".toCharArray());
|
||||||
|
ICPPASTConstructorChainInitializer newInitializer = factory.newConstructorChainInitializer(initName, initExpr);
|
||||||
|
addModification(null, APPEND_CHILD, decl, newInitializer);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (int) {
|
||||||
|
//}
|
||||||
|
public void testException() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTDeclarator exceptionDeclarator = factory.newDeclarator(factory.newName());
|
||||||
|
ICPPASTSimpleDeclSpecifier exDeclSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTTypeId exception = factory.newTypeId(exDeclSpec, exceptionDeclarator);
|
||||||
|
addModification(null, APPEND_CHILD, declarator, exception);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, h = 5;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, h = 5, c = 9;
|
||||||
|
//}
|
||||||
|
public void testExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof IASTExpressionList) {
|
||||||
|
IASTName name = factory.newName("c".toCharArray());
|
||||||
|
IASTIdExpression leftOperand = factory.newIdExpression(name);
|
||||||
|
ICPPASTLiteralExpression rightOperand = factory.newLiteralExpression(lk_integer_constant, "9");
|
||||||
|
ICPPASTBinaryExpression binEx = factory.newBinaryExpression(IASTBinaryExpression.op_assign, leftOperand, rightOperand);
|
||||||
|
addModification(null, APPEND_CHILD, expression, binEx);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(bool cond1, bool cond2) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(bool cond1, bool cond2) {
|
||||||
|
// if (cond1) {
|
||||||
|
// } else if (cond2) {
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testNestedElseifStatement() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
IASTIdExpression elseIfCondition = factory.newIdExpression(factory.newName("cond2".toCharArray()));
|
||||||
|
IASTStatement elseIfThen = factory.newCompoundStatement();
|
||||||
|
IASTIfStatement elseIfStatement = factory.newIfStatement(elseIfCondition, elseIfThen, null);
|
||||||
|
|
||||||
|
IASTIdExpression ifCondition = factory.newIdExpression(factory.newName("cond1".toCharArray()));
|
||||||
|
IASTStatement ifThen = factory.newCompoundStatement();
|
||||||
|
IASTIfStatement ifStatement = factory.newIfStatement(ifCondition, ifThen, elseIfStatement);
|
||||||
|
|
||||||
|
addModification(null, APPEND_CHILD, statement, ifStatement);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int existing) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int existing, int newParameter) {
|
||||||
|
//}
|
||||||
|
public void testParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
IASTName parameterName = factory.newName("newParameter".toCharArray());
|
||||||
|
ICPPASTDeclarator paramDeclarator = factory.newDeclarator(parameterName);
|
||||||
|
paramDeclarator.setName(parameterName);
|
||||||
|
ICPPASTSimpleDeclSpecifier declSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
declSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
ICPPASTParameterDeclaration insertedParameter = factory.newParameterDeclaration(declSpec, paramDeclarator);
|
||||||
|
addModification(null, APPEND_CHILD, declarator, insertedParameter);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int newParameter) {
|
||||||
|
//}
|
||||||
|
public void testParameterToList() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
IASTName parameterName = factory.newName("newParameter".toCharArray());
|
||||||
|
ICPPASTDeclarator parameterDeclarator = factory.newDeclarator(parameterName);
|
||||||
|
ICPPASTSimpleDeclSpecifier parameterDeclSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
ICPPASTParameterDeclaration insertedParameter = factory.newParameterDeclaration(parameterDeclSpec, parameterDeclarator);
|
||||||
|
addModification(null, APPEND_CHILD, declarator, insertedParameter);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int *parameter) {
|
||||||
|
//}
|
||||||
|
public void testPointerToParamter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTDeclarator paramDeclarator = curParam.getDeclarator();
|
||||||
|
IASTName name = paramDeclarator.getName();
|
||||||
|
if (name.toString().equals("parameter")) {
|
||||||
|
IASTPointer addedPointer = factory.newPointer();
|
||||||
|
addModification(null, APPEND_CHILD, paramDeclarator, addedPointer);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int *parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int **parameter) {
|
||||||
|
//}
|
||||||
|
public void testPointerToPointerParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTDeclarator paramDeclarator = curParam.getDeclarator();
|
||||||
|
IASTName name = paramDeclarator.getName();
|
||||||
|
if (name.toString().equals("parameter")) {
|
||||||
|
IASTPointer addedPointer = factory.newPointer();
|
||||||
|
addModification(null, APPEND_CHILD, paramDeclarator, addedPointer);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//class A
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int help();
|
||||||
|
//};
|
||||||
|
|
||||||
|
//class A
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// A();
|
||||||
|
// virtual ~A();
|
||||||
|
// int foo();
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int help();
|
||||||
|
// int exp(int i);
|
||||||
|
//};
|
||||||
|
public void testAddDeclarationBugTest() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclSpecifiers = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
|
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
|
IASTSimpleDeclSpecifier returnType = factory.newSimpleDeclSpecifier();
|
||||||
|
returnType.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTSimpleDeclaration functionDeclaration = factory.newSimpleDeclaration(returnType);
|
||||||
|
|
||||||
|
IASTName functionName = factory.newName("exp".toCharArray());
|
||||||
|
IASTStandardFunctionDeclarator declarator = factory.newFunctionDeclarator(functionName);
|
||||||
|
IASTSimpleDeclSpecifier paramType = factory.newSimpleDeclSpecifier();
|
||||||
|
paramType.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTName paramName = factory.newName("i".toCharArray());
|
||||||
|
IASTDeclarator decl = factory.newDeclarator(paramName);
|
||||||
|
ICPPASTParameterDeclaration param = factory.newParameterDeclaration(paramType, decl);
|
||||||
|
declarator.addParameterDeclaration(param);
|
||||||
|
functionDeclaration.addDeclarator(declarator);
|
||||||
|
|
||||||
|
addModification(null, APPEND_CHILD, declSpec, functionDeclaration);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
// int i;
|
||||||
|
// int j;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testMultilineWhitespaceHandling() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTForStatement) {
|
||||||
|
IASTForStatement forStatement = (IASTForStatement) statement;
|
||||||
|
IASTStatement compoundStatement = forStatement.getBody();
|
||||||
|
|
||||||
|
addIntDeclaration(modStore, compoundStatement, "i");
|
||||||
|
addIntDeclaration(modStore, compoundStatement, "j");
|
||||||
|
}
|
||||||
|
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addIntDeclaration(final ASTModificationStore modStore, IASTStatement compoundStatement,
|
||||||
|
String variableName) {
|
||||||
|
ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier = factory.newSimpleDeclSpecifier();
|
||||||
|
newSimpleDeclSpecifier.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTSimpleDeclaration newSimpleDeclaration = factory.newSimpleDeclaration(newSimpleDeclSpecifier);
|
||||||
|
newSimpleDeclaration.addDeclarator(factory.newDeclarator(factory.newName(variableName.toCharArray())));
|
||||||
|
IASTDeclarationStatement newDeclaration = factory.newDeclarationStatement(newSimpleDeclaration);
|
||||||
|
|
||||||
|
addModification(null, APPEND_CHILD, compoundStatement, newDeclaration);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for(int i = 0; i < 10; i++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testAppendNull() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
addModification(null, APPEND_CHILD, statement, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
// for (int i = 0; i < 10; i++) {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
public void testSelfInsertion() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTForStatement) {
|
||||||
|
IASTForStatement forStatement = (IASTForStatement) statement;
|
||||||
|
IASTStatement compoundStatement = forStatement.getBody();
|
||||||
|
addModification(null, APPEND_CHILD, compoundStatement, forStatement);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -11,13 +11,22 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
|
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
|
||||||
|
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||||
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
||||||
|
@ -31,8 +40,8 @@ import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||||
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
import org.eclipse.ltk.core.refactoring.TextFileChange;
|
||||||
|
|
||||||
public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
||||||
protected String source;
|
protected ASTModificationStore modStore;
|
||||||
protected String expectedSource;
|
protected final ICPPNodeFactory factory = CPPNodeFactory.getDefault();
|
||||||
|
|
||||||
public ChangeGeneratorTest() {
|
public ChangeGeneratorTest() {
|
||||||
super();
|
super();
|
||||||
|
@ -44,45 +53,54 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
modStore = new ASTModificationStore();
|
||||||
CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
|
CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runTest() throws Exception {
|
|
||||||
final ASTModificationStore modStore = new ASTModificationStore();
|
|
||||||
IFile testFile = importFile("source.h", source); //$NON-NLS-1$
|
|
||||||
|
|
||||||
ASTVisitor visitor = createModificator(modStore);
|
|
||||||
|
|
||||||
CCorePlugin.getIndexManager().reindex(cproject);
|
|
||||||
|
|
||||||
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
|
|
||||||
|
|
||||||
waitForIndexer(cproject);
|
|
||||||
|
|
||||||
IASTTranslationUnit unit = CoreModelUtil.findTranslationUnit(testFile).getAST();
|
|
||||||
final ChangeGenerator changeGenerator =
|
|
||||||
new ChangeGenerator(modStore, ASTCommenter.getCommentedNodeMap(unit));
|
|
||||||
unit.accept(visitor);
|
|
||||||
|
|
||||||
changeGenerator.generateChange(unit);
|
|
||||||
Document doc = new Document(source);
|
|
||||||
for (Change change : ((CompositeChange) changeGenerator.getChange()).getChildren()) {
|
|
||||||
if (change instanceof TextFileChange) {
|
|
||||||
TextFileChange textChange = (TextFileChange) change;
|
|
||||||
textChange.getEdit().apply(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertEquals(TestHelper.unifyNewLines(expectedSource), TestHelper.unifyNewLines(doc.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract ASTVisitor createModificator(ASTModificationStore modStore);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
System.gc();
|
System.gc();
|
||||||
fileManager.closeAllFiles();
|
fileManager.closeAllFiles();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected StringBuilder[] getTestSource(int sections) throws IOException {
|
||||||
|
return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "parser",
|
||||||
|
getClass(), getName(), sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void compareResult(ASTVisitor visitor) throws Exception {
|
||||||
|
final StringBuilder[] testSources = getTestSource(2);
|
||||||
|
final String source = testSources[0].toString();
|
||||||
|
final String expected = testSources[1].toString();
|
||||||
|
final IFile testFile = importFile("source.h", source); //$NON-NLS-1$
|
||||||
|
|
||||||
|
CCorePlugin.getIndexManager().reindex(cproject);
|
||||||
|
|
||||||
|
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
|
||||||
|
|
||||||
|
waitForIndexer(cproject);
|
||||||
|
|
||||||
|
final IASTTranslationUnit unit = CoreModelUtil.findTranslationUnit(testFile).getAST();
|
||||||
|
final ChangeGenerator changeGenerator =
|
||||||
|
new ChangeGenerator(modStore, ASTCommenter.getCommentedNodeMap(unit));
|
||||||
|
unit.accept(visitor);
|
||||||
|
|
||||||
|
changeGenerator.generateChange(unit);
|
||||||
|
final Document doc = new Document(source);
|
||||||
|
for (Change change : ((CompositeChange) changeGenerator.getChange()).getChildren()) {
|
||||||
|
if (change instanceof TextFileChange) {
|
||||||
|
TextFileChange textChange = (TextFileChange) change;
|
||||||
|
textChange.getEdit().apply(doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(TestHelper.unifyNewLines(expected), TestHelper.unifyNewLines(doc.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ASTModification addModification(ASTModification parentMod, ModificationKind kind, IASTNode targetNode, IASTNode newNode) {
|
||||||
|
ASTModification mod = new ASTModification(kind, targetNode, newNode, null);
|
||||||
|
modStore.storeModification(parentMod, mod);
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -14,23 +14,18 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append.AppendTestSuite;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore.InsertBeforeTestSuite;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove.RemoveTestSuite;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.ReplaceTestSuite;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Thomas Corbat
|
* @author Thomas Corbat
|
||||||
*/
|
*/
|
||||||
public class ChangeGeneratorTestSuite {
|
public class ChangeGeneratorTestSuite {
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
TestSuite suite = new TestSuite("ChangeGeneratorTestSuite");
|
TestSuite suite = new TestSuite(ChangeGeneratorTestSuite.class.getName());
|
||||||
|
|
||||||
suite.addTest(ReplaceTestSuite.suite());
|
suite.addTest(AppendTests.suite());
|
||||||
suite.addTest(RemoveTestSuite.suite());
|
suite.addTest(InsertBeforeTests.suite());
|
||||||
suite.addTest(InsertBeforeTestSuite.suite());
|
suite.addTest(RemoveTests.suite());
|
||||||
suite.addTest(AppendTestSuite.suite());
|
suite.addTest(ReplaceTests.suite());
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,332 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
|
* Rapperswil, University of applied sciences 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Institute for Software - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
|
|
||||||
|
import static org.eclipse.cdt.core.dom.ast.IASTLiteralExpression.lk_integer_constant;
|
||||||
|
import static org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind.INSERT_BEFORE;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
|
||||||
|
|
||||||
|
public class InsertBeforeTests extends ChangeGeneratorTest {
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return new TestSuite(InsertBeforeTests.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//int* pi[3];
|
||||||
|
|
||||||
|
//int* pi[5][3];
|
||||||
|
public void testArrayModifier() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof IASTArrayDeclarator) {
|
||||||
|
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
|
||||||
|
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||||
|
IASTExpression expr = factory.newLiteralExpression(lk_integer_constant, "5");
|
||||||
|
IASTArrayModifier newModifier = factory.newArrayModifier(expr);
|
||||||
|
|
||||||
|
addModification(null, INSERT_BEFORE, modifiers[0], newModifier);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int* values = new int[5];
|
||||||
|
|
||||||
|
//int* values = new int[6][5];
|
||||||
|
public void testArraySizeExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTTypeId id = newExpression.getTypeId();
|
||||||
|
IASTArrayDeclarator dtor = (IASTArrayDeclarator) id.getAbstractDeclarator();
|
||||||
|
IASTArrayModifier[] mods = dtor.getArrayModifiers();
|
||||||
|
ICPPASTLiteralExpression expr = factory.newLiteralExpression(lk_integer_constant, "6");
|
||||||
|
IASTArrayModifier add = factory.newArrayModifier(expr);
|
||||||
|
addModification(null, INSERT_BEFORE, mods[0], add);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a, int b):beta(b) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a, int b) :
|
||||||
|
// alpha(a), beta(b) {
|
||||||
|
//}
|
||||||
|
public void testCtorChainInitializer() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclaration declaration) {
|
||||||
|
if (declaration instanceof ICPPASTFunctionDefinition) {
|
||||||
|
ICPPASTFunctionDefinition functionDefinition = (ICPPASTFunctionDefinition) declaration;
|
||||||
|
ICPPASTConstructorChainInitializer ctorInitializer = functionDefinition.getMemberInitializers()[0];
|
||||||
|
IASTName name = factory.newName("a".toCharArray());
|
||||||
|
IASTIdExpression idExpression = factory.newIdExpression(name);
|
||||||
|
IASTInitializer initExpression = factory.newConstructorInitializer(new IASTInitializerClause[] { idExpression });
|
||||||
|
IASTName initName = factory.newName("alpha".toCharArray());
|
||||||
|
ICPPASTConstructorChainInitializer newInitializer = factory.newConstructorChainInitializer(initName, initExpression);
|
||||||
|
addModification(null, INSERT_BEFORE, ctorInitializer, newInitializer);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (/*Test*/float) /*Test2*/{
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (int, /*Test*/float) /*Test2*/{
|
||||||
|
//}
|
||||||
|
public void testException() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
||||||
|
|
||||||
|
ICPPASTDeclarator exceptionDeclarator = factory.newDeclarator(factory.newName());
|
||||||
|
ICPPASTSimpleDeclSpecifier exDeclSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTTypeId exception = factory.newTypeId(exDeclSpec, exceptionDeclarator);
|
||||||
|
addModification(null, INSERT_BEFORE, existingException, exception);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, h = 5;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, c = 9, h = 5;
|
||||||
|
//}
|
||||||
|
public void testExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof IASTExpressionList) {
|
||||||
|
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
||||||
|
IASTExpression[] expressions = expressionList.getExpressions();
|
||||||
|
IASTName name = factory.newName("c".toCharArray());
|
||||||
|
IASTIdExpression leftOperand = factory.newIdExpression(name);
|
||||||
|
ICPPASTLiteralExpression rightOperand = factory.newLiteralExpression(0, "9");
|
||||||
|
ICPPASTBinaryExpression binEx = factory.newBinaryExpression(IASTBinaryExpression.op_assign, leftOperand, rightOperand);
|
||||||
|
addModification(null, INSERT_BEFORE, expressions[1], binEx);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int a) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int newParameter, int a) {
|
||||||
|
//}
|
||||||
|
public void testFirstParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTDeclarator paramDeclarator = curParam.getDeclarator();
|
||||||
|
if (paramDeclarator.getName().toString().equals("a")) {
|
||||||
|
IASTName parameterName = factory.newName("newParameter".toCharArray());
|
||||||
|
ICPPASTDeclarator newDeclarator = factory.newDeclarator(parameterName);
|
||||||
|
ICPPASTSimpleDeclSpecifier paramDeclSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
paramDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
ICPPASTParameterDeclaration insertedParameter = factory.newParameterDeclaration(paramDeclSpec, newDeclarator);
|
||||||
|
addModification(null, INSERT_BEFORE, curParam, insertedParameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void function() {
|
||||||
|
// int i;
|
||||||
|
// int j;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void function() {
|
||||||
|
// int i;
|
||||||
|
// s1;
|
||||||
|
// s2;
|
||||||
|
// int j;
|
||||||
|
//}
|
||||||
|
public void testInsertMultipleStatements() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
ASTModification compoundReplacement = addModification(null, ModificationKind.REPLACE, statement, statement);
|
||||||
|
IASTNode secondStatement = statement.getChildren()[1];
|
||||||
|
IASTNode firstNewStatement = createStatement("s1");
|
||||||
|
IASTNode secondNewStatement = createStatement("s2");
|
||||||
|
ContainerNode newNodes = new ContainerNode(firstNewStatement, secondNewStatement);
|
||||||
|
addModification(compoundReplacement, INSERT_BEFORE, secondStatement, newNodes);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IASTNode createStatement(String name) {
|
||||||
|
IASTName nameNode = factory.newName(name.toCharArray());
|
||||||
|
IASTIdExpression idExpression = factory.newIdExpression(nameNode);
|
||||||
|
return factory.newExpressionStatement(idExpression);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void function() {
|
||||||
|
// int i;
|
||||||
|
// int j;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void function() {
|
||||||
|
// int i;
|
||||||
|
// int j;
|
||||||
|
// int j;
|
||||||
|
//}
|
||||||
|
public void testInsertStatement() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
ASTModification compoundReplacement = addModification(null, ModificationKind.REPLACE, statement, statement);
|
||||||
|
IASTNode secondStatement = statement.getChildren()[1];
|
||||||
|
addModification(compoundReplacement, INSERT_BEFORE, secondStatement, secondStatement);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int *parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int **parameter) {
|
||||||
|
//}
|
||||||
|
public void testPointerParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTDeclarator paramDeclarator = curParam.getDeclarator();
|
||||||
|
if (paramDeclarator.getName().toString().equals("parameter")) {
|
||||||
|
IASTPointerOperator pointer = paramDeclarator.getPointerOperators()[0];
|
||||||
|
IASTPointer insertedPointer = factory.newPointer();
|
||||||
|
addModification(null, INSERT_BEFORE, pointer, insertedPointer);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,416 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
|
* Rapperswil, University of applied sciences 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Institute for Software - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
|
|
||||||
|
import static org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind.REPLACE;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
|
|
||||||
|
public class RemoveTests extends ChangeGeneratorTest {
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return new TestSuite(RemoveTests.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *pi[3];
|
||||||
|
|
||||||
|
//int *pi;
|
||||||
|
public void testArrayModifier() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof IASTArrayDeclarator) {
|
||||||
|
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
|
||||||
|
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||||
|
addModification(null, REPLACE, modifiers[0], null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *values = new int[5][6];
|
||||||
|
|
||||||
|
//int *values = new int[5];
|
||||||
|
public void testArraySizeExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTTypeId id = newExpression.getTypeId();
|
||||||
|
IASTArrayDeclarator dtor = (IASTArrayDeclarator) id.getAbstractDeclarator();
|
||||||
|
IASTArrayModifier[] mods = dtor.getArrayModifiers();
|
||||||
|
addModification(null, REPLACE, mods[1], null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a):alpha(a) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a) {
|
||||||
|
//}
|
||||||
|
public void testCtorChainInitializer() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclaration declaration) {
|
||||||
|
if (declaration instanceof ICPPASTFunctionDefinition) {
|
||||||
|
ICPPASTFunctionDefinition functionDefinition = (ICPPASTFunctionDefinition) declaration;
|
||||||
|
ICPPASTConstructorChainInitializer[] ctorInitializers = functionDefinition.getMemberInitializers();
|
||||||
|
for (ICPPASTConstructorChainInitializer curInitializer : ctorInitializers) {
|
||||||
|
addModification(null, REPLACE, curInitializer, null);
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int b;
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int b;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
public void testDeclaration() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclaration declaration) {
|
||||||
|
if (declaration instanceof IASTSimpleDeclaration) {
|
||||||
|
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
|
||||||
|
if (simpleDeclaration.getDeclarators().length > 0) {
|
||||||
|
String name = simpleDeclaration.getDeclarators()[0].getName().toString();
|
||||||
|
if (name.equals("c")) {
|
||||||
|
addModification(null, REPLACE, declaration, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (int) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw () {
|
||||||
|
//}
|
||||||
|
public void testException() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification();
|
||||||
|
for (IASTTypeId curException : exceptions) {
|
||||||
|
addModification(null, REPLACE, curException, null);
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, c = 4, h = 5;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, h = 5;
|
||||||
|
//}
|
||||||
|
public void testExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof IASTExpressionList) {
|
||||||
|
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
||||||
|
IASTExpression[] expressions = expressionList.getExpressions();
|
||||||
|
addModification(null, REPLACE, expressions[1], null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int a, int b, int c) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int b, int c) {
|
||||||
|
//}
|
||||||
|
public void testFirstParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTName name = curParam.getDeclarator().getName();
|
||||||
|
if (name.toString().equals("a")) {
|
||||||
|
addModification(null, REPLACE, curParam, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int a, int b, int c) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int a, int b) {
|
||||||
|
//}
|
||||||
|
public void testLastParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTName name = curParam.getDeclarator().getName();
|
||||||
|
if (name.toString().equals("c")) {
|
||||||
|
addModification(null, REPLACE, curParam, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int a, int b, int c) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int a, int c) {
|
||||||
|
//}
|
||||||
|
public void testMiddleParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTName name = curParam.getDeclarator().getName();
|
||||||
|
if (name.toString().equals("b")) {
|
||||||
|
addModification(null, REPLACE, curParam, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *value = new int(5);
|
||||||
|
|
||||||
|
//int *value = new int();
|
||||||
|
public void testNewInitializerExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTInitializer initializer = newExpression.getInitializer();
|
||||||
|
final IASTNode lit = ((ICPPASTConstructorInitializer) initializer).getArguments()[0];
|
||||||
|
addModification(null, REPLACE, lit, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int *parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int parameter) {
|
||||||
|
//}
|
||||||
|
public void testPointerInParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTName name = curParam.getDeclarator().getName();
|
||||||
|
if (name.toString().equals("parameter")) {
|
||||||
|
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
||||||
|
addModification(null, REPLACE, pointer, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//}
|
||||||
|
public void testSingleParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTName name = curParam.getDeclarator().getName();
|
||||||
|
if (name.toString().equals("parameter")) {
|
||||||
|
addModification(null, REPLACE, curParam, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int f()
|
||||||
|
//{
|
||||||
|
// int i = 0;
|
||||||
|
// if(i < 1){
|
||||||
|
// ++i;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//int f()
|
||||||
|
//{
|
||||||
|
// int i = 0;
|
||||||
|
//}
|
||||||
|
public void testStatement() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTIfStatement) {
|
||||||
|
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
||||||
|
addModification(null, REPLACE, ifStatement, null);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,737 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
||||||
|
* Rapperswil, University of applied sciences 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Institute for Software - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||||
|
|
||||||
|
import static org.eclipse.cdt.core.dom.ast.IASTLiteralExpression.lk_integer_constant;
|
||||||
|
import static org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind.REPLACE;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||||
|
|
||||||
|
public class ReplaceTests extends ChangeGeneratorTest {
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return new TestSuite(ReplaceTests.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *pi[3];
|
||||||
|
|
||||||
|
//int *pi[15];
|
||||||
|
public void testArrayModifier() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof IASTArrayDeclarator) {
|
||||||
|
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
|
||||||
|
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||||
|
IASTExpression expr = factory.newLiteralExpression(lk_integer_constant, "15");
|
||||||
|
IASTArrayModifier newModifier = factory.newArrayModifier(expr);
|
||||||
|
addModification(null, REPLACE, modifiers[0], newModifier);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *values = new int[5][6];
|
||||||
|
|
||||||
|
//int *values = new int[5][7];
|
||||||
|
public void testArraySizeExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTTypeId id = newExpression.getTypeId();
|
||||||
|
IASTArrayDeclarator dtor = (IASTArrayDeclarator) id.getAbstractDeclarator();
|
||||||
|
IASTArrayModifier[] mods = dtor.getArrayModifiers();
|
||||||
|
IASTExpression expr = mods[1].getConstantExpression();
|
||||||
|
ICPPASTLiteralExpression replacement = factory.newLiteralExpression(lk_integer_constant, "7");
|
||||||
|
addModification(null, REPLACE, expr, replacement);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a):beta(b){
|
||||||
|
//}
|
||||||
|
|
||||||
|
//TestClass::TestClass(int a) :
|
||||||
|
// alpha(a) {
|
||||||
|
//}
|
||||||
|
public void testCtorChainInitializer() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclaration declaration) {
|
||||||
|
if (declaration instanceof ICPPASTFunctionDefinition) {
|
||||||
|
ICPPASTFunctionDefinition functionDefinition = (ICPPASTFunctionDefinition) declaration;
|
||||||
|
ICPPASTConstructorChainInitializer[] memberInitializers = functionDefinition.getMemberInitializers();
|
||||||
|
for (ICPPASTConstructorChainInitializer curInitializer : memberInitializers) {
|
||||||
|
IASTName parameterName = factory.newName("a".toCharArray());
|
||||||
|
IASTExpression idExpression = new CPPASTIdExpression(parameterName);
|
||||||
|
IASTInitializer initExpr = factory.newConstructorInitializer(new IASTInitializerClause[] { idExpression });
|
||||||
|
IASTName initName = factory.newName("alpha".toCharArray());
|
||||||
|
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr);
|
||||||
|
addModification(null, REPLACE, curInitializer, newInitializer);
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (float) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int parameter) throw (int) {
|
||||||
|
//}
|
||||||
|
public void testExceptionTest() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
||||||
|
|
||||||
|
IASTName name = factory.newName();
|
||||||
|
ICPPASTDeclarator exceptionDeclarator = factory.newDeclarator(name);
|
||||||
|
ICPPASTSimpleDeclSpecifier exDeclSpec = factory.newSimpleDeclSpecifier();
|
||||||
|
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||||
|
IASTTypeId exception = factory.newTypeId(exDeclSpec, exceptionDeclarator);
|
||||||
|
addModification(null, REPLACE, existingException, exception);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, c = 4, h = 5;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int s = 0, c = 0, h = 0;
|
||||||
|
// s = 3, c = 9, h = 5;
|
||||||
|
//}
|
||||||
|
public void testExpressionTest() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof IASTExpressionList) {
|
||||||
|
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
||||||
|
IASTExpression[] expressions = expressionList.getExpressions();
|
||||||
|
IASTName name = factory.newName("c".toCharArray());
|
||||||
|
IASTIdExpression leftOperand = factory.newIdExpression(name);
|
||||||
|
ICPPASTLiteralExpression rightOperand = factory.newLiteralExpression(lk_integer_constant, "9");
|
||||||
|
ICPPASTBinaryExpression binEx = factory.newBinaryExpression(IASTBinaryExpression.op_assign, leftOperand, rightOperand);
|
||||||
|
addModification(null, REPLACE, expressions[1], binEx);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
public void testIdentical() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
IASTName name = declarator.getName();
|
||||||
|
addModification(null, REPLACE, name, name);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int hs = 5;
|
||||||
|
|
||||||
|
//int hs = 999;
|
||||||
|
public void testInitializer() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
IASTInitializer initializer = declarator.getInitializer();
|
||||||
|
|
||||||
|
ICPPASTLiteralExpression litEx = factory.newLiteralExpression(lk_integer_constant, "999");
|
||||||
|
IASTEqualsInitializer initExpr = factory.newEqualsInitializer(litEx);
|
||||||
|
|
||||||
|
addModification(null, REPLACE, initializer, initExpr);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int b;
|
||||||
|
// int a;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int d;
|
||||||
|
// int b;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
public void testMoveRename() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclSpecifiers = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
|
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
|
ICPPASTCompositeTypeSpecifier classSpecifier = (ICPPASTCompositeTypeSpecifier) declSpec;
|
||||||
|
IASTDeclaration[] members = classSpecifier.getMembers();
|
||||||
|
IASTName name = ((CPPASTSimpleDeclaration) members[2]).getDeclarators()[0].getName();
|
||||||
|
ASTModification swap1 = addModification(null, REPLACE, members[1], members[2]);
|
||||||
|
addModification(null, REPLACE, members[2], members[1]);
|
||||||
|
addModification(swap1, REPLACE, name, new CPPASTName("d".toCharArray()));
|
||||||
|
}
|
||||||
|
return super.visit(declSpec);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int b;
|
||||||
|
// int a;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int a;
|
||||||
|
// int b;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
public void testMove() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclSpecifiers = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
|
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
|
ICPPASTCompositeTypeSpecifier classSpecifier = (ICPPASTCompositeTypeSpecifier) declSpec;
|
||||||
|
IASTDeclaration[] members = classSpecifier.getMembers();
|
||||||
|
addModification(null, REPLACE, members[1], members[2]);
|
||||||
|
addModification(null, REPLACE, members[2], members[1]);
|
||||||
|
}
|
||||||
|
return super.visit(declSpec);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int b;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
public void testName() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
char[] newName = new char[] { 'b' };
|
||||||
|
IASTName name = new CPPASTName(newName);
|
||||||
|
addModification(null, REPLACE, declarator.getName(), name);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int x) {
|
||||||
|
// x += 1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int x) {
|
||||||
|
// x++;
|
||||||
|
//}
|
||||||
|
public void testNestedReplace() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) statement;
|
||||||
|
|
||||||
|
IASTCompoundStatement newCompoundStatement = factory.newCompoundStatement();
|
||||||
|
IASTNullStatement dummyStatement = factory.newNullStatement();
|
||||||
|
newCompoundStatement.addStatement(dummyStatement);
|
||||||
|
ASTModification compoundReplacement = addModification(null, REPLACE, compoundStatement, newCompoundStatement);
|
||||||
|
|
||||||
|
IASTName emptyName = factory.newName();
|
||||||
|
IASTExpression idExpression = factory.newIdExpression(emptyName);
|
||||||
|
IASTExpression incrementExpression = factory.newUnaryExpression(IASTUnaryExpression.op_postFixIncr, idExpression);
|
||||||
|
IASTExpressionStatement newStatement = factory.newExpressionStatement(incrementExpression);
|
||||||
|
IASTStatement replacedStatement = compoundStatement.getStatements()[0];
|
||||||
|
ASTModification statementModification = addModification(compoundReplacement, REPLACE, dummyStatement, newStatement);
|
||||||
|
|
||||||
|
IASTName xName = factory.newName("x".toCharArray());
|
||||||
|
ASTModification nameModification = addModification(statementModification, REPLACE, emptyName, xName);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int *value = new int(5);
|
||||||
|
|
||||||
|
//int *value = new int(6);
|
||||||
|
public void testNewInitializerExpression() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitExpressions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTExpression expression) {
|
||||||
|
if (expression instanceof ICPPASTNewExpression) {
|
||||||
|
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||||
|
IASTNode lit = ((ICPPASTConstructorInitializer) newExpression.getInitializer()).getArguments()[0];
|
||||||
|
|
||||||
|
ICPPASTLiteralExpression newNode = factory.newLiteralExpression(lk_integer_constant, "6");
|
||||||
|
addModification(null, REPLACE, lit, newNode);
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo(int ¶meter) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo(int *parameter) {
|
||||||
|
//}
|
||||||
|
public void testPointerInParameter() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||||
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
|
||||||
|
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||||
|
for (IASTParameterDeclaration curParam : parameters) {
|
||||||
|
IASTDeclarator paramDeclarator = curParam.getDeclarator();
|
||||||
|
if (paramDeclarator.getName().toString().equals("parameter")) {
|
||||||
|
IASTPointerOperator pointer = paramDeclarator.getPointerOperators()[0];
|
||||||
|
IASTPointer newPointer = factory.newPointer();
|
||||||
|
addModification(null, REPLACE, pointer, newPointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for(int i = 0; i < 10; i++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for(int j = 0; j < 10; j++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for (;;)
|
||||||
|
// ;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for(int j = 0; j < 10; j++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
public void testReplaceForLoopBody() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof ICPPASTForStatement) {
|
||||||
|
ICPPASTForStatement newFor = factory.newForStatement();
|
||||||
|
newFor.setInitializerStatement(factory.newNullStatement());
|
||||||
|
newFor.setBody(factory.newNullStatement());
|
||||||
|
addModification(null, REPLACE, statement, newFor);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int i = 0;
|
||||||
|
// ++i;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void main() {
|
||||||
|
// int i = 0;
|
||||||
|
// i = 42;
|
||||||
|
// i++;
|
||||||
|
//}
|
||||||
|
public void testReplaceInsertStatement() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
|
IASTCompoundStatement compStmt = (IASTCompoundStatement) statement;
|
||||||
|
IASTStatement stmt = compStmt.getStatements()[1];
|
||||||
|
|
||||||
|
IASTName name = factory.newName("i".toCharArray());
|
||||||
|
IASTIdExpression id = factory.newIdExpression(name);
|
||||||
|
IASTLiteralExpression value = factory.newLiteralExpression(lk_integer_constant, "42");
|
||||||
|
ICPPASTBinaryExpression binExpr = factory.newBinaryExpression(IASTBinaryExpression.op_assign, id, value);
|
||||||
|
IASTExpressionStatement insertStmt = new CPPASTExpressionStatement(
|
||||||
|
binExpr);
|
||||||
|
|
||||||
|
IASTIdExpression incId = new CPPASTIdExpression(new CPPASTName("i".toCharArray()));
|
||||||
|
IASTUnaryExpression incExp = new CPPASTUnaryExpression(IASTUnaryExpression.op_postFixIncr, incId);
|
||||||
|
IASTExpressionStatement replaceStatement = new CPPASTExpressionStatement(incExp);
|
||||||
|
|
||||||
|
addModification(null, REPLACE, stmt, replaceStatement);
|
||||||
|
addModification(null, ModificationKind.INSERT_BEFORE, stmt, insertStmt);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void bar() {
|
||||||
|
//}
|
||||||
|
public void testReplaceReplacedNode() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitNames = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTName name) {
|
||||||
|
IASTName intermediateName = factory.newName("intermediate".toCharArray());
|
||||||
|
ASTModification replaceMod = addModification(null, REPLACE, name, intermediateName);
|
||||||
|
|
||||||
|
IASTName finalName = factory.newName("bar".toCharArray());
|
||||||
|
addModification(replaceMod, REPLACE, intermediateName, finalName);
|
||||||
|
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
//#ifndef A_H_
|
||||||
|
//#define A_H_
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// int c;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#endif /*A_H_*/
|
||||||
|
//
|
||||||
|
//
|
||||||
|
public void testSameName() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitDeclarators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTDeclarator declarator) {
|
||||||
|
IASTName name = factory.newName("c".toCharArray());
|
||||||
|
addModification(null, REPLACE, declarator.getName(), name);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//int f()
|
||||||
|
//{
|
||||||
|
// int i = 0;
|
||||||
|
// if (i < 1) {
|
||||||
|
// ++i;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//int f()
|
||||||
|
//{
|
||||||
|
// int i = 0;
|
||||||
|
// if (i < 1) {
|
||||||
|
// i++;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testStatement() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof IASTIfStatement) {
|
||||||
|
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
||||||
|
IASTCompoundStatement compound = factory.newCompoundStatement();
|
||||||
|
|
||||||
|
IASTName name = factory.newName("i".toCharArray());
|
||||||
|
IASTIdExpression id = factory.newIdExpression(name);
|
||||||
|
ICPPASTUnaryExpression unaryExpr = factory.newUnaryExpression(IASTUnaryExpression.op_postFixIncr, id);
|
||||||
|
IASTExpressionStatement expr = factory.newExpressionStatement(unaryExpr);
|
||||||
|
compound.addStatement(expr);
|
||||||
|
addModification(null, REPLACE, ifStatement.getThenClause(), compound);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for(int i = 0; i < 10; i++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for(int j = 0; j < 10; j++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < 10; i++)
|
||||||
|
// ;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// for(int j = 0; j < 10; j++){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
public void testWhitespaceHandling() throws Exception {
|
||||||
|
compareResult(new ASTVisitor() {
|
||||||
|
{
|
||||||
|
shouldVisitStatements = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTStatement statement) {
|
||||||
|
if (statement instanceof ICPPASTForStatement) {
|
||||||
|
ICPPASTForStatement forStatement = (ICPPASTForStatement) statement;
|
||||||
|
|
||||||
|
ICPPASTForStatement newFor = forStatement.copy(CopyStyle.withLocations);
|
||||||
|
newFor.setBody(factory.newNullStatement());
|
||||||
|
|
||||||
|
addModification(null, REPLACE, forStatement, newFor);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,35 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Thomas Corbat
|
|
||||||
*/
|
|
||||||
public class AppendTestSuite {
|
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
TestSuite suite = new TestSuite("ChangeGenerator Append Child Tests");
|
|
||||||
suite.addTest(ParameterTest.suite());
|
|
||||||
suite.addTest(ParameterToListTest.suite());
|
|
||||||
suite.addTest(PointerToParameterTest.suite());
|
|
||||||
suite.addTest(PointerToPointerParameterTest.suite());
|
|
||||||
suite.addTest(ExceptionTest.suite());
|
|
||||||
suite.addTest(CtorChainInitializerTest.suite());
|
|
||||||
suite.addTest(ArrayModifierTest.suite());
|
|
||||||
suite.addTest(ExpressionTest.suite());
|
|
||||||
suite.addTest(ArraySizeExpressionTest.suite());
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class ArrayModifierTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArrayModifierTest(){
|
|
||||||
super("Replace Array Modifier"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *pi[5];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *pi[5][3];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof IASTArrayDeclarator) {
|
|
||||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
|
|
||||||
arrayDeclarator.getArrayModifiers();
|
|
||||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
|
||||||
IASTExpression expr = new CPPASTLiteralExpression(
|
|
||||||
IASTLiteralExpression.lk_integer_constant, "3".toCharArray()); //$NON-NLS-1$
|
|
||||||
newModifier.setConstantExpression(expr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
declarator, newModifier, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArrayModifierTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArraySizeExpressionTest(){
|
|
||||||
super("Append Array Size Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *values = new int[6];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
IASTTypeId id= newExpression.getTypeId();
|
|
||||||
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
|
|
||||||
IASTArrayModifier[] mods= dtor.getArrayModifiers();
|
|
||||||
IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5".toCharArray()));
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
|
|
||||||
dtor, add, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArraySizeExpressionTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public CtorChainInitializerTest(){
|
|
||||||
super("Append Ctor Initializer"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "TestClass::TestClass(int a, int b) :\n\t\tbeta(b) {\n}\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "TestClass::TestClass(int a, int b) :\n\t\tbeta(b), alpha(a) {\n}\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarations = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclaration decl) {
|
|
||||||
if (decl instanceof CPPASTFunctionDefinition) {
|
|
||||||
CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition) decl;
|
|
||||||
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
|
|
||||||
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
|
|
||||||
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
|
|
||||||
newInitializer.setInitializerValue(initExpr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
fdef, newInitializer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new CtorChainInitializerTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExceptionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExceptionTest(){
|
|
||||||
super("Append Exception Declaration"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
IASTTypeId exception = new CPPASTTypeId();
|
|
||||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
|
||||||
exceptionDeclarator.setName(new CPPASTName());
|
|
||||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
exception.setDeclSpecifier(exDeclSpec);
|
|
||||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
declarator, exception, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExceptionTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExpressionTest(){
|
|
||||||
super("Append Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5, c = 9;\n}"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof IASTExpressionList) {
|
|
||||||
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
|
||||||
expressionList.getExpressions();
|
|
||||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray()));
|
|
||||||
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
|
|
||||||
idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
|
|
||||||
expressionList, binEx, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExpressionTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Thomas Corbat (IFS) - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class NestedElseifStatementTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public NestedElseifStatementTest(){
|
|
||||||
super("Append Nested Elseif Statement"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(bool cond1, bool cond2) {\n}\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(bool cond1, bool cond2) {\n\tif (cond1) {\n\t} else if (cond2) {\n\t}\n}\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
IASTCompoundStatement compound = (IASTCompoundStatement) statement;
|
|
||||||
INodeFactory factory = statement.getTranslationUnit().getASTNodeFactory();
|
|
||||||
|
|
||||||
IASTIdExpression elseIfCondition = factory.newIdExpression(factory.newName("cond2".toCharArray()));
|
|
||||||
IASTStatement elseIfThen = factory.newCompoundStatement();
|
|
||||||
IASTIfStatement elseIfStatement = factory.newIfStatement(elseIfCondition, elseIfThen, null);
|
|
||||||
|
|
||||||
IASTIdExpression ifCondition = factory.newIdExpression(factory.newName("cond1".toCharArray()));
|
|
||||||
IASTStatement ifThen = factory.newCompoundStatement();
|
|
||||||
IASTIfStatement ifStatement = factory.newIfStatement(ifCondition, ifThen, elseIfStatement);
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, compound, ifStatement, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new NestedElseifStatementTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ParameterTest(){
|
|
||||||
super("Append Parameter to List"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int existing) {\n}\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int existing, int newParameter) {\n}\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
|
|
||||||
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
|
|
||||||
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
|
|
||||||
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
|
|
||||||
parameterDeclarator.setName(parameterName);
|
|
||||||
insertedParameter.setDeclarator(parameterDeclarator);
|
|
||||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
functionDeclarator, insertedParameter, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ParameterTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ParameterToListTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ParameterToListTest(){
|
|
||||||
super("Append Parameter to Empty List"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo() {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int newParameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
|
|
||||||
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
|
|
||||||
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
|
|
||||||
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
|
|
||||||
parameterDeclarator.setName(parameterName);
|
|
||||||
insertedParameter.setDeclarator(parameterDeclarator);
|
|
||||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
functionDeclarator, insertedParameter, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ParameterToListTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class PointerToParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public PointerToParameterTest(){
|
|
||||||
super("Append Pointer to Parameter"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
|
||||||
CPPASTPointer addedPointer = new CPPASTPointer();
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
curParam.getDeclarator(), addedPointer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new PointerToParameterTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class PointerToPointerParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public PointerToPointerParameterTest(){
|
|
||||||
super("Append Pointer to Pointer Parameter"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
|
||||||
CPPASTPointer addedPointer = new CPPASTPointer();
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
|
|
||||||
curParam.getDeclarator(), addedPointer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new PointerToPointerParameterTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software (IFS)- initial API and implementation
|
|
||||||
******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Emanuel Graf IFS
|
|
||||||
*/
|
|
||||||
public class AddDeclarationBugTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
AddDeclarationBugTest() {
|
|
||||||
super("AddDeclarationBug");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new AddDeclarationBugTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n};"; //$NON-NLS-1$
|
|
||||||
expectedSource = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n\tint exp(int i);\n};"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclSpecifiers = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
|
||||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
|
||||||
ICPPASTCompositeTypeSpecifier classNode = (ICPPASTCompositeTypeSpecifier) declSpec;
|
|
||||||
IASTSimpleDeclaration newDecl = new CPPASTSimpleDeclaration();
|
|
||||||
|
|
||||||
IASTSimpleDeclSpecifier returnType = new CPPASTSimpleDeclSpecifier();
|
|
||||||
returnType.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
newDecl.setDeclSpecifier(returnType);
|
|
||||||
|
|
||||||
IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator(
|
|
||||||
new CPPASTName("exp".toCharArray())); //$NON-NLS-1$
|
|
||||||
IASTSimpleDeclSpecifier paramType = new CPPASTSimpleDeclSpecifier();
|
|
||||||
paramType.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
IASTDeclarator decl = new CPPASTDeclarator(new CPPASTName("i".toCharArray())); //$NON-NLS-1$
|
|
||||||
ICPPASTParameterDeclaration param = new CPPASTParameterDeclaration(paramType, decl);
|
|
||||||
declarator.addParameterDeclaration(param);
|
|
||||||
newDecl.addDeclarator(declarator);
|
|
||||||
|
|
||||||
ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode,
|
|
||||||
newDecl, null);
|
|
||||||
modStore.storeModification(null, mod);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ArrayModifierTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
ArrayModifierTest() {
|
|
||||||
super("ArrayModifierTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArrayModifierTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int* pi[3];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int* pi[5][3];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof IASTArrayDeclarator) {
|
|
||||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
|
|
||||||
|
|
||||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
|
||||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
|
||||||
IASTExpression expr =
|
|
||||||
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "5".toCharArray()); //$NON-NLS-1$
|
|
||||||
newModifier.setConstantExpression(expr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
|
|
||||||
modifiers[0], newModifier, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
ArraySizeExpressionTest() {
|
|
||||||
super("ArraySizeExpressionTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArraySizeExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int* values = new int[5];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int* values = new int[6][5];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
IASTTypeId id= newExpression.getTypeId();
|
|
||||||
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
|
|
||||||
IASTArrayModifier[] mods= dtor.getArrayModifiers();
|
|
||||||
IASTArrayModifier add= new CPPASTArrayModifier(
|
|
||||||
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "6".toCharArray()));
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE,
|
|
||||||
mods[0], add, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
CtorChainInitializerTest() {
|
|
||||||
super("CtorChainInitializerTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new CtorChainInitializerTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "TestClass::TestClass(int a, int b):beta(b) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "TestClass::TestClass(int a, int b) :\n\t\talpha(a), beta(b) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0];
|
|
||||||
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
|
|
||||||
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
|
|
||||||
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
|
|
||||||
newInitializer.setInitializerValue(initExpr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExceptionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
ExceptionTest() {
|
|
||||||
super("ExceptionTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExceptionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) throw (/*Test*/float) /*Test2*/{\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int parameter) throw (int, /*Test*/float) /*Test2*/{\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
|
||||||
|
|
||||||
IASTTypeId exception = new CPPASTTypeId();
|
|
||||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
|
||||||
exceptionDeclarator.setName(new CPPASTName());
|
|
||||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
exception.setDeclSpecifier(exDeclSpec);
|
|
||||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
|
|
||||||
existingException, exception, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
ExpressionTest() {
|
|
||||||
super("ExpressionTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof IASTExpressionList) {
|
|
||||||
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
|
||||||
IASTExpression[] expressions = expressionList.getExpressions();
|
|
||||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray())); //$NON-NLS-1$
|
|
||||||
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
|
|
||||||
idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE,
|
|
||||||
expressions[1], binEx, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class FirstParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
FirstParameterTest() {
|
|
||||||
super("FirstParameterTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new FirstParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int a) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int newParameter, int a) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$
|
|
||||||
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
|
|
||||||
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
|
|
||||||
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
|
|
||||||
parameterDeclarator.setName(parameterName);
|
|
||||||
insertedParameter.setDeclarator(parameterDeclarator);
|
|
||||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
|
|
||||||
curParam, insertedParameter, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Thomas Corbat
|
|
||||||
*/
|
|
||||||
public class InsertBeforeTestSuite {
|
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
TestSuite suite = new TestSuite("InsertBeforeTestSuite");
|
|
||||||
|
|
||||||
suite.addTest(FirstParameterTest.suite());
|
|
||||||
suite.addTest(PointerParameterTest.suite());
|
|
||||||
suite.addTest(ExceptionTest.suite());
|
|
||||||
suite.addTest(CtorChainInitializerTest.suite());
|
|
||||||
suite.addTest(ArrayModifierTest.suite());
|
|
||||||
suite.addTest(ExpressionTest.suite());
|
|
||||||
suite.addTest(ArraySizeExpressionTest.suite());
|
|
||||||
suite.addTest(AddDeclarationBugTest.suite());
|
|
||||||
suite.addTest(MultilineWhitespaceHandlingTest.suite());
|
|
||||||
suite.addTest(SelfInsertionTest.suite());
|
|
||||||
suite.addTest(InsertStatementTest.suite());
|
|
||||||
suite.addTest(InsertMultipleStatementsTest.suite());
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Thomas Corbat (IFS)- initial API and implementation
|
|
||||||
******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
|
|
||||||
|
|
||||||
public class InsertMultipleStatementsTest extends ChangeGeneratorTest {
|
|
||||||
public InsertMultipleStatementsTest() {
|
|
||||||
super("InsertMultipleStatementsTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new InsertMultipleStatementsTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void function() {\n" +
|
|
||||||
" int i;\n" +
|
|
||||||
" int j;\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void function() {\n" +
|
|
||||||
" int i;\n" +
|
|
||||||
" s1;\n" +
|
|
||||||
" s2;\n" +
|
|
||||||
" int j;\n" +
|
|
||||||
"}";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
ASTModification compoundReplacement = new ASTModification(ModificationKind.REPLACE, statement, statement, null);
|
|
||||||
modStore.storeModification(null, compoundReplacement);
|
|
||||||
IASTNode secondStatement = statement.getChildren()[1];
|
|
||||||
IASTNode firstNewStatement = createStatement("s1");
|
|
||||||
IASTNode secondNewStatement = createStatement("s2");
|
|
||||||
ContainerNode newNodes = new ContainerNode(firstNewStatement, secondNewStatement);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, secondStatement, newNodes, null);
|
|
||||||
modStore.storeModification(compoundReplacement, modification);
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IASTNode createStatement(String name) {
|
|
||||||
CPPNodeFactory factory = CPPNodeFactory.getDefault();
|
|
||||||
return factory.newExpressionStatement(factory.newIdExpression(factory.newName(name.toCharArray())));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Thomas Corbat (IFS)- initial API and implementation
|
|
||||||
******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class InsertStatementTest extends ChangeGeneratorTest {
|
|
||||||
public InsertStatementTest() {
|
|
||||||
super("InsertStatementTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new InsertStatementTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void function() {\n" +
|
|
||||||
" int i;\n" +
|
|
||||||
" int j;\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void function() {\n" +
|
|
||||||
" int i;\n" +
|
|
||||||
" int j;\n" +
|
|
||||||
" int j;\n" +
|
|
||||||
"}";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
ASTModification compoundReplacement = new ASTModification(ModificationKind.REPLACE, statement, statement, null);
|
|
||||||
modStore.storeModification(null, compoundReplacement);
|
|
||||||
IASTNode secondStatement = statement.getChildren()[1];
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, secondStatement, secondStatement, null);
|
|
||||||
modStore.storeModification(compoundReplacement, modification);
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
MultilineWhitespaceHandlingTest() {
|
|
||||||
super("MultilineWhitespaceHandlingTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new MultilineWhitespaceHandlingTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\n\n\t}\n}\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\t\tint i;\n\t\tint j;\n\t}\n}\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTForStatement) {
|
|
||||||
IASTForStatement forStatement = (IASTForStatement) statement;
|
|
||||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) forStatement.getBody();
|
|
||||||
|
|
||||||
addIntDeclaration(modStore, compoundStatement, "i"); //$NON-NLS-1$
|
|
||||||
addIntDeclaration(modStore, compoundStatement, "j"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addIntDeclaration(final ASTModificationStore modStore,
|
|
||||||
IASTCompoundStatement compoundStatement, String variableName) {
|
|
||||||
CPPNodeFactory nf = CPPNodeFactory.getDefault();
|
|
||||||
|
|
||||||
ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier = nf.newSimpleDeclSpecifier();
|
|
||||||
newSimpleDeclSpecifier.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
IASTSimpleDeclaration newSimpleDeclaration = nf.newSimpleDeclaration(newSimpleDeclSpecifier);
|
|
||||||
newSimpleDeclaration.addDeclarator(nf.newDeclarator(nf.newName(variableName.toCharArray())));
|
|
||||||
IASTDeclarationStatement newDeclaration = nf.newDeclarationStatement(newSimpleDeclaration);
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
|
|
||||||
compoundStatement, newDeclaration, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class PointerParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
PointerParameterTest() {
|
|
||||||
super("PointerParameterTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new PointerParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for(IASTParameterDeclaration curParam : parameters){
|
|
||||||
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
|
||||||
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
|
||||||
CPPASTPointer insertedPointer = new CPPASTPointer();
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, pointer, insertedPointer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class SelfInsertionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
SelfInsertionTest() {
|
|
||||||
super("SelfInsertionTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new SelfInsertionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo() {\r\n\r\n\tfor (int i = 0; i < 10; i++) {\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo() {\r\n\r\n\tfor (int i = 0; i < 10; i++) {\r\n\t\tfor (int i = 0; i < 10; i++) {\r\n\t\t}\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTForStatement) {
|
|
||||||
IASTForStatement forStatement = (IASTForStatement) statement;
|
|
||||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) forStatement.getBody();
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
|
|
||||||
compoundStatement, forStatement, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ArrayModifierTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArrayModifierTest(){
|
|
||||||
super("Remove Array Modifier"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *pi[3];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *pi;"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArrayModifierTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof IASTArrayDeclarator) {
|
|
||||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
|
||||||
|
|
||||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArraySizeExpressionTest(){
|
|
||||||
super("Remove Array Size Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *values = new int[5][6];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *values = new int[5];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
IASTTypeId id= newExpression.getTypeId();
|
|
||||||
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
|
|
||||||
IASTArrayModifier[] mods= dtor.getArrayModifiers();
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, mods[1], null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArraySizeExpressionTest();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public CtorChainInitializerTest() {
|
|
||||||
super("Remove Ctor Initializer"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "TestClass::TestClass(int a):alpha(a) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "TestClass::TestClass(int a) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new CtorChainInitializerTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
|
|
||||||
for (ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curInitializer, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DeclarationTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public DeclarationTest(){
|
|
||||||
super("Remove Declaration Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
|
|
||||||
return new DeclarationTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarations = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclaration declaration) {
|
|
||||||
if (declaration instanceof CPPASTSimpleDeclaration) {
|
|
||||||
CPPASTSimpleDeclaration simpleDeclaration = (CPPASTSimpleDeclaration) declaration;
|
|
||||||
if(simpleDeclaration.getDeclarators().length > 0){
|
|
||||||
String name = String.valueOf(simpleDeclaration.getDeclarators()[0].getName().toCharArray());
|
|
||||||
if(name.equals("c")){ //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declaration, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class ExceptionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExceptionTest(){
|
|
||||||
super("Remove Exception Declaration"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int parameter) throw () {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExceptionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification();
|
|
||||||
for (IASTTypeId curException : exceptions) {
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curException, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExpressionTest() {
|
|
||||||
super("Remove Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof IASTExpressionList) {
|
|
||||||
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
|
||||||
IASTExpression[] expressions = expressionList.getExpressions();
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE,
|
|
||||||
expressions[1], null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class FirstParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public FirstParameterTest() {
|
|
||||||
super("Remove First Parameter Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int b, int c) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new FirstParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")) { //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curParam, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class LastParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public LastParameterTest() {
|
|
||||||
super("Remove Last Parameter Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int a, int b) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new LastParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")) { //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curParam, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class MiddleParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public MiddleParameterTest(){
|
|
||||||
super("Remove Middle Parameter Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int a, int c) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new MiddleParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")) { //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curParam, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class NewInitializerExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public NewInitializerExpressionTest(){
|
|
||||||
super("Remove New Initializer Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception{
|
|
||||||
source = "int *value = new int(5);"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *value = new int();"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
final IASTNode lit = ((ICPPASTConstructorInitializer) newExpression.getInitializer()).getArguments()[0];
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, lit, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new NewInitializerExpressionTest();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class PointerInParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public PointerInParameterTest() {
|
|
||||||
super("Remove Pointer in Parameter"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new PointerInParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
|
||||||
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
pointer, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Thomas Corbat
|
|
||||||
*/
|
|
||||||
public class RemoveTestSuite {
|
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
TestSuite suite = new TestSuite("ChangeGenerator Remove Tests");
|
|
||||||
suite.addTest(DeclarationTest.suite());
|
|
||||||
suite.addTest(FirstParameterTest.suite());
|
|
||||||
suite.addTest(MiddleParameterTest.suite());
|
|
||||||
suite.addTest(LastParameterTest.suite());
|
|
||||||
suite.addTest(SingleParameterTest.suite());
|
|
||||||
suite.addTest(PointerInParameterTest.suite());
|
|
||||||
suite.addTest(ExceptionTest.suite());
|
|
||||||
suite.addTest(CtorChainInitializerTest.suite());
|
|
||||||
suite.addTest(ArrayModifierTest.suite());
|
|
||||||
suite.addTest(ExpressionTest.suite());
|
|
||||||
suite.addTest(ArraySizeExpressionTest.suite());
|
|
||||||
suite.addTest(NewInitializerExpressionTest.suite());
|
|
||||||
suite.addTest(StatementTest.suite());
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class SingleParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public SingleParameterTest() {
|
|
||||||
super("Remove The Only Parameter Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo() {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new SingleParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
curParam, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class StatementTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public StatementTest(){
|
|
||||||
super("Remove Then-Statement"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new StatementTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTIfStatement) {
|
|
||||||
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ArrayModifierTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArrayModifierTest(){
|
|
||||||
super("Replace Array Modifier"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *pi[3];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *pi[15];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArrayModifierTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof IASTArrayDeclarator) {
|
|
||||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
|
||||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
|
||||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
|
||||||
IASTExpression expr = new CPPASTLiteralExpression(0, "15".toCharArray()); //$NON-NLS-1$
|
|
||||||
newModifier.setConstantExpression(expr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], newModifier, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ArraySizeExpressionTest(){
|
|
||||||
super("Relpace Array Size Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *values = new int[5][6];"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *values = new int[5][7];"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ArraySizeExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
IASTTypeId id= newExpression.getTypeId();
|
|
||||||
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
|
|
||||||
IASTArrayModifier[] mods= dtor.getArrayModifiers();
|
|
||||||
IASTExpression expr= mods[1].getConstantExpression();
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expr, new CPPASTLiteralExpression(0, "7"), null); //$NON-NLS-1$
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public CtorChainInitializerTest(){
|
|
||||||
super("Replace Ctor Initializer"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"TestClass::TestClass(int a):beta(b){\n" +
|
|
||||||
"}\n" +
|
|
||||||
"\n";
|
|
||||||
expectedSource =
|
|
||||||
"TestClass::TestClass(int a) :\n" +
|
|
||||||
" alpha(a) {\n" +
|
|
||||||
"}\n" +
|
|
||||||
"\n";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new CtorChainInitializerTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
|
||||||
ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
|
|
||||||
for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
|
|
||||||
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
|
|
||||||
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
|
|
||||||
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
|
|
||||||
newInitializer.setInitializerValue(initExpr);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, newInitializer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class ExceptionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExceptionTest(){
|
|
||||||
super("Remove Exception Declaration"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int parameter) throw (float) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExceptionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
|
||||||
|
|
||||||
IASTTypeId exception = new CPPASTTypeId();
|
|
||||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
|
||||||
exceptionDeclarator.setName(new CPPASTName());
|
|
||||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
|
||||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
|
||||||
exception.setDeclSpecifier(exDeclSpec);
|
|
||||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
|
|
||||||
existingException, exception, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ExpressionTest() {
|
|
||||||
super("Replace Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof IASTExpressionList) {
|
|
||||||
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
|
||||||
IASTExpression[] expressions = expressionList.getExpressions();
|
|
||||||
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
|
|
||||||
new CPPASTIdExpression(new CPPASTName("c".toCharArray())), //$NON-NLS-1$
|
|
||||||
new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE,
|
|
||||||
expressions[1], binEx, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class IdenticalTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public IdenticalTest(){
|
|
||||||
super("Replace Node Same Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new IdenticalTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), declarator.getName(), null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
|
|
||||||
public class InitializerTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public InitializerTest(){
|
|
||||||
super("Replace Initializer"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int hs = 5;"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int hs = 999;"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new InitializerTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTDeclarator) {
|
|
||||||
CPPASTDeclarator fieldDeclarator = (CPPASTDeclarator)declarator;
|
|
||||||
IASTInitializer initializer = fieldDeclarator.getInitializer();
|
|
||||||
|
|
||||||
CPPASTLiteralExpression litEx = new CPPASTLiteralExpression(0, "999"); //$NON-NLS-1$
|
|
||||||
CPPASTEqualsInitializer initExpr = new CPPASTEqualsInitializer(litEx);
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, initializer, initExpr, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class MoveRenameTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
MoveRenameTest() {
|
|
||||||
super("MoveRenameTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new MoveRenameTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint b;\r\n\tint a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint d;\r\n\tint b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclSpecifiers = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
|
||||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
|
||||||
CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
|
|
||||||
IASTDeclaration[] members = classSpecifier.getMembers();
|
|
||||||
ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
|
|
||||||
ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
|
|
||||||
IASTName name =((CPPASTSimpleDeclaration) members[2]).getDeclarators()[0].getName();
|
|
||||||
modStore.storeModification(null, swap1);
|
|
||||||
modStore.storeModification(null, swap2);
|
|
||||||
modStore.storeModification(swap1, new ASTModification(ASTModification.ModificationKind.REPLACE, name, new CPPASTName("d".toCharArray()), null)); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return super.visit(declSpec);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class MoveTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
MoveTest() {
|
|
||||||
super("MoveTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new MoveTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint b;\r\n\tint a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint a;\r\n\tint b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclSpecifiers = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
|
||||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
|
||||||
CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
|
|
||||||
IASTDeclaration[] members = classSpecifier.getMembers();
|
|
||||||
ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
|
|
||||||
ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
|
|
||||||
modStore.storeModification(null, swap1);
|
|
||||||
modStore.storeModification(null, swap2);
|
|
||||||
}
|
|
||||||
return super.visit(declSpec);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public MultilineWhitespaceHandlingTest(){
|
|
||||||
super("Multiline Whitespace Handling in Replace"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int i = 0; i < 10; i++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n";
|
|
||||||
expectedSource =
|
|
||||||
"void foo() {\n" +
|
|
||||||
" for (int i = 0; i < 10; i++) {\n" +
|
|
||||||
" }\n" +
|
|
||||||
"}";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new MultilineWhitespaceHandlingTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) statement;
|
|
||||||
CPPNodeFactory nf = CPPNodeFactory.getDefault();
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, compoundStatement, null, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class NameTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
|
|
||||||
public NameTest(){
|
|
||||||
super("Replace Name Node"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new NameTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
char[] newName = new char[]{'b'};
|
|
||||||
IASTName name = new CPPASTName(newName);
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Thomas Corbat (IFS) - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class NestedReplaceTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public NestedReplaceTest() {
|
|
||||||
super("Nested Replace"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void foo(int x) {\n" +
|
|
||||||
" x += 1;\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void foo(int x) {\n" +
|
|
||||||
" x++;\n" +
|
|
||||||
"}";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new NestedReplaceTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) statement;
|
|
||||||
INodeFactory factory = statement.getTranslationUnit().getASTNodeFactory();
|
|
||||||
|
|
||||||
IASTCompoundStatement newCompoundStatement = factory.newCompoundStatement();
|
|
||||||
IASTNullStatement dummyStatement = factory.newNullStatement();
|
|
||||||
newCompoundStatement.addStatement(dummyStatement);
|
|
||||||
ASTModification compoundReplacement = new ASTModification(ModificationKind.REPLACE, compoundStatement, newCompoundStatement, null);
|
|
||||||
modStore.storeModification(null, compoundReplacement);
|
|
||||||
|
|
||||||
IASTName emptyName = factory.newName();
|
|
||||||
IASTExpression idExpression = factory.newIdExpression(emptyName);
|
|
||||||
IASTExpression incrementExpression = factory.newUnaryExpression(IASTUnaryExpression.op_postFixIncr, idExpression);
|
|
||||||
IASTExpressionStatement newStatement = factory.newExpressionStatement(incrementExpression);
|
|
||||||
IASTStatement replacedStatement = compoundStatement.getStatements()[0];
|
|
||||||
ASTModification statementModification = new ASTModification(ModificationKind.REPLACE, dummyStatement, newStatement, null);
|
|
||||||
modStore.storeModification(compoundReplacement, statementModification);
|
|
||||||
|
|
||||||
IASTName xName = factory.newName("x".toCharArray());
|
|
||||||
ASTModification nameModification = new ASTModification(ModificationKind.REPLACE, emptyName, xName, null);
|
|
||||||
modStore.storeModification(statementModification, nameModification);
|
|
||||||
}
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class NewInitializerExpressionTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public NewInitializerExpressionTest(){
|
|
||||||
super("Replace New Initializer Expression"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int *value = new int(5);"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int *value = new int(6);"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new NewInitializerExpressionTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitExpressions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTExpression expression) {
|
|
||||||
if (expression instanceof ICPPASTNewExpression) {
|
|
||||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
|
||||||
final IASTNode lit = ((ICPPASTConstructorInitializer) newExpression.getInitializer()).getArguments()[0];
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, lit, new CPPASTLiteralExpression(0, "6".toCharArray()), null); //$NON-NLS-1$
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class PointerInParameterTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public PointerInParameterTest() {
|
|
||||||
super("PointerInParameterTest"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void foo(int ¶meter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new PointerInParameterTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
|
||||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
|
||||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
|
||||||
for (IASTParameterDeclaration curParam : parameters){
|
|
||||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")) { //$NON-NLS-1$
|
|
||||||
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
|
||||||
CPPASTPointer newPointer = new CPPASTPointer();
|
|
||||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ReplaceForLoopBodyTest extends ChangeGeneratorTest {
|
|
||||||
private boolean forReplaced;
|
|
||||||
|
|
||||||
public ReplaceForLoopBodyTest(){
|
|
||||||
super("ReplaceForLoopBodyTest"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int i = 0; i < 10; i++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int j = 0; j < 10; j++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"\n" +
|
|
||||||
" for (;;)\n" +
|
|
||||||
" ;\n" +
|
|
||||||
"\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int j = 0; j < 10; j++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
"}";
|
|
||||||
forReplaced = false;
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ReplaceForLoopBodyTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (!forReplaced && statement instanceof ICPPASTForStatement) {
|
|
||||||
ICPPASTForStatement forStatement = (ICPPASTForStatement) statement;
|
|
||||||
CPPNodeFactory nf = CPPNodeFactory.getDefault();
|
|
||||||
ICPPASTForStatement newFor = nf.newForStatement();
|
|
||||||
newFor.setInitializerStatement(nf.newNullStatement());
|
|
||||||
newFor.setBody(nf.newNullStatement());
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, forStatement, newFor, null);
|
|
||||||
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
|
|
||||||
forReplaced = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class ReplaceInsertStatementTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
ReplaceInsertStatementTest() {
|
|
||||||
super("ReplaceInsertStatementTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ReplaceInsertStatementTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "void main() {\r\n\tint i = 0;\r\n\t++i;\r\n}"; //$NON-NLS-1$
|
|
||||||
expectedSource = "void main() {\r\n\tint i = 0;\r\n\ti = 42;\r\n\ti++;\r\n}"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
|
||||||
IASTCompoundStatement compStmt = (IASTCompoundStatement) statement;
|
|
||||||
IASTStatement stmt = compStmt.getStatements()[1];
|
|
||||||
|
|
||||||
IASTIdExpression id = new CPPASTIdExpression(new CPPASTName("i".toCharArray()));
|
|
||||||
IASTLiteralExpression value = new CPPASTLiteralExpression(
|
|
||||||
IASTLiteralExpression.lk_integer_constant, "42".toCharArray());
|
|
||||||
IASTExpressionStatement insertStmt = new CPPASTExpressionStatement(
|
|
||||||
new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, id, value));
|
|
||||||
|
|
||||||
IASTIdExpression incId = new CPPASTIdExpression(
|
|
||||||
new CPPASTName("i".toCharArray()));
|
|
||||||
IASTUnaryExpression incExp = new CPPASTUnaryExpression(
|
|
||||||
IASTUnaryExpression.op_postFixIncr, incId);
|
|
||||||
IASTExpressionStatement replaceStatement = new CPPASTExpressionStatement(
|
|
||||||
incExp);
|
|
||||||
|
|
||||||
ASTModification replaceMod = new ASTModification(
|
|
||||||
ASTModification.ModificationKind.REPLACE, stmt, replaceStatement, null);
|
|
||||||
modStore.storeModification(null, replaceMod);
|
|
||||||
|
|
||||||
ASTModification insertMod = new ASTModification(
|
|
||||||
ASTModification.ModificationKind.INSERT_BEFORE, stmt, insertStmt, null);
|
|
||||||
modStore.storeModification(null, insertMod);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Thomas Corbat (IFS) - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
import static org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind.*;
|
|
||||||
|
|
||||||
public class ReplaceReplacedNodeTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public ReplaceReplacedNodeTest() {
|
|
||||||
super("ReplaceReplacedNodeTest"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void bar() {\n" +
|
|
||||||
"}";
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new ReplaceReplacedNodeTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitNames = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTName name) {
|
|
||||||
INodeFactory factory = name.getTranslationUnit().getASTNodeFactory();
|
|
||||||
|
|
||||||
IASTName intermediateName = factory.newName("intermediate".toCharArray());
|
|
||||||
ASTModification replaceMod = new ASTModification(REPLACE, name, intermediateName, null);
|
|
||||||
modStore.storeModification(null, replaceMod);
|
|
||||||
|
|
||||||
IASTName finalName = factory.newName("bar".toCharArray());
|
|
||||||
ASTModification replaceReplacementMod = new ASTModification(REPLACE, intermediateName, finalName, null);
|
|
||||||
modStore.storeModification(replaceMod, replaceReplacementMod);
|
|
||||||
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Thomas Corbat
|
|
||||||
*/
|
|
||||||
public class ReplaceTestSuite {
|
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
TestSuite suite = new TestSuite("ReplaceTestSuite");
|
|
||||||
|
|
||||||
suite.addTest(ArrayModifierTest.suite());
|
|
||||||
suite.addTest(ArraySizeExpressionTest.suite());
|
|
||||||
suite.addTest(CtorChainInitializerTest.suite());
|
|
||||||
suite.addTest(ExceptionTest.suite());
|
|
||||||
suite.addTest(ExpressionTest.suite());
|
|
||||||
suite.addTest(IdenticalTest.suite());
|
|
||||||
suite.addTest(InitializerTest.suite());
|
|
||||||
suite.addTest(MoveRenameTest.suite());
|
|
||||||
suite.addTest(MoveTest.suite());
|
|
||||||
suite.addTest(MultilineWhitespaceHandlingTest.suite());
|
|
||||||
suite.addTest(NameTest.suite());
|
|
||||||
suite.addTest(NestedReplaceTest.suite());
|
|
||||||
suite.addTest(NewInitializerExpressionTest.suite());
|
|
||||||
suite.addTest(PointerInParameterTest.suite());
|
|
||||||
suite.addTest(ReplaceForLoopBodyTest.suite());
|
|
||||||
suite.addTest(ReplaceInsertStatementTest.suite());
|
|
||||||
suite.addTest(ReplaceReplacedNodeTest.suite());
|
|
||||||
suite.addTest(SameNameTest.suite());
|
|
||||||
suite.addTest(StatementTest.suite());
|
|
||||||
suite.addTest(WhitespaceHandlingTest.suite());
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class SameNameTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
public SameNameTest(){
|
|
||||||
super("Replace Name Node Same Name"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
|
|
||||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new SameNameTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitDeclarators = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclarator declarator) {
|
|
||||||
char[] newName = new char[]{'c'};
|
|
||||||
IASTName name = new CPPASTName(newName);
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
public class StatementTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
StatementTest() {
|
|
||||||
super("StatementTest");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new StatementTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif (i < 1) {\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n\tif (i < 1) {\r\n\t\ti++;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (statement instanceof IASTIfStatement) {
|
|
||||||
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
|
||||||
CPPASTCompoundStatement compound = new CPPASTCompoundStatement();
|
|
||||||
|
|
||||||
CPPASTExpressionStatement expr = new CPPASTExpressionStatement(new CPPASTUnaryExpression(IASTUnaryExpression.op_postFixIncr, new CPPASTIdExpression(new CPPASTName("i".toCharArray())))); //$NON-NLS-1$
|
|
||||||
compound.addStatement(expr);
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement.getThenClause(), compound, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011, 2014 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class WhitespaceHandlingTest extends ChangeGeneratorTest {
|
|
||||||
|
|
||||||
private boolean forReplaced = false;
|
|
||||||
|
|
||||||
public WhitespaceHandlingTest(){
|
|
||||||
super("Whitespace Handling in Replace"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
source =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int i = 0; i < 10; i++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int j = 0; j < 10; j++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
"}";
|
|
||||||
expectedSource =
|
|
||||||
"void foo() {\n" +
|
|
||||||
"\n" +
|
|
||||||
" for (int i = 0; i < 10; i++)\n" +
|
|
||||||
" ;\n" +
|
|
||||||
"\n" +
|
|
||||||
"\n" +
|
|
||||||
" for(int j = 0; j < 10; j++){\n" +
|
|
||||||
"\n" +
|
|
||||||
" }\n" +
|
|
||||||
"\n" +
|
|
||||||
"}";
|
|
||||||
forReplaced = false;
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
|
||||||
return new WhitespaceHandlingTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ASTVisitor createModificator(
|
|
||||||
final ASTModificationStore modStore) {
|
|
||||||
return new ASTVisitor() {
|
|
||||||
{
|
|
||||||
shouldVisitStatements = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTStatement statement) {
|
|
||||||
if (!forReplaced && statement instanceof ICPPASTForStatement) {
|
|
||||||
ICPPASTForStatement forStatement = (ICPPASTForStatement) statement;
|
|
||||||
CPPNodeFactory nf = CPPNodeFactory.getDefault();
|
|
||||||
|
|
||||||
ICPPASTForStatement newFor = forStatement.copy(CopyStyle.withLocations);
|
|
||||||
newFor.setBody(nf.newNullStatement());
|
|
||||||
|
|
||||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, forStatement, newFor, null);
|
|
||||||
modStore.storeModification(null, modification);
|
|
||||||
|
|
||||||
forReplaced = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue