use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method resolveTest.
@Test
public void resolveTest() {
Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T = { " + " Unit printLine_1(){println(\"I'm 1!\");}" + " Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + " Unit printLine_2(){println(\"I'm 2!\");}" + " Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter { }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + " adds Int i = 0;" + " adds T modifies T2" + "}");
ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
DeltaDecl delta = findDelta(model, "D3");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
TraitExpr expr = mcl.getTraitExpr();
TraitExpr set = expr.resolve(cls.getModuleDecl());
assertTrue(set.getChild(0).getNumChild() == 3);
}
use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method sameTraitNameDifferentModules.
@Test
public void sameTraitNameDifferentModules() {
Model model = assertParseOk("\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 abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method addMethod.
@Test
public void addMethod() {
Model model = assertParseOk("module M;" + "trait T = { 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).getMethodSig().getName().equals("myMethod"));
}
use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method resolveTest2.
@Test
public void resolveTest2() {
// this tests that the given delta is wrong (as we take T union T2 and thus have printLine_2 twice)
Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T = { " + " Unit printLine_1(){println(\"I'm 1!\");}" + " Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + " Unit printLine_2(){println(\"I'm 2!\");}" + " Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter { }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + " adds Int i = 0;" + " modifies T adds T2" + "}");
ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
DeltaDecl delta = findDelta(model, "D3");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
ModifyMethodModifier mcl = (ModifyMethodModifier) dml.getMethodModifier();
TraitExpr expr = mcl.getTraitExpr();
TraitExpr set = expr.resolve(cls.getModuleDecl());
assertTrue(set.getChild(0).getNumChild() == 4);
}
use of abs.frontend.ast.Model in project abstools by abstools.
the class TraitTest method circularTraitsMultiMod.
@Test
public void circularTraitsMultiMod() {
Model model = assertParseOk("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);
}
Aggregations