Search in sources :

Example 1 with SubClass

use of spoon.test.imports.testclasses.SubClass in project spoon by INRIA.

the class ImportTest method testNewInnerClassDefinesInItsClassAndSuperClass.

@Test
public void testNewInnerClassDefinesInItsClassAndSuperClass() throws Exception {
    Launcher spoon = new Launcher();
    spoon.setArgs(new String[] { "--output-type", "nooutput" });
    Factory factory = spoon.createFactory();
    SpoonModelBuilder compiler = spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/imports/testclasses/SuperClass.java", "./src/test/java/spoon/test/imports/testclasses/SubClass.java"));
    compiler.build();
    final CtClass<?> subClass = (CtClass<?>) factory.Type().get(SubClass.class);
    final CtConstructorCall<?> ctConstructorCall = subClass.getElements(new TypeFilter<CtConstructorCall<?>>(CtConstructorCall.class)).get(0);
    assertEquals("new spoon.test.imports.testclasses.SubClass.Item(\"\")", ctConstructorCall.toString());
    // here the buggy behavior with type members was encoded
    // so we fix it
    final String expected = "public class SubClass extends spoon.test.imports.testclasses.SuperClass {" + System.lineSeparator() + "    public void aMethod() {" + System.lineSeparator() + "        new spoon.test.imports.testclasses.SubClass.Item(\"\");" + System.lineSeparator() + "    }" + System.lineSeparator() + System.lineSeparator() + "    public static class Item extends spoon.test.imports.testclasses.SuperClass.Item {" + System.lineSeparator() + "        public Item(java.lang.String s) {" + System.lineSeparator() + "            super(1, s);" + System.lineSeparator() + "        }" + System.lineSeparator() + "    }" + System.lineSeparator() + "}";
    assertEquals(expected, subClass.toString());
}
Also used : SubClass(spoon.test.imports.testclasses.SubClass) SpoonModelBuilder(spoon.SpoonModelBuilder) CtClass(spoon.reflect.declaration.CtClass) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 SpoonModelBuilder (spoon.SpoonModelBuilder)1 CtClass (spoon.reflect.declaration.CtClass)1 Factory (spoon.reflect.factory.Factory)1 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)1 SubClass (spoon.test.imports.testclasses.SubClass)1