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"));
}
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()));
}
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
}
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));
}
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));
}
Aggregations