Search in sources :

Example 1 with ModifyClassModifierNamePredicate

use of abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate 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)

Aggregations

ModifyClassModifierNamePredicate (abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate)1 Block (abs.frontend.ast.Block)1 DeltaDecl (abs.frontend.ast.DeltaDecl)1 MethodImpl (abs.frontend.ast.MethodImpl)1 MethodSig (abs.frontend.ast.MethodSig)1 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)1 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)1