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