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