use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method frameTest.
@Test
public void frameTest() {
Model model = assertParseOk("module M;" + " interface I { Unit x(); Unit foo(); Unit bar(); }" + " trait T = Unit x() { this.foo(); original(); this.bar(); }" + " trait T2 = { Unit x() { println(\"T2\"); } } modifies T" + " trait T3 = { Unit x() { println(\"T3\"); } } modifies T" + " class C implements I {" + " Int i = 0;" + " uses T2;" + " Unit foo(){ i = i+1; }" + " Unit bar(){ i = i-1; }" + " }" + " class C2 implements I {" + " Int i = 0;" + " uses T3;" + " Unit foo(){ i = i-1; }" + " Unit bar(){ i = i+1; }" + " }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 2);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 4);
}
use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method removeExistingMethodInTrait.
@Test(expected = DeltaModellingException.class)
public void removeExistingMethodInTrait() {
Model model = assertParseOk("module M; " + " trait T = {} removes Unit myMethod();" + " class C {uses T; Unit myMethod(){ println(\"\"); } }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 1);
model.applyTraits();
}
use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method addAndModifyExistingMethod.
@Test
public void addAndModifyExistingMethod() {
Model model = assertParseOk("module M; " + " trait T = {Unit myMethod(){ println(\"\"); }} modifies { Unit myMethod(){ skip; } }" + " class C {uses T; }");
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 abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method modifyTwiceExistingMethod.
@Test
public void modifyTwiceExistingMethod() {
Model model = assertParseOk("module M; " + "trait T = {Unit myMethod(){ println(\"\"); } } modifies { Unit myMethod(){ println(\"test\"); } } modifies { Unit myMethod(){ skip; } }" + "class C {uses T; }");
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 abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method addAndRemoveExistingMethod.
@Test
public void addAndRemoveExistingMethod() {
Model model = assertParseOk("module M; " + " trait T = Unit myMethod(){ skip; } removes Unit myMethod();" + " class C {uses T; }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 0);
}
Aggregations