use of spoon.reflect.visitor.ImportScannerImpl in project spoon by INRIA.
the class ImportScannerTest method testComputeImportsInClass.
@Test
public void testComputeImportsInClass() throws Exception {
String packageName = "spoon.test.testclasses";
String className = "SampleImportClass";
String qualifiedName = packageName + "." + className;
Factory aFactory = build(packageName, className).getFactory();
CtType<?> theClass = aFactory.Type().get(qualifiedName);
ImportScanner importContext = new ImportScannerImpl();
importContext.computeImports(theClass);
Collection<CtImport> imports = importContext.getAllImports();
// java.lang are also computed
assertEquals(4, imports.size());
}
use of spoon.reflect.visitor.ImportScannerImpl in project spoon by INRIA.
the class ImportScannerTest method testMultiCatchImport.
@Test
public void testMultiCatchImport() throws Exception {
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
SpoonModelBuilder compiler = spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/imports/testclasses/MultiCatch.java"));
compiler.build();
final List<CtClass> classes = Query.getElements(factory, new NamedElementFilter<>(CtClass.class, "MultiCatch"));
ImportScanner importScanner = new ImportScannerImpl();
importScanner.computeImports(classes.get(0));
// as ArithmeticException come from java.lang it is not imported anymore
// assertTrue( importScanner.isImported( factory.Type().createReference( ArithmeticException.class ) ));
assertTrue(importScanner.isImported(factory.Type().createReference(AccessControlException.class)));
}
use of spoon.reflect.visitor.ImportScannerImpl in project spoon by INRIA.
the class ImportScannerTest method testComputeImportsInClassWithSameName.
@Test
public void testComputeImportsInClassWithSameName() throws Exception {
String packageName = "spoon.test.imports.testclasses2";
String className = "ImportSameName";
String qualifiedName = packageName + "." + className;
Launcher spoon = new Launcher();
spoon.addInputResource("src/test/resources/spoon/test/imports/testclasses2/");
spoon.buildModel();
Factory aFactory = spoon.getFactory();
CtType<?> theClass = aFactory.Type().get(qualifiedName);
ImportScanner importContext = new ImportScannerImpl();
importContext.computeImports(theClass);
Collection<CtImport> imports = importContext.getAllImports();
assertEquals(0, imports.size());
}
Aggregations