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());
}
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");
}
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());
}
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);
}
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);
}
}
Aggregations