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;
}
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;
}
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;
}
Aggregations