Search in sources :

Example 21 with ModuleDecl

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

the class ModulePath method getModulesForPrefix.

/**
 * Collects ModuleDecls with a given prefix. Only ModuleDecls with a name
 * prefix.Name are returned, ModuleDecls with a name prefix.subPrefix.Name
 * are ignored.
 *
 * prefix is the current module path of this instance.
 *
 * @return Only ModuleDecls with a name prefix.Name are returned,
 *         ModuleDecls with a name prefix.subPrefix.Name are ignored
 */
public Set<InternalASTNode<ModuleDecl>> getModulesForPrefix() {
    LinkedHashSet<InternalASTNode<ModuleDecl>> names = new LinkedHashSet<InternalASTNode<ModuleDecl>>();
    Model model = absNature.getCompleteModel();
    if ("".equals(modulePath)) {
        for (ModuleDecl m : model.getModuleDecls()) {
            String name = m.getName();
            if (!name.equals(STDLIB_NAME)) {
                if (name.indexOf('.') < 0 && !hasSubModule(name) && !name.equals(modulePath) && !names.contains(m)) {
                    // FIXME: Review, can a ModuleDecl really be inside Set<nternalASTNode<..>>? GC_UNRELATED_TYPES
                    names.add(new InternalASTNode<ModuleDecl>(m, absNature));
                }
            }
        }
        return names;
    } else {
        for (ModuleDecl m : model.getModuleDecls()) {
            String name = m.getName();
            if (!name.equals(STDLIB_NAME)) {
                String regex = NavigatorUtils.buildRegex(modulePath);
                if ((name.matches(regex) && !existsSubLayer(name)) && !hasSubModule(name)) {
                    names.add(new InternalASTNode<ModuleDecl>(m, absNature));
                }
            }
        }
        return names;
    }
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 22 with ModuleDecl

use of abs.frontend.ast.ModuleDecl 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 23 with ModuleDecl

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

Example 24 with ModuleDecl

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

the class ModuleGroupContentProvider method getChildrenOf.

/**
 * Returns the children of a project.
 *
 * @param project
 * @return The children of the Project or an empty object array if the
 *         project is closed or not an ABS project or an Exception occurs
 */
private Object[] getChildrenOf(IProject project) {
    try {
        if (project.isAccessible() && project.hasNature(Constants.NATURE_ID)) {
            AbsNature nature = UtilityFunctions.getAbsNature(project);
            if (nature != null) {
                synchronized (nature.modelLock) {
                    ArrayList<InternalASTNode<?>> decls = new ArrayList<InternalASTNode<?>>();
                    Model model = nature.getCompleteModel();
                    // something could be compiled in the project (i.e. the project is not empty...)
                    if (model != null) {
                        Collection<ModuleDecl> moduleDecls = model.getModuleDecls();
                        for (ModuleDecl m : moduleDecls) {
                            String name = m.getName();
                            /* Don't show internal resources which would be read-only anyway.
								 * This is either the standard lib, or e.g. ABS.FLI, ABS.DC */
                            if (name.startsWith("ABS.")) {
                                continue;
                            }
                            decls.add(new InternalASTNode<ModuleDecl>(m, nature));
                        }
                    }
                    return decls.toArray();
                }
            }
        }
    } catch (CoreException ce) {
        ce.printStackTrace();
        return EMPTY_OBJECT_ARRAY;
    }
    return EMPTY_OBJECT_ARRAY;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 25 with ModuleDecl

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

the class WizardUtilsTests method testValidateInterface.

@Test
public void testValidateInterface() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    InterfaceDecl m1 = mock(InterfaceDecl.class);
    InterfaceDecl m2 = mock(InterfaceDecl.class);
    when(m1.getName()).thenReturn("Interface1");
    when(m2.getName()).thenReturn("Interface2");
    list.add(m1);
    list.add(m2);
    when(mockDecl.getDecls()).thenReturn(list);
    String valid1 = "A";
    String valid2 = "Abc3";
    String valid3 = "ABC3";
    String invalid1 = "";
    String invalid2 = "a";
    String invalid3 = "a.b";
    String invalid4 = ";";
    String invalid5 = "module";
    String invalid6 = "Interface1";
    String invalid7 = "Interface2";
    assertTrue(validateInterface(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateInterface(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateInterface(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateInterface(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateInterface(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : ModuleDecl(abs.frontend.ast.ModuleDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) List(abs.frontend.ast.List) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Test(org.junit.Test)

Aggregations

ModuleDecl (abs.frontend.ast.ModuleDecl)29 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)10 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)8 Decl (abs.frontend.ast.Decl)7 Model (abs.frontend.ast.Model)7 ArrayList (java.util.ArrayList)7 ClassDecl (abs.frontend.ast.ClassDecl)6 CompilationUnit (abs.frontend.ast.CompilationUnit)6 ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)5 IProject (org.eclipse.core.resources.IProject)5 InterfaceDecl (abs.frontend.ast.InterfaceDecl)4 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)4 Test (org.junit.Test)4 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EditorPosition (org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition)2 IFile (org.eclipse.core.resources.IFile)2