Search in sources :

Example 76 with ClassDecl

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

the class DeltaAttributesMixedTest method passBooleanFeatureAttributes1.

@Test
public void passBooleanFeatureAttributes1() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParse("module M;" + "delta D(Bool a1, Bool a2);" + "uses M;" + "    adds class C { Bool first = a1; Bool second = a2; }" + "productline PL;" + "    features F;" + "    delta D(F.a, F.b) when F;" + "product P1( F{a=True, b=False} );");
    model.evaluateAllProductDeclarations();
    model.flattenForProduct("P1");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals("first", cls.getField(0).getName());
    assertEquals("True()", cls.getField(0).getInitExp().toString());
    assertEquals("second", cls.getField(1).getName());
    assertEquals("False()", cls.getField(1).getInitExp().toString());
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 77 with ClassDecl

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

the class DeltaAttributesMixedTest method passBooleanFeatureAttributes2.

@Test
public void passBooleanFeatureAttributes2() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParse("module M;" + "delta D(Bool attr);" + "uses M;" + "    adds class C { Bool attr = attr; Unit m() {Bool x = attr;} }" + "productline PL;" + "    features F; delta D(F.a) when F;" + "product P1( F{a=True} );");
    model.evaluateAllProductDeclarations();
    model.flattenForProduct("P1");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals("attr", cls.getField(0).getName());
    assertEquals("True()", cls.getField(0).getInitExp().toString());
// TODO test the value of x
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 78 with ClassDecl

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

the class DeltaAttributesMixedTest method passFeaturesAsBooleans.

@Test
public void passFeaturesAsBooleans() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParse("module M;" + "delta D(Bool a, Bool b, Bool c, Int c_a1);" + "uses M;" + "    adds class C { " + "        Bool fA = a; " + "        Bool fB = b; " + "        Bool fC = c; " + "        Int fC_a1 = c_a1; " + "    }" + "productline PL;" + "    features A,B,C;" + "    delta D(A, B, C, C.a1) when C;" + "product P1( C{a1=99} );");
    model.evaluateAllProductDeclarations();
    model.flattenForProduct("P1");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals("fA", cls.getField(0).getName());
    assertEquals("False()", cls.getField(0).getInitExp().toString());
    assertEquals("fB", cls.getField(1).getName());
    assertEquals("False()", cls.getField(1).getInitExp().toString());
    assertEquals("fC", cls.getField(2).getName());
    assertEquals("True()", cls.getField(2).getInitExp().toString());
    assertEquals("fC_a1", cls.getField(3).getName());
    assertEquals("IntLiteral(99)", cls.getField(3).getInitExp().toString());
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 79 with ClassDecl

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

the class VarResolutionTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParse(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) getTestModule(m).lookup(new KindedName(KindedName.Kind.CLASS, "UnitTest.C"));
    FieldDecl f = d.getField(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(f, ((FieldUse) s.getRetExp()).getDecl());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) FieldDecl(org.abs_models.frontend.ast.FieldDecl) ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) 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