Search in sources :

Example 61 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl 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 62 with ClassDecl

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

the class OriginalCallTest method multipleCallsToSameMethod.

@Test
public void multipleCallsToSameMethod() throws DeltaModellingException {
    Model model = assertParse("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D;" + "modifies class M.C {" + "modifies Unit m() { original(); original(); }" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    DeltaDecl delta = findDelta(model, "D");
    assertEquals(1, delta.getNumModuleModifier());
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
    assertEquals(2, cls.getMethods().getNumChild());
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta)));
// assertEquals(delta.getModuleModifiers().toString(),2, delta.getNumModuleModifier());
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 63 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl 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 64 with ClassDecl

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

the class TraitTest method frameTest.

@Test
public void frameTest() {
    Model model = assertParse("module M;" + " interface I { Unit x(); Unit foo(); Unit bar(); }" + " trait T = Unit x() { this.foo(); original(); this.bar();  }" + " trait T2 = { Unit x() { println(\"T2\"); } } modifies T" + " trait T3 = { Unit x() { println(\"T3\"); } } modifies T" + " class C implements I {" + "         Int i = 0;" + "         uses T2;" + "         Unit foo(){ i = i+1; }" + "         Unit bar(){ i = i-1; }" + " }" + " class C2 implements I {" + "         Int i = 0;" + "         uses T3;" + "         Unit foo(){ i = i-1; }" + "         Unit bar(){ i = i+1; }" + " }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 2);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 4);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 65 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl 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

ClassDecl (org.abs_models.frontend.ast.ClassDecl)79 Model (org.abs_models.frontend.ast.Model)72 Test (org.junit.Test)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)24 FrontendTest (org.abs_models.frontend.FrontendTest)15 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)12 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)10 KindedName (org.abs_models.frontend.typechecker.KindedName)10 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 MethodImpl (org.abs_models.frontend.ast.MethodImpl)6 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 MethodSig (org.abs_models.frontend.ast.MethodSig)5 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 HashSet (java.util.HashSet)4 List (org.abs_models.frontend.ast.List)4 ABSTest (org.abs_models.ABSTest)3