Search in sources :

Example 11 with MethodImpl

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

Example 12 with MethodImpl

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

the class ABSUnitTestCaseBuilder method initialiseDeltaForTestClass.

/**
 * Initialise (create if necessary) a delta to modify the given test class.
 * In particular it ensures the delta contains a class modifier for the
 * given test class and within that modifier, a method modifier for the given
 * method name.
 *
 * @param testClass
 * @param setOrAssertMethodForTest
 * @return the method block of the method modifier.
 */
Block initialiseDeltaForTestClass(ClassDecl testClass, String setOrAssertMethodForTest) {
    String testClassName = testClass.getName();
    DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
    if (delta == null) {
        delta = deltaBuilder.createDeltaFor(testClass);
    }
    ModifyClassModifier modifier = findClassOrIfaceModifier(delta, ModifyClassModifier.class, new ModifyClassModifierNamePredicate(testClassName));
    if (modifier == null) {
        modifier = new ModifyClassModifier();
        modifier.setName(testClassName);
        delta.addModuleModifier(modifier);
    }
    MethodSig sig = new MethodSig();
    sig.setName(setOrAssertMethodForTest);
    sig.setReturnType(getUnit());
    // add an empty method to be modified
    MethodImpl setOrAssertMethodForObjectImpl = new MethodImpl(sig, new Block(), false);
    testClass.addMethod(setOrAssertMethodForObjectImpl);
    ModifyMethodModifier mmm = new ModifyMethodModifier(setOrAssertMethodForObjectImpl.treeCopyNoTransform());
    Block modifyBlock = mmm.getMethodImpl().getBlock();
    modifier.addModifier(mmm);
    return modifyBlock;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ModifyMethodModifier(abs.frontend.ast.ModifyMethodModifier) Block(abs.frontend.ast.Block) ModifyClassModifierNamePredicate(abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier)

Example 13 with MethodImpl

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

the class DeltaForGetSetFieldsBuilder method addGetter.

AddMethodModifier addGetter(Exp returnValue, String fieldName, Access returnType) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.getterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), returnType, new abs.frontend.ast.List<ParamDecl>());
    Block block = new Block();
    ReturnStmt rs = new ReturnStmt();
    rs.setRetExp(new FieldUse(fieldName));
    block.addStmtNoTransform(rs);
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Block(abs.frontend.ast.Block) ReturnStmt(abs.frontend.ast.ReturnStmt) Annotation(abs.frontend.ast.Annotation)

Example 14 with MethodImpl

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

the class HyperlinkInformationControl method widgetSelected.

@Override
public void widgetSelected(SelectionEvent e) {
    if (firstSelect) {
        // ignore the first selection event
        firstSelect = false;
        return;
    }
    MethodImpl m = implementingMethods.get(list.getSelectionIndex());
    AbsHyperlinkDetector.jumpToPosition(editor, AbsHyperlinkDetector.getPosition(m));
    dispose();
}
Also used : MethodImpl(abs.frontend.ast.MethodImpl)

Aggregations

MethodImpl (abs.frontend.ast.MethodImpl)14 ClassDecl (abs.frontend.ast.ClassDecl)7 MethodSig (abs.frontend.ast.MethodSig)7 Block (abs.frontend.ast.Block)5 DeltaAccess (abs.frontend.ast.DeltaAccess)5 AddMethodModifier (abs.frontend.ast.AddMethodModifier)4 DeltaDecl (abs.frontend.ast.DeltaDecl)4 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)4 ParamDecl (abs.frontend.ast.ParamDecl)4 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)3 Annotation (abs.frontend.ast.Annotation)3 FieldDecl (abs.frontend.ast.FieldDecl)3 Test (org.junit.Test)3 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)2 Access (abs.frontend.ast.Access)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 FieldUse (abs.frontend.ast.FieldUse)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 List (abs.frontend.ast.List)2