use of spoon.test.field.testclasses.BaseClass in project spoon by INRIA.
the class FieldTest method testGetDefaultExpression.
@Test
public void testGetDefaultExpression() throws Exception {
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/field/testclasses/A.java");
spoon.addInputResource("./src/test/java/spoon/test/field/testclasses/BaseClass.java");
spoon.buildModel();
final CtClass<A> aClass = spoon.getFactory().Class().get(A.class);
CtClass<A.ClassB> bClass = aClass.getFactory().Class().get(A.ClassB.class);
List<CtMethod<?>> methods = bClass.getMethodsByName("getKey");
assertEquals(1, methods.size());
CtReturn<?> returnExpression = methods.get(0).getBody().getStatement(0);
CtFieldRead fieldRead = (CtFieldRead) returnExpression.getReturnedExpression();
assertEquals("spoon.test.field.testclasses.BaseClass.PREFIX", fieldRead.toString());
CtField<?> field = fieldRead.getVariable().getDeclaration();
CtClass<BaseClass> baseClass = aClass.getFactory().Class().get(BaseClass.class);
CtField<?> expectedField = baseClass.getField("PREFIX");
assertEquals(expectedField, field);
VisitorPartialEvaluator visitorPartial = new VisitorPartialEvaluator();
Object retour = visitorPartial.evaluate(methods.get(0));
assertTrue(retour != null);
}
Aggregations