Search in sources :

Example 6 with SpoonResource

use of spoon.compiler.SpoonResource in project spoon by INRIA.

the class SnippetTest method testIssue981.

@Test
public void testIssue981() throws Exception {
    // contract: one can get the package of a string
    Launcher spoon = new Launcher();
    spoon.getEnvironment().setNoClasspath(true);
    SpoonResource input = new VirtualFile("package foo.bar; class X {}");
    spoon.addInputResource(input);
    spoon.buildModel();
    assertEquals("foo.bar", spoon.getFactory().Type().get("foo.bar.X").getPackage().getQualifiedName());
}
Also used : VirtualFile(spoon.support.compiler.VirtualFile) Launcher(spoon.Launcher) SpoonResource(spoon.compiler.SpoonResource) Test(org.junit.Test)

Example 7 with SpoonResource

use of spoon.compiler.SpoonResource in project spoon by INRIA.

the class ImportTest method testImportOfAnInnerClassInASuperClassAvailableInLibrary.

@Test
public void testImportOfAnInnerClassInASuperClassAvailableInLibrary() throws Exception {
    SpoonModelBuilder comp = new Launcher().createCompiler();
    List<SpoonResource> fileToBeSpooned = SpoonResourceHelper.resources("./src/test/resources/visibility/YamlRepresenter.java");
    assertEquals(1, fileToBeSpooned.size());
    comp.addInputSources(fileToBeSpooned);
    List<SpoonResource> classpath = SpoonResourceHelper.resources("./src/test/resources/visibility/snakeyaml-1.9.jar");
    assertEquals(1, classpath.size());
    comp.setSourceClasspath(classpath.get(0).getPath());
    comp.build();
    Factory factory = comp.getFactory();
    CtType<?> theClass = factory.Type().get("visibility.YamlRepresenter");
    final CtClass<?> innerClass = theClass.getNestedType("RepresentConfigurationSection");
    String expected = "visibility.YamlRepresenter.RepresentConfigurationSection";
    assertEquals(expected, innerClass.getReference().toString());
    expected = "org.yaml.snakeyaml.representer.Representer.RepresentMap";
    assertEquals(expected, innerClass.getSuperclass().toString());
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SpoonResource(spoon.compiler.SpoonResource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Launcher (spoon.Launcher)7 SpoonResource (spoon.compiler.SpoonResource)7 Factory (spoon.reflect.factory.Factory)6 SpoonModelBuilder (spoon.SpoonModelBuilder)5 CtTypeReference (spoon.reflect.reference.CtTypeReference)3 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CtAssignment (spoon.reflect.code.CtAssignment)1 CtInvocation (spoon.reflect.code.CtInvocation)1 CtNewClass (spoon.reflect.code.CtNewClass)1 CtClass (spoon.reflect.declaration.CtClass)1 CtEnum (spoon.reflect.declaration.CtEnum)1 CtField (spoon.reflect.declaration.CtField)1 CtType (spoon.reflect.declaration.CtType)1 CtFieldReference (spoon.reflect.reference.CtFieldReference)1 ReferenceTypeFilter (spoon.reflect.visitor.filter.ReferenceTypeFilter)1 VirtualFile (spoon.support.compiler.VirtualFile)1 ModelUtils.buildClass (spoon.testing.utils.ModelUtils.buildClass)1