use of org.abs_models.frontend.ast.SkipStmt in project abstools by abstools.
the class TraitTest method addModifyModifierAtRuntimeBackComp.
@Test
public void addModifyModifierAtRuntimeBackComp() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())));
ModifyMethodModifier opr = new ModifyMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
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(1, cls.getMethods().getNumChild());
assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
use of org.abs_models.frontend.ast.SkipStmt in project abstools by abstools.
the class TraitTest method sameTraitNameDifferentModules.
@Test
public void sameTraitNameDifferentModules() {
Model model = assertParse("\n" + "module M;" + "export T2;" + "trait T = { Unit myMethod() { skip; } }" + "trait T2 = T removes Unit myMethod();" + "\n" + "module N;" + "import T2 from M;" + "trait T = T2 adds { Unit foo() { skip; } }" + "class C { uses T; }");
ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertEquals(1, cls.getNumMethod());
assertTrue(cls.getMethods().getChild(0).getBlock().getStmt(0) instanceof SkipStmt);
}
use of org.abs_models.frontend.ast.SkipStmt in project abstools by abstools.
the class TraitTest method modifyTwiceTwoTraitsExistingMethod.
@Test
public void modifyTwiceTwoTraitsExistingMethod() {
Model model = assertParse("module M; " + "trait T = {Unit myMethod(){ println(\"\"); }} modifies { Unit myMethod(){ println(\"test\"); } }" + "trait T2 = T removes Unit myMethod(); adds { Unit myMethod(){ skip; } }" + "class C {uses T2; }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 1);
assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
}
use of org.abs_models.frontend.ast.SkipStmt in project abstools by abstools.
the class TraitTest method removeInClass.
@Test
public void removeInClass() {
Model model = assertParse("module M;" + "trait T = { Unit x() { println(\"signature change\"); } Unit y() { skip; } }" + "class C { uses T adds { Unit x(Int i) { skip; } } removes Unit x();;}");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 2);
assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
assertTrue(cls.getMethod(1).getBlock().getStmt(0) instanceof SkipStmt);
}
use of org.abs_models.frontend.ast.SkipStmt in project abstools by abstools.
the class TraitTest method originalCallMethod.
@Test
public void originalCallMethod() {
Model model = assertParse("module M; " + " trait T = {} modifies { Unit myMethod(){ original(); skip;} }" + " class C {uses T; Unit myMethod(){ skip; }}");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 1);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 2);
assertFalse(cls.getMethod(1).getBlock().getStmt(0) instanceof SkipStmt);
assertTrue(cls.getMethod(1).getBlock().getStmt(1) instanceof SkipStmt);
assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
assertFalse(cls.getMethod(0).toString().equals(cls.getMethod(1).toString()));
}
Aggregations