Search in sources :

Example 36 with ClassDecl

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);
    }
}
Also used : MethodSig(abs.frontend.ast.MethodSig) AbsASTBuilderUtil.findMethodSig(abs.backend.tests.AbsASTBuilderUtil.findMethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) MethodNamePredicate(abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 37 with ClassDecl

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;
}
Also used : InitBlock(abs.frontend.ast.InitBlock) CaseBranchStmt(abs.frontend.ast.CaseBranchStmt) Annotation(abs.frontend.ast.Annotation) FieldDecl(abs.frontend.ast.FieldDecl) AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.createMethodImpl(abs.backend.tests.AbsASTBuilderUtil.createMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse)

Example 38 with ClassDecl

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);
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) PureExp(abs.frontend.ast.PureExp) Stmt(abs.frontend.ast.Stmt)

Example 39 with ClassDecl

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()));
            }
        }
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TypeError(abs.frontend.analyser.TypeError) KindedName(abs.frontend.typechecker.KindedName) Annotation(abs.frontend.ast.Annotation)

Example 40 with ClassDecl

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());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) MethodSig(abs.frontend.ast.MethodSig) ClassDecl(abs.frontend.ast.ClassDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) Annotation(abs.frontend.ast.Annotation)

Aggregations

ClassDecl (abs.frontend.ast.ClassDecl)75 Test (org.junit.Test)59 Model (abs.frontend.ast.Model)57 DeltaDecl (abs.frontend.ast.DeltaDecl)22 FrontendTest (abs.frontend.FrontendTest)12 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 InterfaceDecl (abs.frontend.ast.InterfaceDecl)7 MethodImpl (abs.frontend.ast.MethodImpl)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 MethodSig (abs.frontend.ast.MethodSig)6 ReturnStmt (abs.frontend.ast.ReturnStmt)6 AddMethodModifier (abs.frontend.ast.AddMethodModifier)5 Decl (abs.frontend.ast.Decl)5 DeltaAccess (abs.frontend.ast.DeltaAccess)5 List (abs.frontend.ast.List)5 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 CompilationUnit (abs.frontend.ast.CompilationUnit)4