Search in sources :

Example 21 with Model

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

the class TraitTest method addTwoMethods.

@Test
public void addTwoMethods() {
    Model model = assertParseOk("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()));
    assertTrue(model.getErrors().containsErrors());
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 22 with Model

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

the class TraitTest method circularTraits1.

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

Example 23 with Model

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

the class TraitTest method modifyNonExistingMethods.

@Test
public void modifyNonExistingMethods() {
    Model model = assertParseOk("module M;" + "trait T = {} 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).getMethodSig().getName().equals("myMethod"));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 24 with Model

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

the class TraitTest method collapseTest.

@Test
public void collapseTest() {
    Model model = assertParseOk("module TestMod;" + "interface Inter {}" + "trait T = { " + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + "  Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T3 = { " + "  Unit printLine_5(){println(\"I'm 5!\");}" + "  Unit printLine_6(){println(\"I'm 6!\");}" + "}" + "trait T4 = { " + "  Unit printLine_7(){println(\"I'm 7!\");}" + "  Unit printLine_8(){println(\"I'm 8!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    adds T modifies T2 removes {Unit printLine_2();}" + "    modifies T3 adds T4 " + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    model.collapseTraitModifiers();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    assertTrue(mm.getModifierList().getNumChild() == 6);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr set = mcl.getTraitExpr();
    assertTrue(set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
    DeltaTraitModifier dml2 = (DeltaTraitModifier) mm.getModifier(2);
    ModifyMethodModifier mcl2 = (ModifyMethodModifier) dml2.getMethodModifier();
    TraitExpr set2 = mcl2.getTraitExpr();
    assertTrue(set2.getChild(0).getNumChild() == 1);
    assertThat(set2, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 25 with Model

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

the class TraitTest method collapseTest3.

@Test
public void collapseTest3() {
    Model model = assertParseOk("module TestMod;" + "trait T = {" + "Unit printLine_0(){println(\"I'm 0!\");}" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "trait T2 = {" + "Unit printLine_1(){println(\"I'm 1!\");}" + "}" + "class InterImpl(Inter inter){ }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "adds Int i = 0;" + "adds T " + "modifies T2 " + "removes { Unit printLine_0(); }" + "                removes { Unit printLine_1(); }" + "adds {" + "Unit printLine_2(){println(\"I'm 2!\");}" + "Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "removes { Unit printLine_2(); }" + "removes { Unit printLine_3(); }" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    model.collapseTraitModifiers();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    assertTrue(mm.getModifierList().getNumChild() == 8);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr set = mcl.getTraitExpr();
    assertTrue(set.getChild(0).getNumChild() == 2);
    assertThat(set, instanceOf(TraitSetExpr.class));
    DeltaTraitModifier dml2 = (DeltaTraitModifier) mm.getModifier(2);
    ModifyMethodModifier mcl2 = (ModifyMethodModifier) dml2.getMethodModifier();
    TraitExpr set2 = mcl2.getTraitExpr();
    assertTrue(set2.getChild(0).getNumChild() == 1);
    assertThat(set2, instanceOf(TraitSetExpr.class));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TraitExpr(abs.frontend.ast.TraitExpr) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) TraitSetExpr(abs.frontend.ast.TraitSetExpr) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaTraitModifier(abs.frontend.ast.DeltaTraitModifier) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

Model (abs.frontend.ast.Model)226 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6