use of abs.frontend.ast.ModuleModifier in project abstools by abstools.
the class ABSUnitTestCaseBuilder method createObjectsInHeap.
void createObjectsInHeap(String testMethodName, Set<String> heapNames, Map<String, InterfaceTypeUse> objectsInHeap, ClassDecl testClass, Map<ABSRef, ABSObject> initialHeap, Block testMethodBlock) {
String setMethodForTest = testCaseNameBuilder.initialTestMethodName(testMethodName);
Block modifyBlock = initialiseDeltaForTestClass(testClass, testCaseNameBuilder.initialTestMethodName(testMethodName));
testMethodBlock.addStmtNoTransform(getExpStmt(getCall(getThis(), setMethodForTest, true)));
Map<String, String> typeHierarchy = new HashMap<String, String>();
Map<String, List<Stmt>> initialisations = new HashMap<String, List<Stmt>>();
List<String> initialisationsOrders = new ArrayList<String>();
for (ABSRef r : initialHeap.keySet()) {
makeSetStatements(typeHierarchy, initialisations, initialisationsOrders, testMethodName, heapNames, initialHeap, objectsInHeap, r, initialHeap.get(r), testClass);
}
for (String ref : initialisationsOrders) {
for (Stmt s : initialisations.get(ref)) {
modifyBlock.addStmtNoTransform(s);
}
}
String testClassName = testClass.getName();
DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
ModifyClassModifier cm = null;
for (ModuleModifier m : delta.getModuleModifiers()) {
if (m.getName().equals(testClassName)) {
cm = (ModifyClassModifier) m;
break;
}
}
for (String r : objectsInHeap.keySet()) {
FieldDecl field = new FieldDecl();
field.setName(r);
InterfaceTypeUse inf = objectsInHeap.get(r);
field.setAccess(inf);
testClass.addField(field);
// allow access of subtype information
cm.addModifier(new RemoveFieldModifier(field.treeCopyNoTransform()));
FieldDecl newField = new FieldDecl();
newField.setName(r);
newField.setAccess(new InterfaceTypeUse(typeHierarchy.get(inf.getName()), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
cm.addModifier(new AddFieldModifier(newField));
}
}
Aggregations