Search in sources :

Example 6 with CtTypedElement

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

the class GenericsTest method testCtTypeReference_getSuperclass.

@Test
public void testCtTypeReference_getSuperclass() throws Exception {
    Factory factory = build(new File("src/test/java/spoon/test/generics/testclasses"));
    CtClass<?> ctClassCelebrationLunch = factory.Class().get(CelebrationLunch.class);
    CtTypeReference<?> trWeddingLunch_Mole = ctClassCelebrationLunch.filterChildren(new NamedElementFilter<>(CtNamedElement.class, "disgust")).map((CtTypedElement te) -> {
        return te.getType();
    }).first();
    assertEquals("spoon.test.generics.testclasses.CelebrationLunch<java.lang.Integer, java.lang.Long, java.lang.Double>.WeddingLunch<spoon.test.generics.testclasses.Mole>", trWeddingLunch_Mole.toString());
    CtType<?> tWeddingLunch_X = trWeddingLunch_Mole.getDeclaration();
    CtTypeReference<?> trCelebrationLunch_Tacos_Paella_X = tWeddingLunch_X.getSuperclass();
    // current correct behavior of CtType#getSuperclass()
    assertEquals("spoon.test.generics.testclasses.CelebrationLunch<" + "spoon.test.generics.testclasses.Tacos, " + "spoon.test.generics.testclasses.Paella, " + "X" + ">", trCelebrationLunch_Tacos_Paella_X.toString());
    // current - wrong behavior of CtTypeReference#getSuperclass()
    assertEquals("spoon.test.generics.testclasses.CelebrationLunch<" + "spoon.test.generics.testclasses.Tacos, " + "spoon.test.generics.testclasses.Paella, " + "X" + ">", trWeddingLunch_Mole.getSuperclass().toString());
// future suggested behavior of CtTypeReference#getSuperclass() - the 3rd argument is Mole.
// assertEquals("spoon.test.generics.testclasses.CelebrationLunch<"
// + "spoon.test.generics.testclasses.Tacos, "
// + "spoon.test.generics.testclasses.Paella, "
// + "spoon.test.generics.testclasses.Mole"
// + ">",trWeddingLunch_Mole.getSuperclass().toString());
// future suggested behavior of CtTypeReference#getSuperclass()
// assertEquals("spoon.test.generics.testclasses.Lunch<"
// + "spoon.test.generics.testclasses.Mole, "
// + "spoon.test.generics.testclasses.Tacos"
// + ">",trWeddingLunch_Mole.getSuperclass().getSuperclass().toString());
}
Also used : ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Factory(spoon.reflect.factory.Factory) CtTypedElement(spoon.reflect.declaration.CtTypedElement) File(java.io.File) CtNamedElement(spoon.reflect.declaration.CtNamedElement) MainTest(spoon.test.main.MainTest) Test(org.junit.Test)

Aggregations

CtTypedElement (spoon.reflect.declaration.CtTypedElement)6 CtNamedElement (spoon.reflect.declaration.CtNamedElement)3 File (java.io.File)2 Test (org.junit.Test)2 Factory (spoon.reflect.factory.Factory)2 MainTest (spoon.test.main.MainTest)2 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)2 ArrayList (java.util.ArrayList)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)1 CtAbstractInvocation (spoon.reflect.code.CtAbstractInvocation)1 CtCatchVariable (spoon.reflect.code.CtCatchVariable)1 CtConstructorCall (spoon.reflect.code.CtConstructorCall)1 CtExpression (spoon.reflect.code.CtExpression)1 CtStatement (spoon.reflect.code.CtStatement)1 CtAnnotatedElementType (spoon.reflect.declaration.CtAnnotatedElementType)1 CtAnnotation (spoon.reflect.declaration.CtAnnotation)1 CtElement (spoon.reflect.declaration.CtElement)1 CtPackage (spoon.reflect.declaration.CtPackage)1 CtTypeParameter (spoon.reflect.declaration.CtTypeParameter)1