Search in sources :

Example 21 with ClassDecl

use of abs.frontend.ast.ClassDecl 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 22 with ClassDecl

use of abs.frontend.ast.ClassDecl 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 23 with ClassDecl

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

Example 24 with ClassDecl

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

the class TypingTest method testContextDecl.

@Test
public void testContextDecl() {
    Model m = assertParseOk("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.getDecls().iterator().next();
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(d, s.getRetExp().getContextDecl());
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 25 with ClassDecl

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

the class TypingTest method testThisTyping.

@Test
public void testThisTyping() {
    Model m = assertParseOk("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.lookupModule("UnitTest").getDecl(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(m.lookupModule("UnitTest").getDecl(1), ((UnionType) s.getRetExp().getType()).getType(0).getDecl());
}
Also used : UnionType(abs.frontend.typechecker.UnionType) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

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