Search in sources :

Example 11 with ModifyClassModifier

use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.

the class OriginalCallTest method originalCall2.

@Test
public void originalCall2() throws DeltaModellingException {
    Model model = assertParse("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getMethods().getNumChild() == 1);
    DeltaDecl delta1 = findDelta(model, "D");
    assertTrue(delta1.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
    DeltaDecl delta2 = findDelta(model, "D2");
    assertTrue(delta2.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
    /*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
        assertTrue(delta1.getNumModuleModifier() == 2);
        assertTrue(delta2.getNumModuleModifier() == 2);*/
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
    // there should be 3 methods now: the original one and those added by the two deltas
    assertEquals(3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 12 with ModifyClassModifier

use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.

the class OriginalCallTest method originalCall.

@Test
public void originalCall() throws DeltaModellingException {
    Model model = assertParse("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getMethods().getNumChild() == 1);
    DeltaDecl delta1 = findDelta(model, "D");
    assertTrue(delta1.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
    DeltaDecl delta2 = findDelta(model, "D2");
    assertTrue(delta2.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
    /*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
        assertTrue(delta1.getNumModuleModifier() == 2);
        assertTrue(delta2.getNumModuleModifier() == 2);*/
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
    // there should be 3 methods now: the original one and those added by the two deltas
    assertEquals(3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 13 with ModifyClassModifier

use of org.abs_models.frontend.ast.ModifyClassModifier in project abstools by abstools.

the class TraitTest method addRemoveModifierAtRuntime.

@Test
public void addRemoveModifierAtRuntime() {
    Model model = assertParse("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.setImportedModule(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(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) RemoveMethodModifier(org.abs_models.frontend.ast.RemoveMethodModifier) ClassDecl(org.abs_models.frontend.ast.ClassDecl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) Model(org.abs_models.frontend.ast.Model) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)13 Model (org.abs_models.frontend.ast.Model)13 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 ClassDecl (org.abs_models.frontend.ast.ClassDecl)12 Test (org.junit.Test)12 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)8 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 List (org.abs_models.frontend.ast.List)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 Block (org.abs_models.frontend.ast.Block)2 MethodImpl (org.abs_models.frontend.ast.MethodImpl)2 SkipStmt (org.abs_models.frontend.ast.SkipStmt)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1