Search in sources :

Example 11 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class OriginalCallTest method originalCall2.

@Test
public void originalCall2() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getMethods().getNumChild() == 1);
    DeltaDecl delta1 = findDelta(model, "D");
    assertTrue(delta1.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
    DeltaDecl delta2 = findDelta(model, "D2");
    assertTrue(delta2.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
    /*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
        assertTrue(delta1.getNumModuleModifier() == 2);
        assertTrue(delta2.getNumModuleModifier() == 2);*/
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
    // there should be 3 methods now: the original one and those added by the two deltas
    assertEquals(3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 12 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class OriginalCallTest method targetedDeltaNotYetApplied.

@Test
public void targetedDeltaNotYetApplied() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "class C { Unit m() {} }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }" + "delta D2;" + "uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    try {
        // applying deltas in wrong order (D2 then D1) should throw an exception
        // because D2 has a targeted original call to a method in D1
        // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d2,d1)));
        model.applyDeltas(new ArrayList<>(Arrays.asList(d2, d1)));
        fail("expected a DeltaModellingException");
    } catch (DeltaModellingException e) {
        assertThat(e.getMessage(), containsString("has not yet been applied"));
    }
}
Also used : Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 13 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class ParserTest method entry_deltadecl.

@Test
public void entry_deltadecl() throws Exception {
    CompilationUnit u = new ABSParserWrapper().parse(new StringReader("delta Mon;"));
    DeltaDecl d = (DeltaDecl) u.getDeltaDecl(0);
    Assert.assertNotNull(d);
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) ABSParserWrapper(abs.frontend.antlr.parser.ABSParserWrapper) StringReader(java.io.StringReader) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 14 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class DeltaForGetSetFieldsBuilder method createDeltaFor.

DeltaDecl createDeltaFor(ClassDecl testClass) {
    String deltaName = testCaseNameBuilder.deltaOnClass(testClass.getName());
    DeltaDecl delta = new DeltaDecl();
    delta.setName(deltaName);
    delta.addDeltaAccess(new DeltaAccess(testClass.getModuleDecl().getName()));
    deltas.add(new DeltaWrapper(delta, true));
    return delta;
}
Also used : DeltaAccess(abs.frontend.ast.DeltaAccess) DeltaDecl(abs.frontend.ast.DeltaDecl)

Example 15 with DeltaDecl

use of abs.frontend.ast.DeltaDecl in project abstools by abstools.

the class DeltaForGetSetFieldsBuilder method updateDelta.

/**
 * Add a delta that adds Getters and Setters for clazz.
 *
 * @param extensions
 * @param interf
 * @param clazz
 */
void updateDelta(Map<String, String> typeHierarchy, InterfaceTypeUse interf, ClassDecl clazz) {
    String className = clazz.getName();
    String deltaOnClassName = testCaseNameBuilder.deltaOnClass(className);
    String interfaceForModifyingClassFieldName = testCaseNameBuilder.interfaceForModifyingFieldOfClass(className);
    DeltaDecl dd = getDelta(deltaOnClassName);
    if (dd != null) {
        typeHierarchy.put(interf.getName(), interfaceForModifyingClassFieldName);
        return;
    }
    dd = new DeltaDecl();
    dd.setName(deltaOnClassName);
    dd.addDeltaAccess(new DeltaAccess(clazz.getModuleDecl().getName()));
    // add Setters and Getters
    ModifyClassModifier mcm = new ModifyClassModifier();
    mcm.setName(className);
    InterfaceDecl ai = new InterfaceDecl();
    ai.setName(interfaceForModifyingClassFieldName);
    // extends the existing interface
    InterfaceTypeUse inf = interf.treeCopyNoTransform();
    ai.addExtendedInterfaceUse(inf.treeCopyNoTransform());
    mcm.addAddedInterface(new InterfaceTypeUse(ai.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
    typeHierarchy.put(inf.getName(), interfaceForModifyingClassFieldName);
    for (MethodImpl m : clazz.getMethodList()) {
        if (RUN_METHOD.equals(m.getMethodSig().getName())) {
            mcm.addModifier(removeRun());
            break;
        }
    }
    for (FieldDecl fd : clazz.getFieldList()) {
        AddMethodModifier smm = addSetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
        AddMethodModifier gmm = addGetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
        mcm.addModifier(smm);
        mcm.addModifier(gmm);
        ai.addBody(smm.getMethodImpl().getMethodSig());
        ai.addBody(gmm.getMethodImpl().getMethodSig());
    }
    dd.addModuleModifier(new AddInterfaceModifier(ai));
    dd.addModuleModifier(mcm);
    deltas.add(new DeltaWrapper(dd, false));
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) AddInterfaceModifier(abs.frontend.ast.AddInterfaceModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

DeltaDecl (abs.frontend.ast.DeltaDecl)37 Test (org.junit.Test)32 Model (abs.frontend.ast.Model)30 ClassDecl (abs.frontend.ast.ClassDecl)22 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)15 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)8 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 AddMethodModifier (abs.frontend.ast.AddMethodModifier)6 DeltaAccess (abs.frontend.ast.DeltaAccess)6 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 Block (abs.frontend.ast.Block)4 CompilationUnit (abs.frontend.ast.CompilationUnit)4 MethodImpl (abs.frontend.ast.MethodImpl)4 MethodSig (abs.frontend.ast.MethodSig)4 FrontendTest (abs.frontend.FrontendTest)3 DataTypeDecl (abs.frontend.ast.DataTypeDecl)3 Decl (abs.frontend.ast.Decl)3 FunctionDecl (abs.frontend.ast.FunctionDecl)3 List (abs.frontend.ast.List)3