use of abs.frontend.ast.MethodSig in project abstools by abstools.
the class StringBasedABSTestRunnerGenerator method generateDataPoints.
/**
* Generates data points for test class {@code clazz}
*
* @param inf
* @param clazz
* @param paramNames
* @param main
* @return The data type the set return type is parametric on, null if
* {@code inf} does not define a data point method or {@code clazz}
* does not implement such method.
*/
private Type generateDataPoints(InterfaceDecl inf, ClassDecl clazz, Set<Type> paramNames, TestRunnerScriptBuilder main) {
MethodSig dataPoint = findDataPoints(inf);
if (dataPoint == null) {
return null;
}
/*
* It must be a Set of data
*/
Type data = ((ParametricDataTypeUse) dataPoint.getReturnType()).getParams().iterator().next().getType();
/*
* make sure the return type can be resolved TODO this needs to be
* resolved recursively
*/
paramNames.add(data);
/*
* create an object in the same cog as main for retrieving the data
* points
*/
String objName = uncap(clazz.getName()) + "dataPoint";
String dataSet = dataPointSetName(clazz);
newObj(main, inf, clazz, objName, false);
main.append(dataPoint.getReturnType()).append(" ").append(dataSet).append(" = ").append(objName).append(".").append(dataPoint.getName()).append("();").newLine();
return data;
}
use of abs.frontend.ast.MethodSig in project abstools by abstools.
the class TraitTest method addRemoveModifierAtRuntime.
@Test
public void addRemoveModifierAtRuntime() {
Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
List<MethodSig> l = new List<>(sig);
RemoveMethodModifier opr = new RemoveMethodModifier(l);
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.addDeltaAccess(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(0, cls.getMethods().getNumChild());
}
use of abs.frontend.ast.MethodSig in project abstools by abstools.
the class TraitTest method addAddModifierAtRuntimeBackComp.
@Test
public void addAddModifierAtRuntimeBackComp() {
Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())), false);
AddMethodModifier opr = new AddMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.addDeltaAccess(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(2, cls.getMethods().getNumChild());
}
use of abs.frontend.ast.MethodSig in project abstools by abstools.
the class ABSUnitTestCaseTranslator method createTestSuiteForClassMethod.
/**
* Create a test suite for testing a method.
*
* @param testCases
* @param testInterface
* @param className
* @param methodName
*/
private void createTestSuiteForClassMethod(List<TestCase> testCases, InterfaceDecl testInterface, String className, String methodName) {
// create test class ([Suite])
final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
module.addDecl(testClass);
// find class under test.
ClassDecl classUnderTest = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(className));
assert classUnderTest != null : "It should not be possible to not " + "find class under test";
// find method under test.
MethodImpl methodUnderTest = findMethodImpl(classUnderTest, new MethodNamePredicate(methodName));
assert methodUnderTest != null : "It should not be possible to not " + "find method under test";
// find interface of class under test.
InterfaceDecl interfaceOfClassUnderTest = findInterfaceUnderTest(methodName, classUnderTest);
if (interfaceOfClassUnderTest == null) {
// this method is not exposed by any interface!
}
// return type
MethodSig signature = methodUnderTest.getMethodSig();
final Access access = signature.getReturnType();
// add imports of class/interface under test
importModules.add(classUnderTest.getModuleDecl().getName());
importModules.add(interfaceOfClassUnderTest.getModuleDecl().getName());
/*
* Test methods and Test cases are ordered that is,
* test case 1 is implemented by test method 1 and so on...
*/
for (int i = 0; i < testCases.size(); i++) {
console("Generating test case " + i + "...");
TestCase testCase = testCases.get(i);
MethodImpl method = testClass.getMethod(i);
methodBuilder.buildTestCase(testCase, testClass, method, access, methodName);
}
}
use of abs.frontend.ast.MethodSig in project abstools by abstools.
the class ABSUnitTestCaseTranslatorHelper method createTestClass.
ClassDecl createTestClass(InterfaceDecl inf) {
ClassDecl ct = new ClassDecl(testCaseNameBuilder.className(inf.getName()), new abs.frontend.ast.List<Annotation>(), new abs.frontend.ast.List<ParamDecl>(), new abs.frontend.ast.List<InterfaceTypeUse>(), new Opt<InitBlock>(), new abs.frontend.ast.List<CaseBranchStmt>(), new abs.frontend.ast.List<FieldDecl>(), new abs.frontend.ast.List<MethodImpl>());
ct.addAnnotation(getTestAnnotation(suiteType));
ct.addImplementedInterfaceUse(new InterfaceTypeUse(inf.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
for (MethodSig m : inf.getAllMethodSigs()) {
ct.addMethod(createMethodImpl(m));
}
FieldDecl assertImpl = new FieldDecl();
assertImpl.setName(ASSERT_HELPER);
assertImpl.setAccess(absAssertImpl.getImplementedInterfaceUse(0).treeCopyNoTransform());
ct.addField(assertImpl);
InitBlock block = new InitBlock();
block.addStmtNoTransform(getVAssign(ASSERT_HELPER, newObj(absAssertImpl, false)));
ct.setInitBlock(block);
return ct;
}
Aggregations