Search in sources :

Example 16 with ModuleDecl

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

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

the class InternalASTNode method getParentHierarchyForModuleDecl.

/**
 * Gives the module hierarchy for a given ModuleDecl
 *
 * @return An ArrayList of ModulePaths. This List will be empty if the
 *         ModuleDecl is null
 */
public ArrayList<ModulePath> getParentHierarchyForModuleDecl() {
    ArrayList<ModulePath> hierarchy = new ArrayList<ModulePath>();
    String moduleName = ((ModuleDecl) getASTNode()).getName();
    String[] split = moduleName.split("\\.");
    StringBuffer work = new StringBuffer();
    for (int i = 0; i < split.length - 1; i++) {
        work.append(split[i]);
        ModulePath path = new ModulePath(getNature(), work.toString());
        hierarchy.add(path);
        work.append('.');
    }
    return hierarchy;
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) ArrayList(java.util.ArrayList) ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 18 with ModuleDecl

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

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

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

the class LinkHelper method findSelection.

/**
 * {@inheritDoc}
 */
@Override
public IStructuredSelection findSelection(IEditorInput anInput) {
    if (anInput instanceof FileEditorInput) {
        FileEditorInput fileInput = (FileEditorInput) anInput;
        IProject project = getProject(fileInput);
        AbsNature nature = getAbsNature(project);
        // If we did not get back an ABS nature, do nothing.
        if (nature == null) {
            return null;
        }
        ITextEditor editor = UtilityFunctions.openABSEditorForFile(fileInput.getPath(), project);
        IFile file = fileInput.getFile();
        ModuleDecl md = getModuleDeclAtCurrentCursor(file, nature, editor);
        return buildTreeSelection(nature, project, new InternalASTNode<ModuleDecl>(md, nature));
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ModuleDecl(abs.frontend.ast.ModuleDecl) IProject(org.eclipse.core.resources.IProject) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

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