use of spoon.reflect.cu.CompilationUnit in project spoon by INRIA.
the class ImportBuilderTest method testInternalImportWhenNoClasspath.
@Test
public void testInternalImportWhenNoClasspath() {
// contract: in no-classpath anything which is not loaded cannot be imported, even if original source code has imports
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/resources/noclasspath/Attachment.java");
spoon.getEnvironment().setAutoImports(true);
spoon.getEnvironment().setNoClasspath(true);
spoon.buildModel();
CtClass classA = spoon.getFactory().Class().get("it.feio.android.omninotes.models.Attachment");
CompilationUnit unitA = spoon.getFactory().CompilationUnit().getMap().get(classA.getPosition().getFile().getPath());
assertTrue(unitA.getImports().isEmpty());
}
use of spoon.reflect.cu.CompilationUnit 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());
}
Aggregations