Search in sources :

Example 6 with TraitExpr

use of abs.frontend.ast.TraitExpr in project abstools by abstools.

the class TraitTest method resolveTest3.

@Test
public void resolveTest3() {
    Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T = { " + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + "  Unit printLine_2(){println(\"I'm 2!\");}" + "  Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    modifies T removes {Unit printLine_2();}" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    ModifyMethodModifier mcl = (ModifyMethodModifier) dml.getMethodModifier();
    TraitExpr expr = mcl.getTraitExpr();
    TraitExpr set = expr.resolve(cls.getModuleDecl());
    assertTrue(set.getChild(0).getNumChild() == 1);
    assertThat(set, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) TraitExpr(abs.frontend.ast.TraitExpr) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 7 with TraitExpr

use of abs.frontend.ast.TraitExpr in project abstools by abstools.

the class TraitTest method resolveTest4.

@Test
public void resolveTest4() {
    Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T = { " + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + "  Unit printLine_2(){println(\"I'm 2!\");}" + "  Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    modifies T adds T2 removes {Unit printLine_2();}" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    ModifyMethodModifier mcl = (ModifyMethodModifier) dml.getMethodModifier();
    TraitExpr expr = mcl.getTraitExpr();
    TraitExpr set = expr.resolve(cls.getModuleDecl());
    assertTrue(set.getChild(0).getNumChild() == 3);
    assertThat(set, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) TraitExpr(abs.frontend.ast.TraitExpr) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

ClassDecl (abs.frontend.ast.ClassDecl)7 DeltaDecl (abs.frontend.ast.DeltaDecl)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 Model (abs.frontend.ast.Model)7 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 Test (org.junit.Test)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)6 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 AddMethodModifier (abs.frontend.ast.AddMethodModifier)4