use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method originalNotFound.
@Test(expected = DeltaModellingException.class)
public void originalNotFound() throws DeltaModellingException {
Model model = assertParse("module M;" + "class C { }" + "delta D1;" + "modifies class C { modifies Unit m() { original(); } }");
DeltaDecl d1 = findDelta(model, "D1");
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1)));
model.applyDeltas(new ArrayList<>(Arrays.asList(d1)));
}
use of org.abs_models.frontend.ast.DeltaDecl 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());
}
use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.
the class DeltaSyntax method delta.
@Test
public void delta() throws DeltaModellingException {
Model model = assertParse("module M; delta D;");
DeltaDecl delta = findDelta(model, "D");
assertNotNull(delta);
}
use of org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method originalCall3.
@Test
public void originalCall3() throws DeltaModellingException {
Model model = assertParse("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 org.abs_models.frontend.ast.DeltaDecl in project abstools by abstools.
the class OriginalCallTest method targetedOriginalCall.
@Test
public void targetedOriginalCall() throws DeltaModellingException {
Model model = assertParse("module M;" + "class C { Unit m() {} }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }" + "adds class C2 { }" + "delta D2;" + "modifies class M.C { modifies Unit m() { D1.original(); } }");
DeltaDecl d1 = findDelta(model, "D1");
DeltaDecl d2 = findDelta(model, "D2");
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1,d2)));
model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2)));
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertEquals(cls.getMethods().toString(), 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_D1"));
}
Aggregations