Search in sources :

Example 6 with CtImport

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

the class EqualsChecker method visitCtImport.

@Override
public void visitCtImport(CtImport ctImport) {
    final CtImport peek = (CtImport) this.other;
    if (ctImport.getImportKind() == null) {
        if (peek.getImportKind() != null) {
            isNotEqual = true;
            return;
        }
    } else if (peek.getImportKind() == null) {
        isNotEqual = true;
        return;
    } else if (!ctImport.getImportKind().equals(peek.getImportKind())) {
        isNotEqual = true;
        return;
    }
    super.visitCtImport(ctImport);
}
Also used : CtImport(spoon.reflect.declaration.CtImport)

Example 7 with CtImport

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

the class ImportBuilderTest method testWithStaticStarredImportFromInterface.

@Test
public void testWithStaticStarredImportFromInterface() {
    // contract: when a starred import is used with a target package, all classes of the package should be imported
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/StarredImport.java");
    spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/fullpack/");
    spoon.getEnvironment().setAutoImports(true);
    spoon.buildModel();
    CtClass classA = spoon.getFactory().Class().get(StarredImport.class);
    CompilationUnit unitA = spoon.getFactory().CompilationUnit().getMap().get(classA.getPosition().getFile().getPath());
    Collection<CtImport> imports = unitA.getImports();
    assertEquals(1, imports.size());
    Iterator<CtImport> iterator = imports.iterator();
    CtImport ctImport = iterator.next();
    assertEquals(CtImportKind.ALL_TYPES, ctImport.getImportKind());
    assertTrue(ctImport.getReference() instanceof CtPackageReference);
    CtPackageReference ref = (CtPackageReference) ctImport.getReference();
    assertEquals("spoon.test.jdtimportbuilder.testclasses.fullpack", ref.getQualifiedName());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtClass(spoon.reflect.declaration.CtClass) CtImport(spoon.reflect.declaration.CtImport) CtPackageReference(spoon.reflect.reference.CtPackageReference) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 8 with CtImport

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

the class ImportBuilderTest method testWithImportFromItf.

@Test
public void testWithImportFromItf() {
    // contract: When using starred static import of an interface, it imports a starred type
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/resources/jdtimportbuilder/");
    spoon.getEnvironment().setAutoImports(true);
    spoon.getEnvironment().setShouldCompile(true);
    spoon.setSourceOutputDirectory("./target/spoon-jdtimport-itfimport");
    spoon.run();
    CtClass classStatic = spoon.getFactory().Class().get("jdtimportbuilder.ItfImport");
    CompilationUnit unitStatic = spoon.getFactory().CompilationUnit().getMap().get(classStatic.getPosition().getFile().getPath());
    Collection<CtImport> imports = unitStatic.getImports();
    assertEquals(1, imports.size());
    CtImport ctImport = imports.iterator().next();
    assertEquals(CtImportKind.ALL_STATIC_MEMBERS, ctImport.getImportKind());
    assertEquals("import static jdtimportbuilder.itf.DumbItf.*;\n", ctImport.toString());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtClass(spoon.reflect.declaration.CtClass) CtImport(spoon.reflect.declaration.CtImport) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 9 with CtImport

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

the class ImportBuilderTest method testWithStaticInheritedImport.

@Test
public void testWithStaticInheritedImport() {
    // contract: When using starred static import of a type, it imports a starred type
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/StaticImportWithInheritance.java");
    spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/staticimport");
    spoon.getEnvironment().setAutoImports(true);
    spoon.getEnvironment().setShouldCompile(true);
    spoon.setSourceOutputDirectory("./target/spoon-jdtimport-inheritedstatic");
    spoon.run();
    CtClass classStatic = spoon.getFactory().Class().get(StaticImportWithInheritance.class);
    CompilationUnit unitStatic = spoon.getFactory().CompilationUnit().getMap().get(classStatic.getPosition().getFile().getPath());
    Collection<CtImport> imports = unitStatic.getImports();
    assertEquals(1, imports.size());
    CtImport ctImport = imports.iterator().next();
    assertEquals(CtImportKind.ALL_STATIC_MEMBERS, ctImport.getImportKind());
    assertEquals("import static spoon.test.jdtimportbuilder.testclasses.staticimport.DependencySubClass.*;\n", ctImport.toString());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtClass(spoon.reflect.declaration.CtClass) CtImport(spoon.reflect.declaration.CtImport) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 10 with CtImport

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

the class ImportBuilderTest method testWithSimpleImport.

@Test
public void testWithSimpleImport() {
    // contract: when the source has one import, the same import is created as a reference in auto-import mode
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/imports/testclasses/ClassWithInvocation.java");
    spoon.getEnvironment().setAutoImports(true);
    spoon.buildModel();
    CtClass classA = spoon.getFactory().Class().get(ClassWithInvocation.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();
    assertEquals("import spoon.test.annotation.testclasses.GlobalAnnotation;\n", ref.toString());
    assertTrue(ref.getReference() instanceof CtTypeReference);
    CtTypeReference refType = (CtTypeReference) ref.getReference();
    assertEquals("spoon.test.annotation.testclasses.GlobalAnnotation", refType.getQualifiedName());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtClass(spoon.reflect.declaration.CtClass) CtImport(spoon.reflect.declaration.CtImport) CtTypeReference(spoon.reflect.reference.CtTypeReference) Launcher(spoon.Launcher) 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