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