Search in sources :

Example 6 with ImportScannerImpl

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());
}
Also used : ImportScannerImpl(spoon.reflect.visitor.ImportScannerImpl) CtImport(spoon.reflect.declaration.CtImport) Factory(spoon.reflect.factory.Factory) ImportScanner(spoon.reflect.visitor.ImportScanner) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) Test(org.junit.Test)

Example 7 with ImportScannerImpl

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)));
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtClass(spoon.reflect.declaration.CtClass) ImportScannerImpl(spoon.reflect.visitor.ImportScannerImpl) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) ImportScanner(spoon.reflect.visitor.ImportScanner) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) Test(org.junit.Test)

Example 8 with ImportScannerImpl

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());
}
Also used : ImportScannerImpl(spoon.reflect.visitor.ImportScannerImpl) CtImport(spoon.reflect.declaration.CtImport) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) ImportScanner(spoon.reflect.visitor.ImportScanner) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) Test(org.junit.Test)

Aggregations

ImportScanner (spoon.reflect.visitor.ImportScanner)8 ImportScannerImpl (spoon.reflect.visitor.ImportScannerImpl)8 Test (org.junit.Test)7 CtImport (spoon.reflect.declaration.CtImport)6 Factory (spoon.reflect.factory.Factory)6 Launcher (spoon.Launcher)3 MinimalImportScanner (spoon.reflect.visitor.MinimalImportScanner)3 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)1 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)1 Minimizer (fr.inria.stamp.minimization.Minimizer)1 TestListener (fr.inria.stamp.test.listener.TestListener)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 HashSet (java.util.HashSet)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Description (org.junit.runner.Description)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1