Search in sources :

Example 16 with ClassDecl

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

the class TraitTest method addTwoMethods.

@Test
public void addTwoMethods() {
    Model model = assertParse("module M;" + "trait T = { Unit myMethod(){ skip; } }" + "trait T2 = { Unit myMethod(){ skip; } }" + "class C {uses T; uses T2; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 2);
    assertTrue(cls.getMethod(0).toString().equals(cls.getMethod(1).toString()));
// failing for unknown reasons; comment out since traits might be removed anyway
// assertTrue(model.getErrors().containsErrors());
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 17 with ClassDecl

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

the class TraitTest method removeExistingMethodSetInClassSucc.

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

Example 18 with ClassDecl

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

the class TraitTest method removeExistingMethodInTrait.

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

Example 19 with ClassDecl

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

the class TraitTest method removeSetFromDelta.

@Test
public void removeSetFromDelta() {
    Model model = assertParse("module TestMod;" + "interface Inter {}" + "trait T2 = { " + "  Unit driver(){" + "    println(\"hallo\");" + "    this.greeting();" + "    this.printLine_1();" + "    this.printLine_2();" + "    this.sendoff();" + "  }" + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "  Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {  uses T2;  }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    removes { " + "      Unit printLine_1(); Unit printLine_2(); Unit printLine_3(); }" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 4);
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    model.applyDelta(delta);
    assertTrue(cls.getMethods().getNumChild() == 1);
}
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 20 with ClassDecl

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

the class TraitTest method addSameMethodsTwice.

@Test
public void addSameMethodsTwice() {
    Model model = assertParse("module TestMod;" + "interface Inter {}" + "trait T2 = { " + "  Unit driver(){" + "    println(\"hallo\");" + "    this.greeting();" + "    this.printLine_1();" + "    this.printLine_2();" + "    this.sendoff();" + "  }" + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "  Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {  uses T2 removes Unit printLine_3();; }" + "class InterImpl2(Inter inter) implements Inter { uses T2 removes Unit printLine_3();; }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    adds { " + "      Unit greeting(){println(\"hello\"); i = i + 1;} " + "      Unit sendoff(){println(\"goodbye\"); i = i - 1;}}}" + "modifies class TestMod.InterImpl2{" + "      adds Int i = 0;" + "      adds { " + "      Unit greeting(){println(\"hello\"); i = i + 1;} " + "      Unit sendoff(){println(\"goodbye\"); i = i - 1;}}}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    ClassDecl cls2 = (ClassDecl) findDecl(model, "TestMod", "InterImpl2");
    assertNotNull(cls2);
    assertTrue(cls2.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 3);
    assertTrue(cls2.getMethods().getNumChild() == 3);
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    model.applyDelta(delta);
    assertTrue(cls.getMethods().getNumChild() == 5);
    assertTrue(cls2.getMethods().getNumChild() == 5);
}
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

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