Search in sources :

Example 31 with DeltaDecl

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

the class OriginalCallTest method multipleCallsToSameMethod.

@Test
public void multipleCallsToSameMethod() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D;" + "modifies class M.C {" + "modifies Unit m() { original(); original(); }" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    DeltaDecl delta = findDelta(model, "D");
    assertEquals(1, delta.getNumModuleModifier());
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
    assertEquals(2, cls.getMethods().getNumChild());
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta)));
// assertEquals(delta.getModuleModifiers().toString(),2, delta.getNumModuleModifier());
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 32 with DeltaDecl

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

the class OriginalCallTest method multipleTargetedOriginalCalls2.

@Test
public void multipleTargetedOriginalCalls2() throws DeltaModellingException {
    Model model = assertParseOk("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(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 33 with DeltaDecl

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

the class DeltaAddFunctionalTest method addDataType.

@Test
public void addDataType() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "data O = O;" + "delta I; uses M;" + "adds data X<A> = X(A a) | N;" + "adds data Y = K | Y(Int i);");
    Decl dataO = findDecl(model, "M", "O");
    assertNotNull(dataO);
    assertThat(dataO, instanceOf(DataTypeDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl dataX = findDecl(model, "M", "X");
    assertNull(dataX);
    Decl dataY = findDecl(model, "M", "Y");
    assertNull(dataY);
    model.applyDelta(delta);
    dataX = findDecl(model, "M", "X");
    assertNotNull(dataX);
    assertThat(dataX, instanceOf(ParametricDataTypeDecl.class));
    dataY = findDecl(model, "M", "Y");
    assertNotNull(dataY);
    assertThat(dataY, instanceOf(DataTypeDecl.class));
}
Also used : Model(abs.frontend.ast.Model) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaDecl(abs.frontend.ast.DeltaDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) Test(org.junit.Test)

Example 34 with DeltaDecl

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

the class DeltaAddFunctionalTest method addTypeSyn.

@Test
public void addTypeSyn() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "type X = Int;" + "delta I; uses M;" + "adds type Y = X;");
    Decl typeX = findDecl(model, "M", "X");
    assertNotNull(typeX);
    assertThat(typeX, instanceOf(TypeSynDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl typeY = findDecl(model, "M", "Y");
    assertNull(typeY);
    model.applyDelta(delta);
    typeY = findDecl(model, "M", "Y");
    assertNotNull(typeY);
    assertThat(typeY, instanceOf(TypeSynDecl.class));
}
Also used : Model(abs.frontend.ast.Model) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaDecl(abs.frontend.ast.DeltaDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) Test(org.junit.Test)

Example 35 with DeltaDecl

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

the class ABSUnitTestCaseBuilder method initialiseDeltaForTestClass.

/**
 * Initialise (create if necessary) a delta to modify the given test class.
 * In particular it ensures the delta contains a class modifier for the
 * given test class and within that modifier, a method modifier for the given
 * method name.
 *
 * @param testClass
 * @param setOrAssertMethodForTest
 * @return the method block of the method modifier.
 */
Block initialiseDeltaForTestClass(ClassDecl testClass, String setOrAssertMethodForTest) {
    String testClassName = testClass.getName();
    DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
    if (delta == null) {
        delta = deltaBuilder.createDeltaFor(testClass);
    }
    ModifyClassModifier modifier = findClassOrIfaceModifier(delta, ModifyClassModifier.class, new ModifyClassModifierNamePredicate(testClassName));
    if (modifier == null) {
        modifier = new ModifyClassModifier();
        modifier.setName(testClassName);
        delta.addModuleModifier(modifier);
    }
    MethodSig sig = new MethodSig();
    sig.setName(setOrAssertMethodForTest);
    sig.setReturnType(getUnit());
    // add an empty method to be modified
    MethodImpl setOrAssertMethodForObjectImpl = new MethodImpl(sig, new Block(), false);
    testClass.addMethod(setOrAssertMethodForObjectImpl);
    ModifyMethodModifier mmm = new ModifyMethodModifier(setOrAssertMethodForObjectImpl.treeCopyNoTransform());
    Block modifyBlock = mmm.getMethodImpl().getBlock();
    modifier.addModifier(mmm);
    return modifyBlock;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) Block(abs.frontend.ast.Block) ModifyClassModifierNamePredicate(abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier)

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