use of abs.frontend.ast.FunctionDef in project abstools by abstools.
the class TreeUtilsTest method findChildrenMultipleTypes.
@Test
public void findChildrenMultipleTypes() {
Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
FunctionDef def = functionDecl.getFunctionDef();
Stream<PureExp> children = def.findChildren(cast(ImmutableList.of(FnApp.class, IntLiteral.class)), n -> true);
assertNotNull(children);
List<PureExp> result = children.distinct().collect(Collectors.toList());
assertEquals(2, result.size());
for (PureExp exp : result) {
assertTrue(exp instanceof FnApp || exp instanceof IntLiteral);
}
}
use of abs.frontend.ast.FunctionDef in project abstools by abstools.
the class TreeUtilsTest method recurseForSome.
@Test
public void recurseForSome() {
Model model = assertParseOkStdLib("def Int test(Int i) = 1 + test(2);");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
FunctionDef def = functionDecl.getFunctionDef();
Stream<PureExp> children = def.findChildren(cast(PureExp.class), AddExp.class::isInstance);
assertNotNull(children);
List<PureExp> result = children.distinct().collect(Collectors.toList());
// expecting AddExp, IntLiteral(1), FnApp, NOT IntLiteral(2)
assertEquals(3, result.size());
for (PureExp exp : result) {
assertFalse(exp instanceof IntLiteral && ((IntLiteral) exp).getContent().equals("2"));
}
}
use of abs.frontend.ast.FunctionDef in project abstools by abstools.
the class TreeUtilsTest method closestParentIgnoresSelf.
@Test
public void closestParentIgnoresSelf() {
Model model = assertParseOkStdLib("def Int test() = 1;");
FunctionDecl functionDecl = getLastFunctionDecl(model);
assertEquals("test", functionDecl.getName());
FunctionDef functionDef = functionDecl.getFunctionDef();
assertSame(functionDecl, functionDef.closestParent(ASTNode.class));
}
Aggregations