use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class SourceCodePositionTest method test.
@Test
public void test() throws IOException, InternalBackendException {
File fcore = folder.newFile("core.abs");
File fd1 = folder.newFile("delta1.abs");
File fd2 = folder.newFile("delta2.abs");
{
FileWriter writer = new FileWriter(fcore);
writer.write("module M;" + "class C0 { Unit m() {} }");
writer.close();
}
{
FileWriter writer = new FileWriter(fd1);
writer.write("delta D1; uses M;" + "adds class C1 { Unit m() {} }" + "modifies class C0 { modifies Unit m() {} }");
writer.close();
}
{
FileWriter writer = new FileWriter(fd2);
writer.write("delta D2; uses M;" + "modifies class C1 { modifies Unit m() { original(); } }");
writer.close();
}
HashSet<String> fileNames = new HashSet<>();
fileNames.add(fcore.getCanonicalPath());
fileNames.add(fd1.getCanonicalPath());
fileNames.add(fd2.getCanonicalPath());
Model model = assertParseFilesOk(fileNames, true);
DeltaDecl d1 = findDelta(model, "D1");
DeltaDecl d2 = findDelta(model, "D2");
model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2)));
{
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C0");
assertEquals(cls.getMethod(0).getFileName(), d1.getFileName());
}
{
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C1");
assertEquals(cls.getFileName(), d1.getFileName());
assertEquals(cls.getMethod(0).getFileName(), d2.getFileName());
}
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method removeNonExistingMethodInTrait.
@Test(expected = DeltaModellingException.class)
public void removeNonExistingMethodInTrait() {
Model model = assertParseOk("module M;" + "trait T = {} removes Unit myMethod(); " + "class C {uses T; }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method addModifyRemoveMethod.
@Test
public void addModifyRemoveMethod() {
Model model = assertParseOk("module M;" + "trait T = {Unit myMethod(){ println(\"\"); }} " + "trait T2 = T3 removes Unit myMethod(); " + "trait T3 = T modifies { Unit myMethod(){ skip; }} " + "class C {uses T2; }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 0);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method modifyTwiceTwoTraitsExistingMethod.
@Test
public void modifyTwiceTwoTraitsExistingMethod() {
Model model = assertParseOk("module M; " + "trait T = {Unit myMethod(){ println(\"\"); }} modifies { Unit myMethod(){ println(\"test\"); } }" + "trait T2 = T removes Unit myMethod(); adds { Unit myMethod(){ skip; } }" + "class C {uses T2; }");
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);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class TraitTest method removeInClass.
@Test
public void removeInClass() {
Model model = assertParseOk("module M;" + "trait T = { Unit x() { println(\"signature change\"); } Unit y() { skip; } }" + "class C { 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);
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);
}
Aggregations