Search in sources :

Example 6 with IntLiteral

use of org.abs_models.frontend.ast.IntLiteral in project abstools by abstools.

the class TreeUtilsTest method recurseForSome.

@Test
public void recurseForSome() {
    Model model = assertParse("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"));
    }
}
Also used : AddExp(org.abs_models.frontend.ast.AddExp) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FunctionDef(org.abs_models.frontend.ast.FunctionDef) IntLiteral(org.abs_models.frontend.ast.IntLiteral) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

IntLiteral (org.abs_models.frontend.ast.IntLiteral)6 PureExp (org.abs_models.frontend.ast.PureExp)5 Annotation (org.abs_models.frontend.ast.Annotation)3 FnApp (org.abs_models.frontend.ast.FnApp)3 TypedAnnotation (org.abs_models.frontend.ast.TypedAnnotation)3 FrontendTest (org.abs_models.frontend.FrontendTest)2 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)2 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)2 FunctionDef (org.abs_models.frontend.ast.FunctionDef)2 Model (org.abs_models.frontend.ast.Model)2 Test (org.junit.Test)2 AddExp (org.abs_models.frontend.ast.AddExp)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 List (org.abs_models.frontend.ast.List)1 ListLiteral (org.abs_models.frontend.ast.ListLiteral)1 StringLiteral (org.abs_models.frontend.ast.StringLiteral)1