use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method multipleNameResolveSteps.
@Test
public void multipleNameResolveSteps() {
Model model = assertParseOk("\n" + "module M;" + "export T;" + "trait T = { Unit myMethod(){ skip; } }" + "\n" + "module N;" + "export U;" + "import T from M;" + "trait U = T modifies {}" + "class C { uses U; }" + "\n" + "module O;" + "import U from N;" + "class D { uses U; }");
ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
ClassDecl cls2 = (ClassDecl) findDecl(model, "O", "D");
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 abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method originalCallMethod.
@Test
public void originalCallMethod() {
Model model = assertParseOk("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()));
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method removeSetFromDelta.
@Test
public void removeSetFromDelta() {
Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T2 = { " + " Unit driver(){" + " println(\"hallo\");" + " this.greeting();" + " this.printLine_1();" + " this.printLine_2();" + " this.sendoff();" + " }" + " Unit printLine_1(){println(\"I'm 1!\");}" + " Unit printLine_2(){println(\"I'm 2!\");}" + " Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter { uses T2; }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + " adds Int i = 0;" + " removes { " + " Unit printLine_1(); Unit printLine_2(); Unit printLine_3(); }" + "}");
ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 4);
DeltaDecl delta = findDelta(model, "D3");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
model.applyDelta(delta);
assertTrue(cls.getMethods().getNumChild() == 1);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method collapseTest2.
@Test
public void collapseTest2() {
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!\");}" + "}" + "trait T3 = { " + " Unit printLine_5(){println(\"I'm 5!\");}" + " Unit printLine_6(){println(\"I'm 6!\");}" + "}" + "trait T4 = { " + " Unit printLine_7(){println(\"I'm 7!\");}" + " Unit printLine_8(){println(\"I'm 8!\");}" + "}" + "class InterImpl(Inter inter) implements Inter { }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + " adds T modifies T2 removes Unit printLine_2();" + " adds Int i = 0;" + " modifies T3 adds T4 " + "}");
ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
model.collapseTraitModifiers();
DeltaDecl delta = findDelta(model, "D3");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
assertTrue(mm.getModifierList().getNumChild() == 6);
DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
TraitExpr set = mcl.getTraitExpr();
assertTrue(set.getChild(0).getNumChild() == 2);
assertThat(set, instanceOf(TraitSetExpr.class));
DeltaTraitModifier dml2 = (DeltaTraitModifier) mm.getModifier(2);
ModifyMethodModifier mcl2 = (ModifyMethodModifier) dml2.getMethodModifier();
TraitExpr set2 = mcl2.getTraitExpr();
assertTrue(set2.getChild(0).getNumChild() == 1);
assertThat(set2, instanceOf(TraitSetExpr.class));
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method resolveTest3.
@Test
public void resolveTest3() {
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 removes {Unit printLine_2();}" + "}");
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() == 1);
assertThat(set, instanceOf(TraitSetExpr.class));
}
Aggregations