Search in sources :

Example 1 with SkipStmt

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

the class TraitTest method removeInClassVsRemoveInTrait.

@Test
public void removeInClassVsRemoveInTrait() {
    Model model = assertParse("module M;" + "trait T = { Unit x() { println(\"signature change\"); } Unit y() { skip; } }" + "trait T2 = T removes Unit x();  adds { Unit x(Int i) { skip; } } " + "class C  { uses T2; }" + "class C2  { 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);
    ClassDecl cls2 = (ClassDecl) findDecl(model, "M", "C2");
    assertNotNull(cls2);
    assertTrue(cls2.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);
    assertTrue(cls2.getMethods().getNumChild() == 2);
    assertTrue(cls2.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
    assertTrue(cls2.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)

Example 2 with SkipStmt

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

the class TraitTest method addAndModifyExistingMethod.

@Test
public void addAndModifyExistingMethod() {
    Model model = assertParse("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(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 3 with SkipStmt

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

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
    AddMethodModifier opr = new AddMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.setImportedModule(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) SkipStmt(org.abs_models.frontend.ast.SkipStmt) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 4 with SkipStmt

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

the class TraitTest method addAndModifyExistingMethodInTwoClasses.

@Test
public void addAndModifyExistingMethodInTwoClasses() {
    Model model = assertParse("module M; " + " trait T2 = {Unit myMethod(){ println(\"\"); }}" + " trait T = T2 modifies { Unit myMethod(){ skip; } }" + " class C {uses T; }" + " class C2 {uses T; }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    ClassDecl cls2 = (ClassDecl) findDecl(model, "M", "C2");
    assertNotNull(cls2);
    assertTrue(cls2.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 1);
    assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
    assertTrue(cls2.getMethods().getNumChild() == 1);
    assertTrue(cls2.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 5 with SkipStmt

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

the class TraitTest method modifyTwiceExistingMethod.

@Test
public void modifyTwiceExistingMethod() {
    Model model = assertParse("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(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)11 Model (org.abs_models.frontend.ast.Model)11 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 Test (org.junit.Test)11 Block (org.abs_models.frontend.ast.Block)2 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)2 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)2 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)2 List (org.abs_models.frontend.ast.List)2 MethodImpl (org.abs_models.frontend.ast.MethodImpl)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)2 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)1 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)1