Search in sources :

Example 16 with MethodSig

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

the class ASTBasedABSTestRunnerGenerator method generateDataPointsAST.

private TypeUse generateDataPointsAST(InterfaceDecl key, ClassDecl clazz, Set<TypeUse> use, MainBlock block) {
    MethodSig dataPoint = findDataPoints(key);
    if (dataPoint == null) {
        return null;
    }
    Access rt = dataPoint.getReturnType();
    if (!(rt instanceof ParametricDataTypeUse)) {
        return null;
    }
    ParametricDataTypeUse prt = (ParametricDataTypeUse) rt;
    if (!prt.getName().equals("Set")) {
        return null;
    }
    // Set has only one type parameter
    TypeUse u = (TypeUse) prt.getParam(0).copy();
    use.add(u);
    String objName = uncap(clazz.getName()) + "dataPoint";
    String dataSet = dataPointSetName(clazz);
    block.addStmtNoTransform(newObj(key, clazz, objName, true));
    block.addStmtNoTransform(getVarDecl(dataSet, prt.copy(), new SyncCall(new VarUse(objName), dataPoint.getName(), new List<>())));
    return u;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) SyncCall(abs.frontend.ast.SyncCall) Access(abs.frontend.ast.Access) VarUse(abs.frontend.ast.VarUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse)

Example 17 with MethodSig

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

the class AbsASTBuilderUtil method createMethodSig.

public static final MethodSig createMethodSig(String methodName, Access returnType, ParamDecl... decls) {
    abs.frontend.ast.List<ParamDecl> dl = new abs.frontend.ast.List<>();
    for (ParamDecl d : decls) {
        dl.add(d);
    }
    MethodSig method = new MethodSig(methodName, new abs.frontend.ast.List<>(), returnType, dl);
    return method;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) ParamDecl(abs.frontend.ast.ParamDecl) List(abs.frontend.ast.List)

Example 18 with MethodSig

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

the class StringBasedABSTestRunnerGenerator method generateTestClassImpl.

private Set<Type> generateTestClassImpl(InterfaceDecl inf, ClassDecl clazz, TestRunnerScriptBuilder main) {
    Set<Type> paramNames = new HashSet<>();
    Type dataType = generateDataPoints(inf, clazz, paramNames, main);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        boolean needdata = method.getParamList().iterator().hasNext();
        if (needdata) {
            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);
            // begin while
            main.append("while (hasNext(").append(dataPointSet).append(")) {").newLine().increaseIndent();
            main.append("Pair<Set<").append(dataType).append(">,").append(dataType).append("> nt = next(").append(dataPointSet).append(");").newLine();
            main.append(dataType).append(" ").append(dataValue).append(" = snd(nt);").newLine();
            main.append(dataPointSet).append(" = fst(nt);").newLine();
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            main.append("//Test cases for method ").append(method.getName()).newLine();
            String objectRef = uncap(namePrefix) + instance;
            main = newCog(main, inf, clazz, objectRef);
            generateAsyncTestCall(main, objectRef, method);
        }
        if (needdata) {
            // end while
            main.decreaseIndent().append("}").newLine();
        }
        instance++;
    }
    return paramNames;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) Type(abs.frontend.typechecker.Type) 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