Search in sources :

Example 6 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class TraitTest method addAndModifyExistingMethod.

@Test
public void addAndModifyExistingMethod() {
    Model model = assertParseOk("module M; " + " trait T = {Unit myMethod(){ println(\"\"); }} modifies { Unit myMethod(){ skip; } }" + " class C {uses T; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 1);
    assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) SkipStmt(abs.frontend.ast.SkipStmt) Test(org.junit.Test)

Example 7 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class TraitTest method modifyTwiceExistingMethod.

@Test
public void modifyTwiceExistingMethod() {
    Model model = assertParseOk("module M; " + "trait T = {Unit myMethod(){ println(\"\"); } } modifies { Unit myMethod(){ println(\"test\"); } } modifies { Unit myMethod(){ skip; } }" + "class C {uses T; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 1);
    assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) SkipStmt(abs.frontend.ast.SkipStmt) Test(org.junit.Test)

Example 8 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class TraitTest method addAndRemoveExistingMethod.

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

Example 9 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class TraitTest method addSameMethodsTwice.

@Test
public void addSameMethodsTwice() {
    Model model = assertParseOk("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(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 10 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class TraitTest method removeExistingMethodSetInClassSucc.

@Test
public void removeExistingMethodSetInClassSucc() {
    Model model = assertParseOk("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(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Aggregations

ClassDecl (abs.frontend.ast.ClassDecl)75 Test (org.junit.Test)59 Model (abs.frontend.ast.Model)57 DeltaDecl (abs.frontend.ast.DeltaDecl)22 FrontendTest (abs.frontend.FrontendTest)12 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 InterfaceDecl (abs.frontend.ast.InterfaceDecl)7 MethodImpl (abs.frontend.ast.MethodImpl)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 MethodSig (abs.frontend.ast.MethodSig)6 ReturnStmt (abs.frontend.ast.ReturnStmt)6 AddMethodModifier (abs.frontend.ast.AddMethodModifier)5 Decl (abs.frontend.ast.Decl)5 DeltaAccess (abs.frontend.ast.DeltaAccess)5 List (abs.frontend.ast.List)5 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 CompilationUnit (abs.frontend.ast.CompilationUnit)4