Search in sources :

Example 16 with CtImport

use of spoon.reflect.declaration.CtImport in project spoon by INRIA.

the class ImportTest method testEqualsImports.

@Test
public void testEqualsImports() {
    // contract: two imports of same kind with same reference should be equals
    final Launcher launcher = new Launcher();
    CtType typeA = launcher.getFactory().Type().get(A.class);
    CtImport importsA1 = launcher.getFactory().createImport(typeA.getReference());
    CtImport importsA2 = launcher.getFactory().createImport(typeA.getReference());
    assertEquals(importsA1, importsA2);
    assertEquals(importsA1.hashCode(), importsA2.hashCode());
    CtType typeB = launcher.getFactory().Type().get(Pozole.class);
    CtImport importsB = launcher.getFactory().createImport(typeB.getReference());
    assertNotEquals(importsA1, importsB);
    assertNotEquals(importsA1.hashCode(), importsB.hashCode());
}
Also used : CtImport(spoon.reflect.declaration.CtImport) CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 17 with CtImport

use of spoon.reflect.declaration.CtImport 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 18 with CtImport

use of spoon.reflect.declaration.CtImport in project spoon by INRIA.

the class ImportScannerTest method testTargetTypeNull.

@Test
public void testTargetTypeNull() throws Exception {
    Launcher spoon = new Launcher();
    Factory factory = spoon.createFactory();
    CtFieldReference fieldRef = factory.createFieldReference();
    fieldRef.setStatic(true);
    ImportScanner importScanner = new MinimalImportScanner();
    importScanner.computeImports(fieldRef);
    Collection<CtImport> imports = importScanner.getAllImports();
    assertEquals(0, imports.size());
}
Also used : CtImport(spoon.reflect.declaration.CtImport) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) CtFieldReference(spoon.reflect.reference.CtFieldReference) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) ImportScanner(spoon.reflect.visitor.ImportScanner) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) Test(org.junit.Test)

Example 19 with CtImport

use of spoon.reflect.declaration.CtImport in project spoon by INRIA.

the class ImportScannerTest method testComputeMinimalImportsInClass.

@Test
public void testComputeMinimalImportsInClass() 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 MinimalImportScanner();
    importContext.computeImports(theClass);
    Collection<CtImport> imports = importContext.getAllImports();
    assertTrue(imports.isEmpty());
}
Also used : CtImport(spoon.reflect.declaration.CtImport) Factory(spoon.reflect.factory.Factory) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) ImportScanner(spoon.reflect.visitor.ImportScanner) MinimalImportScanner(spoon.reflect.visitor.MinimalImportScanner) Test(org.junit.Test)

Example 20 with CtImport

use of spoon.reflect.declaration.CtImport 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

CtImport (spoon.reflect.declaration.CtImport)22 Test (org.junit.Test)15 Launcher (spoon.Launcher)9 ImportScanner (spoon.reflect.visitor.ImportScanner)8 Factory (spoon.reflect.factory.Factory)7 ImportScannerImpl (spoon.reflect.visitor.ImportScannerImpl)6 CompilationUnit (spoon.reflect.cu.CompilationUnit)5 CtClass (spoon.reflect.declaration.CtClass)5 CtTypeReference (spoon.reflect.reference.CtTypeReference)5 CtType (spoon.reflect.declaration.CtType)4 MinimalImportScanner (spoon.reflect.visitor.MinimalImportScanner)4 CtFieldReference (spoon.reflect.reference.CtFieldReference)3 CtPackageReference (spoon.reflect.reference.CtPackageReference)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CtMethod (spoon.reflect.declaration.CtMethod)2 DefaultJavaPrettyPrinter (spoon.reflect.visitor.DefaultJavaPrettyPrinter)2 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)1 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)1 Minimizer (fr.inria.stamp.minimization.Minimizer)1