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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations