Search in sources :

Example 1 with CtParameterRemoveRefactoring

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();
    }
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtParameterRemoveRefactoring(spoon.refactoring.CtParameterRemoveRefactoring) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) RefactoringException(spoon.refactoring.RefactoringException) File(java.io.File) CtExecutable(spoon.reflect.declaration.CtExecutable) Test(org.junit.Test)

Example 2 with CtParameterRemoveRefactoring

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);
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtParameterRemoveRefactoring(spoon.refactoring.CtParameterRemoveRefactoring) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) File(java.io.File) CtExecutable(spoon.reflect.declaration.CtExecutable) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Test (org.junit.Test)2 Launcher (spoon.Launcher)2 SpoonModelBuilder (spoon.SpoonModelBuilder)2 CtParameterRemoveRefactoring (spoon.refactoring.CtParameterRemoveRefactoring)2 CtExecutable (spoon.reflect.declaration.CtExecutable)2 Factory (spoon.reflect.factory.Factory)2 RefactoringException (spoon.refactoring.RefactoringException)1