Search in sources :

Example 11 with AbsNature

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

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class UtilityFunctions method getPackageAbsFile.

/**
 * A convenient method to reconstruct a {@link PackageAbsFile} from the absolute
 * path to the ABS package and the name to the specific entry in the package.
 * @param proj the project which the package belongs to
 * @param pak
 * @param entry
 * @return
 */
public static PackageAbsFile getPackageAbsFile(IProject proj, String pak, String entry) {
    File file = new File(pak);
    try {
        if (new ABSPackageFile(file).isABSPackage()) {
            PackageEntry pentry = null;
            if (proj != null) {
                AbsNature nature = getAbsNature(proj);
                for (PackageEntry e : nature.getPackages().getPackages()) {
                    if (e.getPath().equals(file.getAbsolutePath())) {
                        pentry = e;
                        break;
                    }
                }
            }
            if (pentry == null) {
                PackageContainer container = new PackageContainer();
                container.setProject(proj);
                pentry = new PackageEntry(container, file.getName(), file.getAbsolutePath(), true);
            }
            return new PackageAbsFile(pentry, entry);
        }
    } catch (IOException e) {
    }
    return null;
}
Also used : ABSPackageFile(abs.frontend.parser.ABSPackageFile) PackageEntry(org.absmodels.abs.plugin.editor.outline.PackageEntry) PackageContainer(org.absmodels.abs.plugin.editor.outline.PackageContainer) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) ABSPackageFile(abs.frontend.parser.ABSPackageFile) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile)

Example 13 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature 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 14 with AbsNature

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

Example 15 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class NavigatorUtils method updateDependencies.

public static void updateDependencies(TreeSelection ts) {
    IProject project = getProject(ts);
    if (project != null) {
        AbsNature nature = getAbsNature(project);
        nature.initDependencies();
    }
}
Also used : IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Aggregations

AbsNature (org.absmodels.abs.plugin.builder.AbsNature)27 IProject (org.eclipse.core.resources.IProject)10 Model (abs.frontend.ast.Model)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)8 ArrayList (java.util.ArrayList)6 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)6 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)6 CompilationUnit (abs.frontend.ast.CompilationUnit)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 DeltaModellingException (abs.frontend.delta.DeltaModellingException)3 IOException (java.io.IOException)3 LocationType (abs.frontend.typechecker.locationtypes.LocationType)2 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)2 File (java.io.File)2 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2