Search in sources :

Example 6 with InternalASTNode

use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.

the class ABSNavigatorStyledLabelProvider method getStyledString.

/**
 * Gets a styledString for the object. If the object is
 * <ul>
 *  <li>an InternalASTnode&lt;ModuleDecl&gt;, the part of the name after the last '.' will be returned.</li>
 * </ul>
 * In all other cases {@link org.absmodels.abs.plugin.editor.outline.ABSContentOutlineUtils#getLabel(ModulePath)} will be used.
 * @param obj the Object whose String representation should be returned
 * @return A String representation of obj
 */
protected StyledString getStyledString(Object obj) {
    StyledString styledString;
    if (obj instanceof InternalASTNode) {
        InternalASTNode<?> node = (InternalASTNode<?>) obj;
        if (node.getASTNode() instanceof ModuleDecl) {
            String name = ((ModuleDecl) node.getASTNode()).getName();
            String lastName;
            if (name.indexOf('.') > 0) {
                lastName = name.substring(name.lastIndexOf('.') + 1, name.length());
            } else {
                lastName = name;
            }
            styledString = new StyledString(lastName, STYLER_BLACK);
        } else {
            styledString = getLabel(node);
        }
    } else if (obj instanceof ModulePath) {
        styledString = getLabel((ModulePath) obj);
    } else {
        styledString = getLabel(obj);
    }
    return styledString;
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 7 with InternalASTNode

use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.

the class NavigatorContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof InternalASTNode) {
        return outlineProvider.getChildren(parentElement);
    } else if (parentElement instanceof IProject) {
        if (((IProject) parentElement).isOpen()) {
            AbsNature nature = UtilityFunctions.getAbsNature((IProject) parentElement);
            assert nature != null;
            return ModulePath.getRootHierarchy(nature).toArray();
        }
    } else if (parentElement instanceof ModulePath) {
        ModulePath mPath = (ModulePath) parentElement;
        ArrayList<Object> children = new ArrayList<Object>();
        children.addAll(mPath.getChildModulePathsAndModuleDecls());
        InternalASTNode<ModuleDecl> intNode = mPath.getModuleDecl();
        // if the module path has a matching module declaration unfold its content..
        if (intNode != null) {
            ModuleDecl md = intNode.getASTNode();
            ArrayList<ASTNode<?>> chld = getChildrenOf(md);
            ASTNode<?>[] chldArr = chld.toArray(new ASTNode<?>[chld.size()]);
            List<InternalASTNode<ASTNode<?>>> wrapASTNodes = InternalASTNode.wrapASTNodes(chldArr, mPath.getNature());
            children.addAll(wrapASTNodes);
            return (children.toArray());
        }
        return children.toArray();
    }
    return super.getChildren(parentElement);
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ASTNode(abs.frontend.ast.ASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 8 with InternalASTNode

use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.

the class NavigatorUtils method openEditor.

/**
 * Opens the file in an editor that corresponds to the given
 * TreeSelection. Only the first element of the selection will be
 * taken into account.
 *
 * @param ts TreeSelection that is used as a base to find an appropriate editor
 * @throws PartInitException - if the editor could not be opened for highlighting
 */
public static void openEditor(TreeSelection ts) throws PartInitException {
    if (!ts.equals(TreeSelection.EMPTY)) {
        TreePath path = ts.getPaths()[0];
        IProject project = getProject(path);
        if (project != null) {
            if (path.getLastSegment() instanceof InternalASTNode<?>) {
                InternalASTNode<?> node = (InternalASTNode<?>) path.getLastSegment();
                openAndHighlightEditor(node);
            } else if (path.getLastSegment() instanceof ModulePath) {
                ModulePath mp = (ModulePath) path.getLastSegment();
                if (mp.hasModuleWithDecls()) {
                    InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
                    openAndHighlightEditor(moduleDecl);
                }
            } else if (path.getLastSegment() instanceof PackageAbsFile) {
                openABSEditorForFile((PackageAbsFile) path.getLastSegment());
            }
        }
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) IProject(org.eclipse.core.resources.IProject) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile)

Example 9 with InternalASTNode

use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.

the class NewABSFileWizard method getProjectSelectionFromModulePath.

private IStructuredSelection getProjectSelectionFromModulePath(IStructuredSelection sel) {
    ModulePath mp = getLastModulePathElement(sel);
    if (mp != null) {
        AbsNature nature = mp.getNature();
        IProject project = nature.getProject();
        Set<InternalASTNode<ModuleDecl>> modulesForPrefix = mp.getModulesForPrefix();
        // Get first the of element in the HashSet
        InternalASTNode<ModuleDecl> m = modulesForPrefix.isEmpty() ? null : modulesForPrefix.iterator().next();
        List<IResource> folders = new ArrayList<IResource>();
        folders.add(project);
        if (m != null) {
            CompilationUnit compilationUnit = m.getASTNode().getCompilationUnit();
            IPath path = new Path(compilationUnit.getFileName());
            path = path.makeRelativeTo(project.getLocation());
            for (int i = 0; i < path.segmentCount() - 1; i++) {
                folders.add(project.getFolder(path.segment(i)));
            }
        }
        TreePath treePath = new TreePath(folders.toArray());
        TreeSelection treeSelection = new TreeSelection(new TreePath[] { treePath });
        return treeSelection;
    }
    return sel;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) TreePath(org.eclipse.jface.viewers.TreePath) IPath(org.eclipse.core.runtime.IPath) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) Path(org.eclipse.core.runtime.Path) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) IPath(org.eclipse.core.runtime.IPath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) IResource(org.eclipse.core.resources.IResource)

Example 10 with InternalASTNode

use of org.absmodels.abs.plugin.util.InternalASTNode 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)

Aggregations

InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)13 ModuleDecl (abs.frontend.ast.ModuleDecl)8 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)6 IProject (org.eclipse.core.resources.IProject)5 ArrayList (java.util.ArrayList)3 ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)3 CompilationUnit (abs.frontend.ast.CompilationUnit)2 Model (abs.frontend.ast.Model)2 IPath (org.eclipse.core.runtime.IPath)2 StyledString (org.eclipse.jface.viewers.StyledString)2 TreePath (org.eclipse.jface.viewers.TreePath)2 Test (org.junit.Test)2 ASTNode (abs.frontend.ast.ASTNode)1 PackageAbsFile (org.absmodels.abs.plugin.editor.outline.PackageAbsFile)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1