use of spoon.support.reflect.code.CtFieldAccessImpl in project spoon by INRIA.
the class QualifiedThisRefTest method testPrintCtFieldAccessWorkEvenWhenParentNotInitialized.
@Test
public void testPrintCtFieldAccessWorkEvenWhenParentNotInitialized() throws Exception {
CtClass zeclass = factory.Class().get(QualifiedThisRef.class);
List<CtMethod> methods = zeclass.getMethodsByName("bla");
assertEquals(1, methods.size());
CtStatement invocation = methods.get(0).getBody().getStatement(0);
assertTrue(invocation instanceof CtInvocation);
CtInvocation<?> arg0 = (CtInvocation) invocation;
CtExpression param = arg0.getArguments().get(0);
CtExecutableReference execref = factory.Core().createExecutableReference();
execref.setDeclaringType(factory.Type().createReference("java.util.Map"));
execref.setSimpleName("exorcise");
execref.setStatic(true);
CtTypeReference tmp = param.getType();
CtExpression arg = null;
CtFieldReference ctfe = factory.createFieldReference();
ctfe.setSimpleName("class");
ctfe.setDeclaringType(tmp.box());
arg = factory.Core().createFieldRead();
((CtFieldAccessImpl) arg).setVariable(ctfe);
CtLiteral location = factory.Core().createLiteral();
location.setType(factory.Type().createReference(String.class));
CtTypeReference tmpref = factory.Core().clone(tmp);
CtInvocation invoc = factory.Core().createInvocation();
invoc.setExecutable(execref);
invoc.setArguments(Arrays.asList(new CtExpression[] { param, arg, location }));
execref.setActualTypeArguments(Arrays.asList(new CtTypeReference<?>[] { tmpref }));
// succeeds
arg0.getArguments().set(0, invoc);
DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(factory.getEnvironment());
printer.visitCtClass(zeclass);
assertFalse(printer.getResult().isEmpty());
}
Aggregations