use of spoon.reflect.visitor.filter.ParameterScopeFunction in project spoon by INRIA.
the class VariableReferencesTest method testVariableScopeFunction.
@Test
public void testVariableScopeFunction() throws Exception {
// visits all the CtVariable elements whose name is "field" and search for all elements in their scopes
// Comparing with the result found by basic functions
List list = modelClass.filterChildren((CtVariable<?> var) -> {
if (var.getSimpleName().equals("field")) {
if (var instanceof CtField) {
// field scope is not supported
return false;
}
CtElement[] real = var.map(new VariableScopeFunction()).list().toArray(new CtElement[0]);
if (var instanceof CtLocalVariable) {
assertArrayEquals(var.map(new LocalVariableScopeFunction()).list().toArray(new CtElement[0]), real);
} else if (var instanceof CtField) {
// assertArrayEquals(var.map(new FieldScopeFunction()).list().toArray(new CtElement[0]), real);
} else if (var instanceof CtParameter) {
assertArrayEquals(var.map(new ParameterScopeFunction()).list().toArray(new CtElement[0]), real);
} else if (var instanceof CtCatchVariable) {
assertArrayEquals(var.map(new CatchVariableScopeFunction()).list().toArray(new CtElement[0]), real);
} else {
fail("Unexpected variable of type " + var.getClass().getName());
}
return true;
}
return false;
}).list();
assertTrue(list.size() > 0);
}
Aggregations