Search in sources :

Example 1 with InternalASTNode

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

the class NewModuleWizard method setInitialInput.

private void setInitialInput() {
    if (firstSelection instanceof IFile) {
        IFile file = (IFile) firstSelection;
        if (file.getName().endsWith("." + Constants.ABS_FILE_EXTENSION)) {
            page.setInitialFileResource(file);
        }
    } else if (firstSelection instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) firstSelection;
        if (node.hasASTNodeOfType(ModuleDecl.class)) {
            ModuleDecl m = (ModuleDecl) node.getASTNode();
            page.setInitialValue(m.getName() + ".");
            IFile file = UtilityFunctions.getFileOfModuleDecl(m);
            page.setInitialFileResource(file);
        }
    } else if (firstSelection instanceof ModulePath) {
        ModulePath mp = (ModulePath) firstSelection;
        page.setInitialValue(mp.getModulePath() + ".");
        InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
        if (moduleDecl.hasASTNodeOfType(ModuleDecl.class)) {
            IFile fileOfModuleDecl = UtilityFunctions.getFileOfModuleDecl(mp.getModuleDecl().getASTNode());
            page.setInitialFileResource(fileOfModuleDecl);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 2 with InternalASTNode

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

the class UtilityFunctionsTest method testGetPathOfModuleDecl.

@Test
public void testGetPathOfModuleDecl() throws Exception {
    ModuleDecl md = mock(ModuleDecl.class);
    CompilationUnit cd = mock(CompilationUnit.class);
    AbsNature nature = mock(AbsNature.class);
    InternalASTNode<ModuleDecl> internalASTNode = new InternalASTNode<ModuleDecl>(md, nature);
    when(cd.getFileName()).thenReturn("C:/test.abs");
    when(md.getCompilationUnit()).thenReturn(cd);
    IPath pathOfModuleDecl = getPathOfModuleDecl(internalASTNode);
    assertEquals("C:/test.abs", pathOfModuleDecl.toString());
    assertSame(getPathOfModuleDecl(null), null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Test(org.junit.Test)

Example 3 with InternalASTNode

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

the class WizardUtilsTests method testGetProjectOfModuleDecl.

@Test
public void testGetProjectOfModuleDecl() {
    AbsNature natureMock = mock(AbsNature.class);
    IProject project = mock(IProject.class);
    when(project.getName()).thenReturn("");
    when(natureMock.getProject()).thenReturn(project);
    ModuleDecl moduleMock = mock(ModuleDecl.class);
    InternalASTNode<ModuleDecl> node = new InternalASTNode<ModuleDecl>(moduleMock, natureMock);
    assertSame(node.getProject(), project);
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 4 with InternalASTNode

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

the class ModuleDecorator method decorate.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) element;
        if (node.hasASTNodeOfType(ModuleDecl.class)) {
            checkModuleDecl(decoration, (InternalASTNode<ModuleDecl>) node);
        }
    } else if (element instanceof ModulePath) {
        ModulePath m = (ModulePath) element;
        checkModulePath(decoration, m);
    } else if (element instanceof IProject) {
        IProject project = (IProject) element;
        checkProject(project, decoration);
    }
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) IProject(org.eclipse.core.resources.IProject)

Example 5 with InternalASTNode

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

the class OpenTypeHierarchyDelegate method getNodeUnderCursor.

InternalASTNode<?> getNodeUnderCursor(ABSEditor abseditor, TextSelection sel) {
    InternalASTNode<CompilationUnit> cu = abseditor.getCompilationUnit();
    if (cu == null) {
        return null;
    }
    IDocument doc = abseditor.getDocumentProvider().getDocument(editor.getEditorInput());
    synchronized (cu.getNature()) {
        try {
            ASTNode<?> node = UtilityFunctions.getASTNodeOfOffset(doc, cu.getASTNode(), sel.getOffset());
            return new InternalASTNode(node, cu.getNature());
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

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