Search in sources :

Example 26 with DeltaDecl

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

the class ParserTest method entry_deltadecl.

@Test
public void entry_deltadecl() throws Exception {
    CompilationUnit u = parseString("delta Mon;").getCompilationUnit(1);
    DeltaDecl d = (DeltaDecl) u.getDeltaDecl(0);
    Assert.assertNotNull(d);
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 27 with DeltaDecl

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

the class OriginalCallTest method targetedDeltaNotYetApplied.

@Test
public void targetedDeltaNotYetApplied() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { Unit m() {} }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }" + "delta D2;" + "uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    try {
        // applying deltas in wrong order (D2 then D1) should throw an exception
        // because D2 has a targeted original call to a method in D1
        // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d2,d1)));
        model.applyDeltas(new ArrayList<>(Arrays.asList(d2, d1)));
        fail("expected a DeltaModellingException");
    } catch (DeltaModellingException e) {
        assertThat(e.getMessage(), containsString("has not yet been applied"));
    }
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 28 with DeltaDecl

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

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

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

Aggregations

DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)36 Test (org.junit.Test)35 Model (org.abs_models.frontend.ast.Model)34 ClassDecl (org.abs_models.frontend.ast.ClassDecl)24 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 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)4 FrontendTest (org.abs_models.frontend.FrontendTest)3 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)3 Decl (org.abs_models.frontend.ast.Decl)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)3 List (org.abs_models.frontend.ast.List)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 ParametricDataTypeDecl (org.abs_models.frontend.ast.ParametricDataTypeDecl)3 TypeSynDecl (org.abs_models.frontend.ast.TypeSynDecl)3