use of abs.frontend.ast.ClassDecl 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.ClassDecl 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;
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class SchedulerChecker method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
Stmt stmt = CompilerUtils.findStmtForExpression(e);
PureExp sched = CompilerUtils.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
if (sched != null) {
ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
checkScheduleExp(sched, decl, stmt);
}
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class ClassKindTypeExtension method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
ClassDecl d = (ClassDecl) e.lookup(new KindedName(Kind.CLASS, e.getClassName()));
List<Annotation> anns = AnnotationHelper.getAnnotationsOfType(d.getAnnotations(), "ABS.StdLib.ClassKindAnnotation");
if (!anns.isEmpty()) {
String name = ((DataConstructorExp) anns.get(0).getValue()).getDecl().getName();
if (e.hasLocal()) {
if (name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_PLAIN, d.getName()));
}
} else {
if (!name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_COG, d.getName()));
}
}
}
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class ABSUnitRunner method analyzeModelUnit.
private void analyzeModelUnit(Model model) {
System.out.println("Analyzing model:");
for (CompilationUnit cu : model.getCompilationUnits()) {
System.out.println(cu.getFileName());
for (ModuleDecl m : cu.getModuleDecls()) {
for (Decl cd : m.getDecls()) {
if (cd instanceof ClassDecl) {
for (MethodSig ms : ((ClassDecl) cd).getAllMethodSigs()) {
for (Annotation a : ms.getAnnotations()) {
if (a.getType().getSimpleName().equals("Test")) {
System.out.println("Found test method:" + ms.getName());
testMethods.add(ms);
} else if (a.getType().getSimpleName().equals("Suite")) {
System.out.println("Found test suite:" + ms.getName());
}
}
}
}
}
}
}
}
Aggregations