Search in sources :

Example 21 with ClassDecl

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

the class TraitTest method removeNonExistingMethodInTrait.

@Test(expected = DeltaModellingException.class)
public void removeNonExistingMethodInTrait() {
    Model model = assertParse("module M;" + "trait T = {} removes Unit myMethod(); " + "class C {uses T;  }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 22 with ClassDecl

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

the class OriginalCallTest method oneDeltaMultipleCalls.

@Test
public void oneDeltaMultipleCalls() throws DeltaModellingException {
    Model model = assertParse("module M;" + "interface I {}" + "class C implements I { Unit m() {} Unit n() {} Unit p() {} }" + "delta D;uses M;" + "modifies class C {" + "modifies Unit m() { original(); }" + "modifies Unit n() { original(); }" + "modifies Unit p() { 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(6, cls.getMethods().getNumChild());
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta)));
// assertEquals(4, 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 23 with ClassDecl

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

the class OriginalCallTest method multipleTargetedOriginalCalls.

@Test
public void multipleTargetedOriginalCalls() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { }" + "delta D1;" + "uses M;" + "modifies class C { adds Unit m() {} }" + "delta D2;uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }" + "delta D3;uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    DeltaDecl d3 = findDelta(model, "D3");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1,d2,d3)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2, d3)));
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals(cls.getMethods().toString(), 2, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).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)

Example 24 with ClassDecl

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

the class TypeCheckerTest method classParamsRewrite.

@Test
public void classParamsRewrite() {
    Model m = assertParse("class C(Bool b) { Bool m() { return b; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(ClassDecl.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(FieldUse.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) FieldUse(org.abs_models.frontend.ast.FieldUse) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 25 with ClassDecl

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

the class TypeCheckerTest method classParamsRewrite2.

@Test
public void classParamsRewrite2() {
    Model m = assertParse("class C(Bool b) { Bool m(Bool x) { return x; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(MethodSig.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) VarUse(org.abs_models.frontend.ast.VarUse) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) 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