Search in sources :

Example 1 with TraitExpr

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

the class TraitTest method resolveTest.

@Test
public void resolveTest() {
    Model model = assertParse("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;" + "    adds T modifies T2" + "}");
    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);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr expr = mcl.getTraitExpr();
    TraitExpr set = expr.resolve(cls.getModuleDecl());
    assertTrue("expected 2, got " + set.getChild(0).getNumChild(), set.getChild(0).getNumChild() == 2);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TraitExpr(org.abs_models.frontend.ast.TraitExpr) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 2 with TraitExpr

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

the class TraitTest method collapseTest2.

@Test
public void collapseTest2() {
    Model model = assertParse("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!\");}" + "}" + "trait T3 = { " + "  Unit printLine_5(){println(\"I'm 5!\");}" + "  Unit printLine_6(){println(\"I'm 6!\");}" + "}" + "trait T4 = { " + "  Unit printLine_7(){println(\"I'm 7!\");}" + "  Unit printLine_8(){println(\"I'm 8!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds T modifies T2 removes Unit printLine_2();" + "    adds Int i = 0;" + "    modifies T3 adds T4 " + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    model.collapseTraitModifiers();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    assertTrue(mm.getModifierList().getNumChild() == 6);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(0);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr set = mcl.getTraitExpr();
    assertTrue(set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
    DeltaTraitModifier dml2 = (DeltaTraitModifier) mm.getModifier(1);
    ModifyMethodModifier mcl2 = (ModifyMethodModifier) dml2.getMethodModifier();
    TraitExpr set2 = mcl2.getTraitExpr();
    assertTrue(set2.getChild(0).getNumChild() == 1);
    assertThat(set2, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TraitExpr(org.abs_models.frontend.ast.TraitExpr) ModifyMethodModifier(org.abs_models.frontend.ast.ModifyMethodModifier) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) TraitSetExpr(org.abs_models.frontend.ast.TraitSetExpr) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 3 with TraitExpr

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

the class TraitTest method resolveTest3.

@Test
public void resolveTest3() {
    Model model = assertParse("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("expected 2, got " + set.getChild(0).getNumChild(), set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) ModifyMethodModifier(org.abs_models.frontend.ast.ModifyMethodModifier) TraitExpr(org.abs_models.frontend.ast.TraitExpr) Model(org.abs_models.frontend.ast.Model) TraitSetExpr(org.abs_models.frontend.ast.TraitSetExpr) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 4 with TraitExpr

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

the class TraitTest method collapseTest.

@Test
public void collapseTest() {
    Model model = assertParse("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!\");}" + "}" + "trait T3 = { " + "  Unit printLine_5(){println(\"I'm 5!\");}" + "  Unit printLine_6(){println(\"I'm 6!\");}" + "}" + "trait T4 = { " + "  Unit printLine_7(){println(\"I'm 7!\");}" + "  Unit printLine_8(){println(\"I'm 8!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    adds T modifies T2 removes {Unit printLine_2();}" + "    modifies T3 adds T4 " + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    model.collapseTraitModifiers();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    assertTrue(mm.getModifierList().getNumChild() == 6);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr set = mcl.getTraitExpr();
    assertTrue(set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
    DeltaTraitModifier dml2 = (DeltaTraitModifier) mm.getModifier(2);
    ModifyMethodModifier mcl2 = (ModifyMethodModifier) dml2.getMethodModifier();
    TraitExpr set2 = mcl2.getTraitExpr();
    assertTrue(set2.getChild(0).getNumChild() == 1);
    assertThat(set2, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TraitExpr(org.abs_models.frontend.ast.TraitExpr) ModifyMethodModifier(org.abs_models.frontend.ast.ModifyMethodModifier) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) TraitSetExpr(org.abs_models.frontend.ast.TraitSetExpr) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with TraitExpr

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

the class TraitTest method resolveTest4.

@Test
public void resolveTest4() {
    Model model = assertParse("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("expected 2, got " + set.getChild(0).getNumChild(), set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) ModifyMethodModifier(org.abs_models.frontend.ast.ModifyMethodModifier) TraitExpr(org.abs_models.frontend.ast.TraitExpr) Model(org.abs_models.frontend.ast.Model) TraitSetExpr(org.abs_models.frontend.ast.TraitSetExpr) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

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