Search in sources :

Example 1 with AddInterfaceModifier

use of abs.frontend.ast.AddInterfaceModifier 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));
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) AddInterfaceModifier(abs.frontend.ast.AddInterfaceModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 AddMethodModifier (abs.frontend.ast.AddMethodModifier)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1 DeltaDecl (abs.frontend.ast.DeltaDecl)1 FieldDecl (abs.frontend.ast.FieldDecl)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)1 MethodImpl (abs.frontend.ast.MethodImpl)1 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)1