Search in sources :

Example 56 with CtType

use of spoon.reflect.declaration.CtType in project spoon by INRIA.

the class CtRenameLocalVariableRefactoringTest method testRenameLocalVariableToSameName.

@Test
public void testRenameLocalVariableToSameName() throws Exception {
    CtType varRenameClass = ModelUtils.buildClass(CtRenameLocalVariableRefactoringTestSubject.class);
    CtLocalVariable<?> local1Var = varRenameClass.filterChildren((CtLocalVariable<?> var) -> var.getSimpleName().equals("local1")).first();
    CtRenameLocalVariableRefactoring refactor = new CtRenameLocalVariableRefactoring();
    refactor.setTarget(local1Var);
    refactor.setNewName("local1");
    refactor.refactor();
    assertEquals("local1", local1Var.getSimpleName());
}
Also used : CtRenameLocalVariableRefactoring(spoon.refactoring.CtRenameLocalVariableRefactoring) CtType(spoon.reflect.declaration.CtType) Test(org.junit.Test)

Example 57 with CtType

use of spoon.reflect.declaration.CtType in project spoon by INRIA.

the class MethodsRefactoringTest method testSubInheritanceHierarchyFunction.

@Test
public void testSubInheritanceHierarchyFunction() {
    Factory factory = ModelUtils.build(new File("./src/test/java/spoon/test/refactoring/parameter/testclasses"));
    List<String> allSubtypes = factory.Class().get(TypeA.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    checkContainsOnly(allSubtypes, "spoon.test.refactoring.parameter.testclasses.TypeB", "spoon.test.refactoring.parameter.testclasses.TypeB$1", "spoon.test.refactoring.parameter.testclasses.TypeC");
    allSubtypes = factory.Class().get(TypeB.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    checkContainsOnly(allSubtypes, "spoon.test.refactoring.parameter.testclasses.TypeB$1", "spoon.test.refactoring.parameter.testclasses.TypeC");
    allSubtypes = factory.Class().get(TypeC.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    assertEquals(0, allSubtypes.size());
    allSubtypes = factory.Interface().get(IFaceB.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    checkContainsOnly(allSubtypes, "spoon.test.refactoring.parameter.testclasses.TypeB", "spoon.test.refactoring.parameter.testclasses.TypeB$1", "spoon.test.refactoring.parameter.testclasses.TypeB$1Local", "spoon.test.refactoring.parameter.testclasses.TypeB$2", "spoon.test.refactoring.parameter.testclasses.TypeC", "spoon.test.refactoring.parameter.testclasses.IFaceL", "spoon.test.refactoring.parameter.testclasses.TypeL", "spoon.test.refactoring.parameter.testclasses.TypeM");
    allSubtypes = factory.Interface().get(IFaceL.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    checkContainsOnly(allSubtypes, "spoon.test.refactoring.parameter.testclasses.TypeB$1Local", "spoon.test.refactoring.parameter.testclasses.TypeL", "spoon.test.refactoring.parameter.testclasses.TypeM");
    allSubtypes = factory.Interface().get(IFaceK.class).map(new SubInheritanceHierarchyFunction()).map((CtType type) -> type.getQualifiedName()).list();
    checkContainsOnly(allSubtypes, "spoon.test.refactoring.parameter.testclasses.TypeB$1Local", "spoon.test.refactoring.parameter.testclasses.TypeL", "spoon.test.refactoring.parameter.testclasses.TypeM", "spoon.test.refactoring.parameter.testclasses.TypeK", "spoon.test.refactoring.parameter.testclasses.TypeR", "spoon.test.refactoring.parameter.testclasses.TypeS");
}
Also used : CtType(spoon.reflect.declaration.CtType) Factory(spoon.reflect.factory.Factory) File(java.io.File) SubInheritanceHierarchyFunction(spoon.reflect.visitor.filter.SubInheritanceHierarchyFunction) TypeA(spoon.test.refactoring.parameter.testclasses.TypeA) Test(org.junit.Test)

Example 58 with CtType

use of spoon.reflect.declaration.CtType in project spoon by INRIA.

the class LinesTest method testCompileWhenUsingLinesArgument.

@Test
public void testCompileWhenUsingLinesArgument() {
    final Launcher launcher = new Launcher();
    launcher.setArgs(new String[] { "--compile", "--with-imports", "--lines" });
    launcher.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/FooCasper.java");
    launcher.run();
    List<CtType> fooCasperClass = launcher.getModel().getElements(new NamedElementFilter<>(CtType.class, "FooCasper"));
    assertEquals(1, fooCasperClass.size());
}
Also used : CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 59 with CtType

use of spoon.reflect.declaration.CtType in project spoon by INRIA.

the class PrinterTest method testJDTBatchCompilerCanBeBuild.

@Test
public void testJDTBatchCompilerCanBeBuild() {
    Launcher spoon = new Launcher();
    PrettyPrinter printer = spoon.createPrettyPrinter();
    spoon.getEnvironment().setAutoImports(false);
    String output = "./target/spoon-jdtbatchcompiler/";
    spoon.addInputResource("./src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java");
    spoon.setSourceOutputDirectory(output);
    spoon.run();
    CtType element = spoon.getFactory().Class().getAll().get(0);
    List<CtType<?>> toPrint = new ArrayList<>();
    toPrint.add(element);
    printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
    String result = printer.getResult();
    // assertTrue("The result should contain direct this accessor for field: "+result, !result.contains("Rule.Phoneme.this.phonemeText"));
    canBeBuilt(output, 7);
}
Also used : PrettyPrinter(spoon.reflect.visitor.PrettyPrinter) DefaultJavaPrettyPrinter(spoon.reflect.visitor.DefaultJavaPrettyPrinter) CtType(spoon.reflect.declaration.CtType) ArrayList(java.util.ArrayList) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 60 with CtType

use of spoon.reflect.declaration.CtType in project spoon by INRIA.

the class ProcessingTest method testProcessorWithGenericType.

@Test
public void testProcessorWithGenericType() {
    // contract: we can use generic type for another abstract processor
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/imports/testclasses");
    CtClassProcessor classProcessor = new CtClassProcessor();
    spoon.addProcessor(classProcessor);
    spoon.run();
    assertFalse(classProcessor.elements.isEmpty());
    for (CtType type : classProcessor.elements) {
        assertTrue("Type " + type.getSimpleName() + " is not a class", type instanceof CtClass);
    }
}
Also used : CtClass(spoon.reflect.declaration.CtClass) CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) CtClassProcessor(spoon.test.processing.testclasses.CtClassProcessor) Test(org.junit.Test)

Aggregations

CtType (spoon.reflect.declaration.CtType)134 Test (org.junit.Test)67 Launcher (spoon.Launcher)60 ArrayList (java.util.ArrayList)42 CtMethod (spoon.reflect.declaration.CtMethod)38 CtTypeReference (spoon.reflect.reference.CtTypeReference)30 DefaultJavaPrettyPrinter (spoon.reflect.visitor.DefaultJavaPrettyPrinter)20 File (java.io.File)19 Factory (spoon.reflect.factory.Factory)19 PrettyPrinter (spoon.reflect.visitor.PrettyPrinter)19 List (java.util.List)18 Collectors (java.util.stream.Collectors)17 CtField (spoon.reflect.declaration.CtField)17 CtElement (spoon.reflect.declaration.CtElement)16 CtPackage (spoon.reflect.declaration.CtPackage)16 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)14 IOException (java.io.IOException)12 SpoonException (spoon.SpoonException)12 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)11 Set (java.util.Set)11