use of org.abs_models.frontend.ast.ClassDecl 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.ClassDecl 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.ClassDecl in project abstools by abstools.
the class TraitTest method circularTraitsMultiMod.
@Test
public void circularTraitsMultiMod() {
Model model = assertParse("module M;" + "trait T = {Unit myMethod(){ skip; }} " + "trait T2 = T modifies T modifies T modifies T modifies T modifies T modifies T \n" + "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);
}
use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method addMethodWithImportedTrait.
@Test
public void addMethodWithImportedTrait() {
Model model = assertParse("module M;" + "export T;" + "trait T = { Unit myMethod(){ skip; } }" + "class C { uses T; }" + "\n" + "module N;" + "export T;" + "import T from M;" + "class C { uses T; }" + "\n" + "module O;" + "import T from N;" + "class C { uses T; }");
ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
ClassDecl cls2 = (ClassDecl) findDecl(model, "O", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
assertNotNull(cls2);
assertTrue(cls2.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 1);
assertTrue(cls.getMethod(0).getMethodSig().getName().equals("myMethod"));
assertTrue(cls2.getMethods().getNumChild() == 1);
assertTrue(cls2.getMethod(0).getMethodSig().getName().equals("myMethod"));
}
use of org.abs_models.frontend.ast.ClassDecl 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);
}
Aggregations