Search in sources :

Example 6 with Model

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

the class TraitTest method frameTest.

@Test
public void frameTest() {
    Model model = assertParseOk("module M;" + " interface I { Unit x(); Unit foo(); Unit bar(); }" + " trait T = Unit x() { this.foo(); original(); this.bar();  }" + " trait T2 = { Unit x() { println(\"T2\"); } } modifies T" + " trait T3 = { Unit x() { println(\"T3\"); } } modifies T" + " class C implements I {" + "         Int i = 0;" + "         uses T2;" + "         Unit foo(){ i = i+1; }" + "         Unit bar(){ i = i-1; }" + " }" + " class C2 implements I {" + "         Int i = 0;" + "         uses T3;" + "         Unit foo(){ i = i-1; }" + "         Unit bar(){ i = i+1; }" + " }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 2);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 4);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 7 with Model

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

the class TraitTest method removeExistingMethodInTrait.

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

Example 8 with Model

use of abs.frontend.ast.Model 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 9 with Model

use of abs.frontend.ast.Model 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 10 with Model

use of abs.frontend.ast.Model 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)

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