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