Search in sources :

Example 1 with ModifyMethodModifier

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

the class TraitTest method resolveTest2.

@Test
public void resolveTest2() {
    // this tests that the given delta is wrong (as we take T union T2 and thus have printLine_2 twice)
    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" + "}");
    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() == 4);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) TraitExpr(abs.frontend.ast.TraitExpr) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 2 with ModifyMethodModifier

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

the class TraitTest method collapseTest.

@Test
public void collapseTest() {
    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!\");}" + "}" + "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(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) 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 3 with ModifyMethodModifier

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

the class TraitTest method collapseTest3.

@Test
public void collapseTest3() {
    Model model = assertParseOk("module TestMod;" + "trait T = {" + "Unit printLine_0(){println(\"I'm 0!\");}" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "trait T2 = {" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "class InterImpl(Inter inter){ }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "adds Int i = 0;" + "adds T " + "modifies T2 " + "removes { Unit printLine_0(); }" + "                removes { Unit printLine_1(); }" + "adds {" + "Unit printLine_2(){println(\"I'm 2!\");}" + "Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "removes { Unit printLine_2(); }" + "removes { Unit printLine_3(); }" + "}");
    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() == 8);
    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(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) 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 4 with ModifyMethodModifier

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

the class TraitTest method collapseTest2.

@Test
public void collapseTest2() {
    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!\");}" + "}" + "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(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(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) 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 5 with ModifyMethodModifier

use of abs.frontend.ast.ModifyMethodModifier 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)

Aggregations

DeltaDecl (abs.frontend.ast.DeltaDecl)8 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)8 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)8 ClassDecl (abs.frontend.ast.ClassDecl)7 Model (abs.frontend.ast.Model)7 Test (org.junit.Test)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)6 TraitExpr (abs.frontend.ast.TraitExpr)6 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 AddMethodModifier (abs.frontend.ast.AddMethodModifier)3 Block (abs.frontend.ast.Block)2 MethodImpl (abs.frontend.ast.MethodImpl)2 MethodSig (abs.frontend.ast.MethodSig)2 ModifyClassModifierNamePredicate (abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1 List (abs.frontend.ast.List)1 SkipStmt (abs.frontend.ast.SkipStmt)1