Search in sources :

Example 51 with ClassDecl

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

the class TraitTest method sameTraitNameDifferentModules.

@Test
public void sameTraitNameDifferentModules() {
    Model model = assertParse("\n" + "module M;" + "export T2;" + "trait T = { Unit myMethod() { skip; } }" + "trait T2 = T removes Unit myMethod();" + "\n" + "module N;" + "import T2 from M;" + "trait T = T2 adds { Unit foo() { skip; } }" + "class C { uses T; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertEquals(1, cls.getNumMethod());
    assertTrue(cls.getMethods().getChild(0).getBlock().getStmt(0) instanceof SkipStmt);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) SkipStmt(org.abs_models.frontend.ast.SkipStmt) Test(org.junit.Test)

Example 52 with ClassDecl

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

the class TraitTest method modifyTwiceTwoTraitsExistingMethod.

@Test
public void modifyTwiceTwoTraitsExistingMethod() {
    Model model = assertParse("module M; " + "trait T = {Unit myMethod(){ println(\"\"); }} modifies { Unit myMethod(){ println(\"test\"); } }" + "trait T2 = T removes Unit myMethod(); adds { Unit myMethod(){ skip; } }" + "class C {uses T2;  }");
    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(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) SkipStmt(org.abs_models.frontend.ast.SkipStmt) Test(org.junit.Test)

Example 53 with ClassDecl

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

the class TraitTest method circularTraitsMultiMod.

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

Example 54 with ClassDecl

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

the class TraitTest method addMethodWithImportedTrait.

@Test
public void addMethodWithImportedTrait() {
    Model model = assertParse("module M;" + "export T;" + "trait T = { Unit myMethod(){ skip; } }" + "class C { uses T; }" + "\n" + "module N;" + "export T;" + "import T from M;" + "class C { uses T; }" + "\n" + "module O;" + "import T from N;" + "class C { uses T; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
    ClassDecl cls2 = (ClassDecl) findDecl(model, "O", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    assertNotNull(cls2);
    assertTrue(cls2.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 1);
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("myMethod"));
    assertTrue(cls2.getMethods().getNumChild() == 1);
    assertTrue(cls2.getMethod(0).getMethodSig().getName().equals("myMethod"));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 55 with ClassDecl

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

the class TraitTest method removeInClass.

@Test
public void removeInClass() {
    Model model = assertParse("module M;" + "trait T = { Unit x() { println(\"signature change\"); } Unit y() { skip; } }" + "class C  { uses T adds { Unit x(Int i) { skip; } } removes Unit x();;}");
    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).getBlock().getStmt(0) instanceof SkipStmt);
    assertTrue(cls.getMethod(1).getBlock().getStmt(0) instanceof SkipStmt);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) SkipStmt(org.abs_models.frontend.ast.SkipStmt) 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