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());
}
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"));
}
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));
}
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));
}
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;
}
Aggregations