use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.
the class OriginalCallTest method originalCall2.
@Test
public void originalCall2() throws DeltaModellingException {
Model model = assertParse("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"));
}
use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.
the class OriginalCallTest method originalCall.
@Test
public void originalCall() throws DeltaModellingException {
Model model = assertParse("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"));
}
use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.
the class TraitTest method addRemoveModifierAtRuntime.
@Test
public void addRemoveModifierAtRuntime() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
List<MethodSig> l = new List<>(sig);
RemoveMethodModifier opr = new RemoveMethodModifier(l);
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.setImportedModule(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(0, cls.getMethods().getNumChild());
}
Aggregations