Search in sources :

Example 1 with DeltaAccess

use of abs.frontend.ast.DeltaAccess in project abstools by abstools.

the class TraitTest method addRemoveModifierAtRuntime.

@Test
public void addRemoveModifierAtRuntime() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
    List<MethodSig> l = new List<>(sig);
    RemoveMethodModifier opr = new RemoveMethodModifier(l);
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(0, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) RemoveMethodModifier(abs.frontend.ast.RemoveMethodModifier) ClassDecl(abs.frontend.ast.ClassDecl) DeltaAccess(abs.frontend.ast.DeltaAccess) Model(abs.frontend.ast.Model) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 2 with DeltaAccess

use of abs.frontend.ast.DeltaAccess in project abstools by abstools.

the class TraitTest method addAddModifierAtRuntimeBackComp.

@Test
public void addAddModifierAtRuntimeBackComp() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())), false);
    AddMethodModifier opr = new AddMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(2, cls.getMethods().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Model(abs.frontend.ast.Model) Block(abs.frontend.ast.Block) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) SkipStmt(abs.frontend.ast.SkipStmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 3 with DeltaAccess

use of abs.frontend.ast.DeltaAccess 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;
}
Also used : DeltaAccess(abs.frontend.ast.DeltaAccess) DeltaDecl(abs.frontend.ast.DeltaDecl)

Example 4 with DeltaAccess

use of abs.frontend.ast.DeltaAccess 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)

Example 5 with DeltaAccess

use of abs.frontend.ast.DeltaAccess in project abstools by abstools.

the class TraitTest method addModifyModifierAtRuntimeBackComp.

@Test
public void addModifyModifierAtRuntimeBackComp() {
    Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
    MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())), false);
    ModifyMethodModifier opr = new ModifyMethodModifier(impl);
    assertNotNull(opr.getMethodImpl());
    ModifyClassModifier mcn = new ModifyClassModifier();
    mcn.setName("M.C");
    DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
    DeltaDecl dd = new DeltaDecl();
    dd.setName("MyDelta");
    dd.addDeltaAccess(acc);
    dd.addModuleModifier(mcn);
    mcn.addModifier(opr);
    mcn.setParent(dd);
    acc.setParent(dd);
    opr.setParent(mcn);
    sig.setParent(opr);
    CompilationUnit cu = model.getCompilationUnitList().getChild(0);
    cu.addDeltaDecl(dd);
    dd.setParent(cu);
    model.applyDelta(dd);
    assertEquals(1, cls.getMethods().getNumChild());
    assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) DeltaAccess(abs.frontend.ast.DeltaAccess) Model(abs.frontend.ast.Model) Block(abs.frontend.ast.Block) List(abs.frontend.ast.List) DeltaDecl(abs.frontend.ast.DeltaDecl) SkipStmt(abs.frontend.ast.SkipStmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

DeltaAccess (abs.frontend.ast.DeltaAccess)6 DeltaDecl (abs.frontend.ast.DeltaDecl)6 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)4 ClassDecl (abs.frontend.ast.ClassDecl)3 CompilationUnit (abs.frontend.ast.CompilationUnit)3 List (abs.frontend.ast.List)3 MethodImpl (abs.frontend.ast.MethodImpl)3 MethodSig (abs.frontend.ast.MethodSig)3 Model (abs.frontend.ast.Model)3 Test (org.junit.Test)3 AddMethodModifier (abs.frontend.ast.AddMethodModifier)2 Block (abs.frontend.ast.Block)2 SkipStmt (abs.frontend.ast.SkipStmt)2 ASTNode (abs.frontend.ast.ASTNode)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 FieldDecl (abs.frontend.ast.FieldDecl)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)1 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)1 RemoveMethodModifier (abs.frontend.ast.RemoveMethodModifier)1