Search in sources :

Example 11 with InternalASTNode

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

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

the class ABSContentOutlineProvider method getParent.

@Override
public Object getParent(Object element) {
    if (element instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) element;
        AbsNature nature = node.getNature();
        ASTNode<?> parent = node.getASTNode().getParent();
        assert nature != null;
        /* Root nodes don't have parents, so there's nothing to wrap (ABSTools #301) */
        if (parent == null) {
            assert node.getASTNode() instanceof Model : element;
            return null;
        }
        return new InternalASTNode<ASTNode<?>>(parent, nature);
    }
    return null;
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 13 with InternalASTNode

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

the class ABSContentOutlineUtils method insertCostabsItems.

static void insertCostabsItems(ISelection sel) {
    Object[] selectedItems = ((IStructuredSelection) sel).toArray();
    CostabsLink.ENTRIES_STRINGS = new ArrayList<String>();
    CostabsLink.ENTRIES_NODES = new ArrayList<ASTNode<?>>();
    CostabsLink.LINE_ITEMS = new ArrayList<Integer>();
    if (selectedItems.length > 0)
        CostabsLink.ABS_NATURE = ((InternalASTNode<?>) selectedItems[0]).getNature();
    for (int i = 0; i < selectedItems.length; i++) {
        ASTNode<?> node = ((InternalASTNode<?>) selectedItems[i]).getASTNode();
        CostabsLink.ENTRIES_NODES.add(node);
        String callerName;
        int line;
        if (node instanceof FunctionDecl) {
            FunctionDecl del = (FunctionDecl) node;
            callerName = del.getName();
            line = del.getStartLine();
            CostabsLink.ENTRIES_STRINGS.add(callerName);
            CostabsLink.LINE_ITEMS.add(line);
        } else if (node instanceof MethodImpl) {
            MethodImpl del = (MethodImpl) node;
            ASTNode<?> par = del.getContextDecl();
            if (par instanceof ClassDecl) {
                ClassDecl cl = (ClassDecl) par;
                callerName = cl.getName() + "." + del.getMethodSig().getName();
                line = del.getStartLine();
                CostabsLink.ENTRIES_STRINGS.add(callerName);
                CostabsLink.LINE_ITEMS.add(line);
            }
        } else if (node instanceof MethodSig) {
            MethodSig del = (MethodSig) node;
            ASTNode<?> par = del.getContextDecl();
            if (par instanceof ClassDecl) {
                ClassDecl cl = (ClassDecl) par;
                callerName = cl.getName() + "." + del.getName();
                line = del.getStartLine();
                CostabsLink.ENTRIES_STRINGS.add(callerName);
                CostabsLink.LINE_ITEMS.add(line);
            }
        }
    }
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StyledString(org.eclipse.jface.viewers.StyledString) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode)

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