Search in sources :

Example 6 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath 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 7 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath 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 8 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.

the class ModulePathTest method testClearRootHierarchyCache.

/**
 * Test method for {@link org.absmodels.abs.plugin.navigator.ModulePath#clearRootHierarchyCache()}.
 */
@Test
public void testClearRootHierarchyCache() {
    // Get the cached root hierarchy of our nature mock object
    List<Object> rootHierarchy = ModulePath.getRootHierarchy(natureMock);
    // The root hierarchy should only contain one element, namely the ModulePath A
    assertTrue(rootHierarchy.size() == 1);
    ModulePath originalObject = (ModulePath) rootHierarchy.get(0);
    ModulePath.clearRootHierarchyCache();
    // Get the new root hierarchy of our nature mock object
    List<Object> newRootHierarchy = ModulePath.getRootHierarchy(natureMock);
    // and check the size again
    assertTrue(rootHierarchy.size() == 1);
    ModulePath newObject = (ModulePath) newRootHierarchy.get(0);
    // As the root hierarchy cache was cleared, the elements should not be the same...
    assertTrue(newObject != originalObject);
    // ...but contain the same information
    assertEquals(newObject.getModulePath(), originalObject.getModulePath());
    assertEquals(newObject.getModuleDecl(), originalObject.getModuleDecl());
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) Test(org.junit.Test)

Example 9 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.

the class NewABSFileWizard method insertModuleDeclaration.

/**
 * If the original selection
 * @param targeteditor
 * @throws BadLocationException
 */
private void insertModuleDeclaration(ABSEditor targeteditor) throws BadLocationException {
    IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
    ModulePath mp = getLastModulePathElement(selection);
    if (mp != null) {
        doc.replace(0, 0, "module " + mp.getModulePath() + ".");
        targeteditor.getSelectionProvider().setSelection(new TextSelection(8 + mp.getModulePath().length(), 0));
    } else {
        doc.replace(0, 0, "module ");
        targeteditor.getSelectionProvider().setSelection(new TextSelection(7, 0));
    }
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) TextSelection(org.eclipse.jface.text.TextSelection) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)9 ModuleDecl (abs.frontend.ast.ModuleDecl)5 ArrayList (java.util.ArrayList)3 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)3 Test (org.junit.Test)3 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 IProject (org.eclipse.core.resources.IProject)2 ClassDecl (abs.frontend.ast.ClassDecl)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 Decl (abs.frontend.ast.Decl)1 MainBlock (abs.frontend.ast.MainBlock)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IDocument (org.eclipse.jface.text.IDocument)1 TextSelection (org.eclipse.jface.text.TextSelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1