Search in sources :

Example 31 with DeltaDecl

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

the class OriginalCallTest method originalNotFound.

@Test(expected = DeltaModellingException.class)
public void originalNotFound() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { }" + "delta D1;" + "modifies class C { modifies Unit m() { original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(d1)));
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 32 with DeltaDecl

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

Example 33 with DeltaDecl

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

the class DeltaSyntax method delta.

@Test
public void delta() throws DeltaModellingException {
    Model model = assertParse("module M; delta D;");
    DeltaDecl delta = findDelta(model, "D");
    assertNotNull(delta);
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 34 with DeltaDecl

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

the class OriginalCallTest method originalCall3.

@Test
public void originalCall3() throws DeltaModellingException {
    Model model = assertParse("module M;" + "interface I {}" + "class C implements I { Int one() { return 1; } }" + "delta D; uses M;" + "modifies class C { modifies Int one() { Int x = original(); return x + 1; } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals(1, cls.getMethods().getNumChild());
    DeltaDecl delta1 = findDelta(model, "D");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1)));
    assertEquals(2, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("one"));
    // make sure method has the right body
    assertTrue(cls.getMethod(0).getBlock().getStmt(1) instanceof ReturnStmt);
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("one$ORIGIN_core"));
    // make sure method has the right body
    assertTrue(cls.getMethod(1).getBlock().getStmt(0) instanceof ReturnStmt);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) Test(org.junit.Test)

Example 35 with DeltaDecl

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

the class OriginalCallTest method targetedOriginalCall.

@Test
public void targetedOriginalCall() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { Unit m() {} }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }" + "adds class C2 { }" + "delta D2;" + "modifies class M.C { modifies Unit m() { D1.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1,d2)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2)));
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals(cls.getMethods().toString(), 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_D1"));
}
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)

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