use of spoon.reflect.code.CtVariableWrite in project spoon by INRIA.
the class AccessTest method testCanVisitVariableAccessAndSubClasses.
@Test
public void testCanVisitVariableAccessAndSubClasses() throws Exception {
final Factory factory = build(VariableAccessSample.class);
final List<CtVariableRead<?>> variablesRead = Query.getElements(factory, new AbstractFilter<CtVariableRead<?>>(CtVariableRead.class) {
@Override
public boolean matches(CtVariableRead<?> element) {
return super.matches(element);
}
});
// System.out and s
assertEquals(2, variablesRead.size());
final List<CtVariableWrite<?>> variablesWrite = Query.getElements(factory, new AbstractFilter<CtVariableWrite<?>>(CtVariableWrite.class) {
@Override
public boolean matches(CtVariableWrite<?> element) {
return super.matches(element);
}
});
assertEquals(1, variablesWrite.size());
final List<CtVariableAccess<?>> variablesAccess = Query.getElements(factory, new AbstractFilter<CtVariableAccess<?>>(CtVariableAccess.class) {
@Override
public boolean matches(CtVariableAccess<?> element) {
return super.matches(element);
}
});
assertEquals(3, variablesAccess.size());
}
use of spoon.reflect.code.CtVariableWrite in project spoon by INRIA.
the class FieldAccessTest method testFieldAccessOnUnknownType.
@Test
public void testFieldAccessOnUnknownType() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/noclasspath/FieldAccessRes.java");
launcher.getEnvironment().setNoClasspath(true);
launcher.buildModel();
class CounterScanner extends CtScanner {
private int visited = 0;
@Override
public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
visited++;
assertEquals("array", ((CtVariableWrite) fieldWrite.getTarget()).getVariable().getSimpleName());
assertEquals("length", fieldWrite.getVariable().getSimpleName());
}
}
CounterScanner scanner = new CounterScanner();
launcher.getFactory().Class().get("FieldAccessRes").accept(scanner);
assertEquals(1, scanner.visited);
}
Aggregations