use of spoon.refactoring.CtParameterRemoveRefactoring in project spoon by INRIA.
the class MethodsRefactoringTest method testCtParameterRemoveRefactoringValidationCheck.
@Test
public void testCtParameterRemoveRefactoringValidationCheck() throws FileNotFoundException {
String testPackagePath = "spoon/test/refactoring/parameter/testclasses";
final Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
SpoonModelBuilder comp = launcher.createCompiler();
comp.addInputSource(SpoonResourceHelper.createResource(new File("./src/test/java/" + testPackagePath)));
comp.build();
Factory factory = comp.getFactory();
CtType<?> typeR = factory.Class().get(TypeR.class);
CtMethod<?> methodTypeR_method1 = typeR.getMethodsByName("method1").get(0);
CtParameterRemoveRefactoring refactor = new CtParameterRemoveRefactoring().setTarget(methodTypeR_method1.getParameters().get(0));
refactor.setTarget(methodTypeR_method1.getParameters().get(0));
// check that each to be refactored method has one parameter
List<CtExecutable<?>> execs = refactor.getTargetExecutables();
execs.forEach(exec -> {
// check that each to be modified method has one parameter
assertEquals(1, exec.getParameters().size());
});
// try refactor
try {
refactor.refactor();
fail();
} catch (RefactoringException e) {
this.getClass();
}
}
use of spoon.refactoring.CtParameterRemoveRefactoring in project spoon by INRIA.
the class MethodsRefactoringTest method testCtParameterRemoveRefactoring.
@Test
public void testCtParameterRemoveRefactoring() throws FileNotFoundException {
String testPackagePath = "spoon/test/refactoring/parameter/testclasses";
final Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
SpoonModelBuilder comp = launcher.createCompiler();
comp.addInputSource(SpoonResourceHelper.createResource(new File("./src/test/java/" + testPackagePath)));
comp.build();
Factory factory = comp.getFactory();
CtType<?> typeA = factory.Class().get(TypeA.class);
CtMethod<?> methodTypeA_method1 = typeA.getMethodsByName("method1").get(0);
CtParameterRemoveRefactoring refactor = new CtParameterRemoveRefactoring();
refactor.setTarget(methodTypeA_method1.getParameters().get(0));
// check that expected methods are targets of refactoring
List<CtExecutable<?>> execs = refactor.getTargetExecutables();
execs.forEach(exec -> {
// check that each to be modified method has one parameter
assertEquals(1, exec.getParameters().size());
});
refactor.refactor();
execs.forEach(exec -> {
// check that each to be modified method has no parameter after refactoring
assertEquals(0, exec.getParameters().size());
});
launcher.setSourceOutputDirectory(new File("./target/spooned/"));
launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES);
ModelUtils.canBeBuilt("./target/spooned/" + testPackagePath, 8);
}
Aggregations