Search in sources :

Example 1 with AddMethodModifier

use of abs.frontend.ast.AddMethodModifier 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 2 with AddMethodModifier

use of abs.frontend.ast.AddMethodModifier 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 3 with AddMethodModifier

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

the class TraitTest method collapseTest.

@Test
public void collapseTest() {
    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 Int i = 0;" + "    adds T modifies T2 removes {Unit printLine_2();}" + "    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));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 4 with AddMethodModifier

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

the class TraitTest method collapseTest3.

@Test
public void collapseTest3() {
    Model model = assertParseOk("module TestMod;" + "trait T = {" + "Unit printLine_0(){println(\"I'm 0!\");}" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "trait T2 = {" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "class InterImpl(Inter inter){ }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "adds Int i = 0;" + "adds T " + "modifies T2 " + "removes { Unit printLine_0(); }" + "                removes { Unit printLine_1(); }" + "adds {" + "Unit printLine_2(){println(\"I'm 2!\");}" + "Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "removes { Unit printLine_2(); }" + "removes { Unit printLine_3(); }" + "}");
    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() == 8);
    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));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with AddMethodModifier

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

the class DeltaForGetSetFieldsBuilder method addSetter.

/**
 * Add an add method modifier
 * @param fieldName
 * @param exp
 * @param decl
 * @return
 */
AddMethodModifier addSetter(String fieldName, Access type) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.setterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), getUnit(), new abs.frontend.ast.List<ParamDecl>());
    sig.addParam(new ParamDecl("v", type, new abs.frontend.ast.List<Annotation>()));
    Block block = new Block();
    block.addStmtNoTransform(getVAssign(new FieldUse(fieldName), new VarUse("v")));
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) VarUse(abs.frontend.ast.VarUse) Annotation(abs.frontend.ast.Annotation) AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) Block(abs.frontend.ast.Block)

Aggregations

AddMethodModifier (abs.frontend.ast.AddMethodModifier)8 DeltaDecl (abs.frontend.ast.DeltaDecl)6 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)6 ClassDecl (abs.frontend.ast.ClassDecl)5 Model (abs.frontend.ast.Model)5 Test (org.junit.Test)5 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)4 MethodImpl (abs.frontend.ast.MethodImpl)4 TraitExpr (abs.frontend.ast.TraitExpr)4 Block (abs.frontend.ast.Block)3 MethodSig (abs.frontend.ast.MethodSig)3 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)3 TraitSetExpr (abs.frontend.ast.TraitSetExpr)3 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)2 Annotation (abs.frontend.ast.Annotation)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 FieldUse (abs.frontend.ast.FieldUse)2 ParamDecl (abs.frontend.ast.ParamDecl)2 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1