use of spoon.reflect.declaration.CtImport in project spoon by INRIA.
the class ImportBuilderTest method testSimpleStaticImport.
@Test
public void testSimpleStaticImport() {
// contract: simple static import are imported correctly
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/StaticImport.java");
spoon.getEnvironment().setAutoImports(true);
spoon.buildModel();
CtClass classA = spoon.getFactory().Class().get(StaticImport.class);
CompilationUnit unitA = spoon.getFactory().CompilationUnit().getMap().get(classA.getPosition().getFile().getPath());
Collection<CtImport> imports = unitA.getImports();
assertEquals(1, imports.size());
CtImport ref = imports.iterator().next();
assertTrue(ref.getReference() instanceof CtFieldReference);
assertEquals("spoon.test.jdtimportbuilder.testclasses.staticimport.Dependency#ANY", ((CtFieldReference) ref.getReference()).getQualifiedName());
}
use of spoon.reflect.declaration.CtImport in project spoon by INRIA.
the class QualifiedThisRefTest method testQualifiedThisRef.
@Test
public void testQualifiedThisRef() {
DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(factory.getEnvironment());
CtType<?> ctClass = factory.Type().get(QualifiedThisRef.class);
Collection<CtImport> imports = printer.computeImports(ctClass);
final List<CtType<?>> ctTypes = new ArrayList<>();
ctTypes.add(ctClass);
printer.getElementPrinterHelper().writeHeader(ctTypes, imports);
printer.scan(ctClass);
Assert.assertTrue(printer.getResult().contains("Object o = this"));
Assert.assertTrue(printer.getResult().contains("Object o2 = QualifiedThisRef.this"));
}
Aggregations