Search in sources :

Example 1 with DeltaDecl

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

the class OriginalCallTest method targetedOriginalNotFound.

@Test(expected = DeltaModellingException.class)
public void targetedOriginalNotFound() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(d1)));
}
Also used : Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 2 with DeltaDecl

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

the class OriginalCallTest method multipleTargetedOriginalCalls2.

@Test
public void multipleTargetedOriginalCalls2() throws DeltaModellingException {
    Model model = assertParse("module M;" + "class C { }" + "delta D1;" + "uses M;" + "modifies class C { adds Unit m() {} }" + "delta D2;uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }" + "delta D3;uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }" + "delta D4;uses M;" + "modifies class C { modifies Unit m() { D2.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    DeltaDecl d3 = findDelta(model, "D3");
    DeltaDecl d4 = findDelta(model, "D4");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d1,d2,d3)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2, d3, d4)));
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals(cls.getMethods().toString(), 3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_D1"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D2"));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 3 with DeltaDecl

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

the class SourceCodePositionTest method test.

@Test
public void test() throws IOException, InternalBackendException, DeltaModellingException, WrongProgramArgumentException {
    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);
    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(org.abs_models.frontend.ast.ClassDecl) FileWriter(java.io.FileWriter) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with DeltaDecl

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

the class TraitTest method resolveTest.

@Test
public void resolveTest() {
    Model model = assertParse("module TestMod;" + "interface Inter {}" + "trait T = { " + "  Unit printLine_1(){println(\"I'm 1!\");}" + "  Unit printLine_2(){println(\"I'm 2!\");}" + "}" + "trait T2 = { " + "  Unit printLine_2(){println(\"I'm 2!\");}" + "  Unit printLine_3(){println(\"I'm 3!\");}" + "}" + "class InterImpl(Inter inter) implements Inter {   }" + "" + "delta D3;" + "modifies class TestMod.InterImpl{" + "    adds Int i = 0;" + "    adds T modifies T2" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "TestMod", "InterImpl");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    DeltaDecl delta = findDelta(model, "D3");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    ModifyClassModifier mm = (ModifyClassModifier) delta.getModuleModifier(0);
    DeltaTraitModifier dml = (DeltaTraitModifier) mm.getModifier(1);
    AddMethodModifier mcl = (AddMethodModifier) dml.getMethodModifier();
    TraitExpr expr = mcl.getTraitExpr();
    TraitExpr set = expr.resolve(cls.getModuleDecl());
    assertTrue("expected 2, got " + set.getChild(0).getNumChild(), set.getChild(0).getNumChild() == 2);
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TraitExpr(org.abs_models.frontend.ast.TraitExpr) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) DeltaTraitModifier(org.abs_models.frontend.ast.DeltaTraitModifier) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 5 with DeltaDecl

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

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
    AddMethodModifier opr = new AddMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.setImportedModule(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) SkipStmt(org.abs_models.frontend.ast.SkipStmt) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)36 Test (org.junit.Test)35 Model (org.abs_models.frontend.ast.Model)34 ClassDecl (org.abs_models.frontend.ast.ClassDecl)24 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)8 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)4 FrontendTest (org.abs_models.frontend.FrontendTest)3 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)3 Decl (org.abs_models.frontend.ast.Decl)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)3 List (org.abs_models.frontend.ast.List)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 ParametricDataTypeDecl (org.abs_models.frontend.ast.ParametricDataTypeDecl)3 TypeSynDecl (org.abs_models.frontend.ast.TypeSynDecl)3