use of spoon.reflect.code.CtNewClass in project spoon by INRIA.
the class TypeReferenceTest method testSubTypeAnonymous.
@Test
public void testSubTypeAnonymous() throws Exception {
CtType<Panini> paniniCtType = buildClass(Panini.class);
CtClass anonymousClass = ((CtNewClass) ((CtReturn) paniniCtType.getMethod("entryIterator").getBody().getStatement(0)).getReturnedExpression()).getAnonymousClass();
assertTrue(anonymousClass.getReference().isSubtypeOf(paniniCtType.getFactory().Type().createReference("spoon.test.reference.testclasses.Panini$Itr")));
}
use of spoon.reflect.code.CtNewClass in project spoon by INRIA.
the class NewClassTest method testCtNewClassInNoClasspath.
@Test
public void testCtNewClassInNoClasspath() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/new-class");
launcher.setSourceOutputDirectory("./target/new-class");
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Object> aClass = launcher.getFactory().Class().get("IndexWriter");
final List<CtNewClass> ctNewClasses = aClass.getElements(new TypeFilter<>(CtNewClass.class));
final CtNewClass ctNewClass = ctNewClasses.get(0);
final CtNewClass secondNewClass = ctNewClasses.get(1);
final CtClass anonymousClass = ctNewClass.getAnonymousClass();
assertNotNull(anonymousClass);
assertNotNull(anonymousClass.getSuperclass());
assertEquals("With", anonymousClass.getSuperclass().getSimpleName());
assertEquals("org.apache.lucene.store.Lock$With", anonymousClass.getSuperclass().getQualifiedName());
assertEquals("Lock", anonymousClass.getSuperclass().getDeclaringType().getSimpleName());
assertEquals("org.apache.lucene.store.Lock.With", anonymousClass.getSuperclass().toString());
assertEquals("1", anonymousClass.getSimpleName());
assertEquals("2", secondNewClass.getAnonymousClass().getSimpleName());
assertEquals(1, anonymousClass.getMethods().size());
canBeBuilt("./target/new-class", 8, true);
}
Aggregations