Search in sources :

Example 21 with CtImport

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

the class ImportBuilderTest method testSimpleStaticImport.

@Test
public void testSimpleStaticImport() {
    // contract: simple static import are imported correctly
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/jdtimportbuilder/testclasses/StaticImport.java");
    spoon.getEnvironment().setAutoImports(true);
    spoon.buildModel();
    CtClass classA = spoon.getFactory().Class().get(StaticImport.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();
    assertTrue(ref.getReference() instanceof CtFieldReference);
    assertEquals("spoon.test.jdtimportbuilder.testclasses.staticimport.Dependency#ANY", ((CtFieldReference) ref.getReference()).getQualifiedName());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtClass(spoon.reflect.declaration.CtClass) CtImport(spoon.reflect.declaration.CtImport) Launcher(spoon.Launcher) CtFieldReference(spoon.reflect.reference.CtFieldReference) Test(org.junit.Test)

Example 22 with CtImport

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

the class QualifiedThisRefTest method testQualifiedThisRef.

@Test
public void testQualifiedThisRef() {
    DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(factory.getEnvironment());
    CtType<?> ctClass = factory.Type().get(QualifiedThisRef.class);
    Collection<CtImport> imports = printer.computeImports(ctClass);
    final List<CtType<?>> ctTypes = new ArrayList<>();
    ctTypes.add(ctClass);
    printer.getElementPrinterHelper().writeHeader(ctTypes, imports);
    printer.scan(ctClass);
    Assert.assertTrue(printer.getResult().contains("Object o = this"));
    Assert.assertTrue(printer.getResult().contains("Object o2 = QualifiedThisRef.this"));
}
Also used : CtImport(spoon.reflect.declaration.CtImport) CtType(spoon.reflect.declaration.CtType) ArrayList(java.util.ArrayList) DefaultJavaPrettyPrinter(spoon.reflect.visitor.DefaultJavaPrettyPrinter) 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