use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.
the class ABSUnitTestCaseBuilder method getTypesFromABSData.
Map<String, InterfaceTypeUse> getTypesFromABSData(String testName, ABSData data) {
Map<String, InterfaceTypeUse> map = new HashMap<String, InterfaceTypeUse>();
if (data instanceof ABSRef) {
String type = getABSDataType(data);
String value = getABSDataValue(data);
if (!value.equals(NULL)) {
map.put(heapRefBuilder.heapReferenceForTest(testName, value), new InterfaceTypeUse(type, new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
}
} else if (data instanceof ABSTerm) {
ABSTerm term = (ABSTerm) data;
for (ABSData t : getABSTermArgs(term)) {
map.putAll(getTypesFromABSData(testName, t));
}
}
return map;
}
use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.
the class ABSUnitTestCaseTranslatorHelper method createTestClass.
ClassDecl createTestClass(InterfaceDecl inf) {
ClassDecl ct = new ClassDecl(testCaseNameBuilder.className(inf.getName()), new abs.frontend.ast.List<Annotation>(), new abs.frontend.ast.List<ParamDecl>(), new abs.frontend.ast.List<InterfaceTypeUse>(), new Opt<InitBlock>(), new abs.frontend.ast.List<CaseBranchStmt>(), new abs.frontend.ast.List<FieldDecl>(), new abs.frontend.ast.List<MethodImpl>());
ct.addAnnotation(getTestAnnotation(suiteType));
ct.addImplementedInterfaceUse(new InterfaceTypeUse(inf.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
for (MethodSig m : inf.getAllMethodSigs()) {
ct.addMethod(createMethodImpl(m));
}
FieldDecl assertImpl = new FieldDecl();
assertImpl.setName(ASSERT_HELPER);
assertImpl.setAccess(absAssertImpl.getImplementedInterfaceUse(0).treeCopyNoTransform());
ct.addField(assertImpl);
InitBlock block = new InitBlock();
block.addStmtNoTransform(getVAssign(ASSERT_HELPER, newObj(absAssertImpl, false)));
ct.setInitBlock(block);
return ct;
}
use of abs.frontend.ast.InterfaceTypeUse 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));
}
use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.
the class ClassDeclGenerator method generateClassHeader.
private void generateClassHeader() {
stream.print("public ");
if (!decl.isForeign())
stream.print("final ");
stream.print("class " + className + " extends " + ABSObject.class.getName() + " implements " + ABSClass.class.getName());
for (InterfaceTypeUse use : decl.getImplementedInterfaceUses()) {
String iname = JavaBackend.getQualifiedString(((InterfaceType) use.getType()).getDecl());
stream.print(", " + iname);
}
}
use of abs.frontend.ast.InterfaceTypeUse in project abstools by abstools.
the class InferMain method shouldBeConsidered.
private boolean shouldBeConsidered(LocationTypeVariable ltv) {
ASTNode<?> node = ltv.getNode();
Decl contextDecl = node.getContextDecl();
if (contextDecl != null) {
// Don't print interface annotations in "implements/extends" clauses:
if (node instanceof InterfaceTypeUse && (contextDecl instanceof ClassDecl || contextDecl instanceof InterfaceDecl))
return false;
if (contextDecl.isClass() && !config.contains(Config.CLASSES))
return false;
if (contextDecl.isInterface() && !config.contains(Config.INTERFACES))
return false;
if (contextDecl.isFunction() && !config.contains(Config.FUNCTIONS))
return false;
}
if (node instanceof VarDecl && !config.contains(Config.LOCAL_VAR_DECLS))
return false;
if (node instanceof FieldDecl && !config.contains(Config.FIELDS))
return false;
if (ltv.getAnnotatedType() != null) {
return false;
}
return true;
}
Aggregations