Search in sources :

Example 6 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class PureExpressionBuilder method importType.

void importType(Decl decl) {
    importModules.add(decl.getModuleDecl().getName());
    if (decl instanceof TypeSynDecl) {
        decl = resolveTypeSynonym((TypeSynDecl) decl);
        importModules.add(decl.getModuleDecl().getName());
    }
    // import type parameters
    if (decl instanceof ParametricDataTypeDecl) {
        for (TypeParameterDecl t : ((ParametricDataTypeDecl) decl).getTypeParameters()) {
            Decl type = getDecl(model, Decl.class, namePred(t.getName()));
            if (type == null) {
                // most likely a generic type
                continue;
            }
            importType(type);
        }
    }
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) AbsASTBuilderUtil.getDecl(abs.backend.tests.AbsASTBuilderUtil.getDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Decl(abs.frontend.ast.Decl) TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl)

Example 7 with Decl

use of abs.frontend.ast.Decl 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)

Example 8 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class DeltaAddFunctionalTest method addFun.

@Test
public void addFun() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "def Int i() = 1;" + "delta I; uses M;" + "adds def Int j<A>(A a) = 2;" + "adds def Int h() = 2;");
    Decl funI = findDecl(model, "M", "i");
    assertNotNull(funI);
    assertThat(funI, instanceOf(FunctionDecl.class));
    DeltaDecl delta = findDelta(model, "I");
    assertNotNull(delta);
    assertThat(delta, instanceOf(DeltaDecl.class));
    Decl funj = findDecl(model, "M", "j");
    assertNull(funj);
    Decl funh = findDecl(model, "M", "h");
    assertNull(funh);
    model.applyDelta(delta);
    funj = findDecl(model, "M", "j");
    assertNotNull(funj);
    assertThat(funj, instanceOf(FunctionDecl.class));
    funh = findDecl(model, "M", "h");
    assertNotNull(funh);
    assertThat(funh, instanceOf(FunctionDecl.class));
}
Also used : Model(abs.frontend.ast.Model) DataTypeDecl(abs.frontend.ast.DataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) DeltaDecl(abs.frontend.ast.DeltaDecl) DeltaDecl(abs.frontend.ast.DeltaDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 9 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class WizardUtil method validateInterface.

/**
 * Same as {@link #validate(String)} but additionally checks, whether the specified
 * interface name already exists in the given module declaration
 *
 * @param text
 *            Name to be checked.
 * @param decl
 *            Target ModuleDecl.
 * @return In case of a duplicate name, this method returns
 *         ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
 *         its information string.
 */
public static ErrorType validateInterface(String text, ModuleDecl decl) {
    if (decl != null) {
        for (Decl d : decl.getDecls()) {
            if (d instanceof InterfaceDecl && d.getName().equals(text)) {
                ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
                type.setInformationString(text);
                return type;
            }
        }
    }
    return validate(text);
}
Also used : InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 10 with Decl

use of abs.frontend.ast.Decl in project abstools by abstools.

the class WizardUtil method validateClass.

/**
 * Same as {@link #validate(String)} but additionally checks, whether the specified
 * class name already exists in the given module declaration
 *
 * @param text
 *            Name to be checked.
 * @param decl
 *            Target ModuleDecl.
 * @return In case of a duplicate name, this method returns
 *         ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
 *         its information string.
 */
public static ErrorType validateClass(String text, ModuleDecl decl) {
    if (decl != null) {
        for (Decl d : decl.getDecls()) {
            if (d instanceof ClassDecl && d.getName().equals(text)) {
                ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
                type.setInformationString(text);
                return type;
            }
        }
    }
    return validate(text);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl)

Aggregations

Decl (abs.frontend.ast.Decl)17 ClassDecl (abs.frontend.ast.ClassDecl)9 InterfaceDecl (abs.frontend.ast.InterfaceDecl)8 ModuleDecl (abs.frontend.ast.ModuleDecl)7 DataTypeDecl (abs.frontend.ast.DataTypeDecl)6 ParametricDataTypeDecl (abs.frontend.ast.ParametricDataTypeDecl)6 TypeSynDecl (abs.frontend.ast.TypeSynDecl)6 Test (org.junit.Test)6 FunctionDecl (abs.frontend.ast.FunctionDecl)5 Model (abs.frontend.ast.Model)4 AbsASTBuilderUtil.getDecl (abs.backend.tests.AbsASTBuilderUtil.getDecl)3 DeltaDecl (abs.frontend.ast.DeltaDecl)3 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 HasCogs (abs.frontend.analyser.HasCogs)1 Annotation (abs.frontend.ast.Annotation)1 Block (abs.frontend.ast.Block)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1