Search in sources :

Example 56 with ClassDecl

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

the class TraitTest method modifyNonExistingMethods.

@Test
public void modifyNonExistingMethods() {
    Model model = assertParse("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(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 57 with ClassDecl

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

the class TraitTest method originalCallMethod.

@Test
public void originalCallMethod() {
    Model model = assertParse("module M; " + " trait T = {} modifies { Unit myMethod(){  original();  skip;} }" + " class C {uses T; Unit myMethod(){ skip; }}");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 1);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 2);
    assertFalse(cls.getMethod(1).getBlock().getStmt(0) instanceof SkipStmt);
    assertTrue(cls.getMethod(1).getBlock().getStmt(1) instanceof SkipStmt);
    assertTrue(cls.getMethod(0).getBlock().getStmt(0) instanceof SkipStmt);
    assertFalse(cls.getMethod(0).toString().equals(cls.getMethod(1).toString()));
}
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 58 with ClassDecl

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

the class TraitTest method modifyExistingMethod.

@Test
public void modifyExistingMethod() {
    Model model = assertParse("module M; " + "trait T = {} modifies { Unit myMethod(){ skip; } } " + "class C {uses T; Unit myMethod(){ println(\"\"); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 1);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 2);
    assertTrue(cls.getMethod(0).getMethodSig().toString().equals(cls.getMethod(1).getMethodSig().toString()));
// myMethod is added twice
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 59 with ClassDecl

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

the class DeltaAttributesIntegerTest method passIntegerConstant.

public void passIntegerConstant() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParse("module M;" + "delta D(Int attr);" + " uses M;" + "    adds class C { Int myField = attr; }" + "productline PL;" + "    features A,B;" + "    delta D(0) when A;" + "    delta D(99) when B;" + "product P1(A);" + "product P2(B);");
    model.flattenForProduct(product);
    model.evaluateAllProductDeclarations();
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getField(0).getName().equals("myField"));
    assertTrue(cls.getField(0).getInitExp().toString().equals(expected));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model)

Example 60 with ClassDecl

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

the class DeltaAttributesIntegerTest method passIntegerFeatureAttribute.

@Test
public void passIntegerFeatureAttribute() throws DeltaModellingException, WrongProgramArgumentException {
    // TODO: test what happens if attribute is not passed
    // + "product P3(F);"
    Model model = assertParse("module M;" + "delta D(Int attr);" + "uses M;" + "    adds class C { Int myField = attr; }" + "productline PL;" + "    features F;" + "    delta D(F.a) when F;" + "product P1(F{a=0});" + "product P2(F{a=99});");
    model.evaluateAllProductDeclarations();
    model.flattenForProduct(product);
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getField(0).getName().equals("myField"));
    // System.out.println("******** expected: " + expected + " *** found: " + cls.getField(0).getInitExp().toString());
    assertTrue(cls.getField(0).getInitExp().toString().equals(expected));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) 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