Search in sources :

Example 1 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class TraitTest method addSameMethodsTwice.

@Test
public void addSameMethodsTwice() {
    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 removes Unit printLine_3();; }" + "class InterImpl2(Inter inter) implements Inter { uses T2 removes Unit printLine_3();; }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    adds { " + "      Unit greeting(){println(\"hello\"); i = i + 1;} " + "      Unit sendoff(){println(\"goodbye\"); i = i - 1;}}}" + "modifies class TestMod.InterImpl2{" + "      adds Int i = 0;" + "      adds { " + "      Unit greeting(){println(\"hello\"); i = i + 1;} " + "      Unit sendoff(){println(\"goodbye\"); i = i - 1;}}}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    ClassDecl cls2 = (ClassDecl) findDecl(model, "TestMod", "InterImpl2");
    assertNotNull(cls2);
    assertTrue(cls2.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 3);
    assertTrue(cls2.getMethods().getNumChild() == 3);
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    model.applyDelta(delta);
    assertTrue(cls.getMethods().getNumChild() == 5);
    assertTrue(cls2.getMethods().getNumChild() == 5);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 2 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class TraitTest method addRemoveModifierAtRuntime.

@Test
public void addRemoveModifierAtRuntime() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
    List<MethodSig> l = new List<>(sig);
    RemoveMethodModifier opr = new RemoveMethodModifier(l);
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(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(0, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) RemoveMethodModifier(abs.frontend.ast.RemoveMethodModifier) ClassDecl(abs.frontend.ast.ClassDecl) DeltaAccess(abs.frontend.ast.DeltaAccess) Model(abs.frontend.ast.Model) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 3 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())), false);
    AddMethodModifier opr = new AddMethodModifier(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.addDeltaAccess(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(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) Block(abs.frontend.ast.Block) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) SkipStmt(abs.frontend.ast.SkipStmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 4 with DeltaDecl

use of abs.frontend.ast.DeltaDecl 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);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with DeltaDecl

use of abs.frontend.ast.DeltaDecl 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);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) TraitExpr(abs.frontend.ast.TraitExpr) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

DeltaDecl (abs.frontend.ast.DeltaDecl)37 Test (org.junit.Test)32 Model (abs.frontend.ast.Model)30 ClassDecl (abs.frontend.ast.ClassDecl)22 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)15 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)8 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 AddMethodModifier (abs.frontend.ast.AddMethodModifier)6 DeltaAccess (abs.frontend.ast.DeltaAccess)6 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 Block (abs.frontend.ast.Block)4 CompilationUnit (abs.frontend.ast.CompilationUnit)4 MethodImpl (abs.frontend.ast.MethodImpl)4 MethodSig (abs.frontend.ast.MethodSig)4 FrontendTest (abs.frontend.FrontendTest)3 DataTypeDecl (abs.frontend.ast.DataTypeDecl)3 Decl (abs.frontend.ast.Decl)3 FunctionDecl (abs.frontend.ast.FunctionDecl)3 List (abs.frontend.ast.List)3