Search in sources :

Example 46 with ClassDecl

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());
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) FileWriter(java.io.FileWriter) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with ClassDecl

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();
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 48 with ClassDecl

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);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 49 with ClassDecl

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);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) SkipStmt(abs.frontend.ast.SkipStmt) Test(org.junit.Test)

Example 50 with ClassDecl

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);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) SkipStmt(abs.frontend.ast.SkipStmt) Test(org.junit.Test)

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