use of abs.frontend.ast.DeltaDecl 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));
}
use of abs.frontend.ast.DeltaDecl 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));
}
use of abs.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method originalCall3.
@Test
public void originalCall3() throws DeltaModellingException {
Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Int one() { return 1; } }" + "delta D; uses M;" + "modifies class C { modifies Int one() { Int x = original(); return x + 1; } }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertEquals(1, cls.getMethods().getNumChild());
DeltaDecl delta1 = findDelta(model, "D");
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1)));
model.applyDeltas(new ArrayList<>(Arrays.asList(delta1)));
assertEquals(2, cls.getMethods().getNumChild());
assertTrue(cls.getMethod(0).getMethodSig().getName().equals("one"));
// make sure method has the right body
assertTrue(cls.getMethod(0).getBlock().getStmt(1) instanceof ReturnStmt);
assertTrue(cls.getMethod(1).getMethodSig().getName().equals("one$ORIGIN_core"));
// make sure method has the right body
assertTrue(cls.getMethod(1).getBlock().getStmt(0) instanceof ReturnStmt);
}
use of abs.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method oneDeltaMultipleCalls.
@Test
public void oneDeltaMultipleCalls() throws DeltaModellingException {
Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} Unit n() {} Unit p() {} }" + "delta D;uses M;" + "modifies class C {" + "modifies Unit m() { original(); }" + "modifies Unit n() { original(); }" + "modifies Unit p() { original(); }" + "}");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
DeltaDecl delta = findDelta(model, "D");
assertEquals(1, delta.getNumModuleModifier());
model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
assertEquals(6, cls.getMethods().getNumChild());
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta)));
// assertEquals(4, delta.getNumModuleModifier());
}
use of abs.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method originalCall.
@Test
public void originalCall() throws DeltaModellingException {
Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertTrue(cls.getMethods().getNumChild() == 1);
DeltaDecl delta1 = findDelta(model, "D");
assertTrue(delta1.getNumModuleModifier() == 1);
assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
DeltaDecl delta2 = findDelta(model, "D2");
assertTrue(delta2.getNumModuleModifier() == 1);
assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
/*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
assertTrue(delta1.getNumModuleModifier() == 2);
assertTrue(delta2.getNumModuleModifier() == 2);*/
model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
// there should be 3 methods now: the original one and those added by the two deltas
assertEquals(3, cls.getMethods().getNumChild());
assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Aggregations