Search in sources :

Example 11 with MethodSig

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

the class JavaGeneratorHelper method generateAwaitAsyncCall.

public static void generateAwaitAsyncCall(PrintStream stream, AwaitAsyncCall call) {
    final PureExp callee = call.getCallee();
    final List<PureExp> params = call.getParams();
    final MethodSig sig = call.getMethodSig();
    final List<Annotation> annotations = call.getAnnotations();
    // FIXME: implement await, assignment afterwards
    // OutputStream exprOStream = new ByteArrayOutputStream();
    // PrintStream exprStream = new PrintStream(exprOStream);
    // ClaimGuard guard = new ClaimGuard();
    // // Necessary temporary variables are written to "stream" and the
    // // await-expression is written to exprStream
    // 
    // // FIXME: implement await, assignment afterwards
    // guard.generateJavaGuard(stream, exprStream);
    // stream.print(JavaBackendConstants.ABSRUNTIME + ".await(");
    // stream.print(exprOStream.toString());
    // stream.println(");");
    generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
Also used : MethodSig(abs.frontend.ast.MethodSig) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation)

Example 12 with MethodSig

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

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

the class ABSUnitTestCaseTranslatorHelper method createTestMethodSig.

/**
 * Create a method signature for testing method with the given method name.
 *
 * @param methodName
 * @param decls
 * @return
 */
MethodSig createTestMethodSig(String methodName, ParamDecl... decls) {
    MethodSig methodSig = createMethodSig(methodName, getUnit(), decls);
    methodSig.addAnnotation(getTestAnnotation(testType));
    return methodSig;
}
Also used : AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig)

Example 14 with MethodSig

use of abs.frontend.ast.MethodSig 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 15 with MethodSig

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

the class ASTBasedABSTestRunnerGenerator method generateTestClassImplAST.

private Set<TypeUse> generateTestClassImplAST(InterfaceDecl inf, ClassDecl clazz, MainBlock block) {
    Set<TypeUse> accesses = new HashSet<>();
    TypeUse dataType = generateDataPointsAST(inf, clazz, accesses, block);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        Block thisBlock = block;
        WhileStmt ws = null;
        if (method.getNumParam() > 0) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            ws = new WhileStmt();
            ws.setCondition(getFnApp("hasNext", new VarUse(dataPointSet)));
            Block body = new Block();
            thisBlock = body;
            DataTypeUse u = getType("Pair", getType("Set", (TypeUse) dataType.copy()), (TypeUse) dataType.copy());
            thisBlock.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(dataPointSet))));
            thisBlock.addStmtNoTransform(getVarDecl(dataValue, (TypeUse) dataType.copy(), getFnApp("snd", new VarUse("nt"))));
            thisBlock.addStmtNoTransform(getVAssign(dataPointSet, getFnApp("fst", new VarUse("nt"))));
            ws.setBody(body);
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            String objectRef = uncap(namePrefix) + instance;
            thisBlock.addStmtNoTransform(newObj(inf, clazz, objectRef, false));
            generateAsyncTestCallAST(thisBlock, objectRef, method);
        }
        if (ws != null) {
            block.addStmtNoTransform(ws);
        }
        instance++;
    }
    return accesses;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) VarUse(abs.frontend.ast.VarUse) HashSet(java.util.HashSet)

Aggregations

MethodSig (abs.frontend.ast.MethodSig)18 MethodImpl (abs.frontend.ast.MethodImpl)7 Annotation (abs.frontend.ast.Annotation)6 Block (abs.frontend.ast.Block)6 ClassDecl (abs.frontend.ast.ClassDecl)6 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)4 CompilationUnit (abs.frontend.ast.CompilationUnit)4 DeltaAccess (abs.frontend.ast.DeltaAccess)4 DeltaDecl (abs.frontend.ast.DeltaDecl)4 List (abs.frontend.ast.List)4 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)4 ParamDecl (abs.frontend.ast.ParamDecl)4 AddMethodModifier (abs.frontend.ast.AddMethodModifier)3 Model (abs.frontend.ast.Model)3 VarUse (abs.frontend.ast.VarUse)3 Test (org.junit.Test)3 Access (abs.frontend.ast.Access)2 DataTypeUse (abs.frontend.ast.DataTypeUse)2 FieldUse (abs.frontend.ast.FieldUse)2 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)2