Search in sources :

Example 16 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class ErlModelUtils method openExternalFunction.

public static boolean openExternalFunction(final String moduleName, final ErlangFunction function, final String modulePath, final IErlModule module, final IErlProject project, final IErlElementLocator.Scope scope) throws CoreException {
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule module2 = ErlangEngine.getInstance().getModelFindService().findModule(model, project, moduleName, modulePath, scope);
    if (module2 != null) {
        final IEditorPart editor = EditorUtility.openInEditor(module2);
        return ErlModelUtils.openFunctionInEditor(function, editor);
    }
    return false;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IEditorPart(org.eclipse.ui.IEditorPart)

Example 17 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class ErlModelUtils method openModule.

public static void openModule(final String moduleName) throws CoreException {
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule module = ErlangEngine.getInstance().getModelFindService().findModule(model, null, moduleName, null, IErlElementLocator.Scope.ALL_PROJECTS);
    if (module != null) {
        EditorUtility.openInEditor(module);
    }
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator)

Example 18 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class ErlModelUtils method getModule.

public static IErlModule getModule(final IEditorInput editorInput) throws CoreException {
    if (editorInput instanceof IFileEditorInput) {
        final IFileEditorInput input = (IFileEditorInput) editorInput;
        final IFile file = input.getFile();
        final IErlModel model = ErlangEngine.getInstance().getModel();
        IErlModule module = model.findModule(file);
        if (module != null) {
            return module;
        }
        final IPath path = file.getLocation();
        Charset encoding;
        try {
            encoding = Charset.forName(file.getCharset());
        } catch (Exception e) {
            encoding = Charsets.UTF_8;
        }
        module = model.getModuleFromFile(model, file.getName(), path, encoding);
        module.setResource(file);
        return module;
    }
    if (editorInput instanceof ErlangExternalEditorInput) {
        final ErlangExternalEditorInput erlangExternalEditorInput = (ErlangExternalEditorInput) editorInput;
        return erlangExternalEditorInput.getModule();
    }
    final String path = ErlModelUtils.getPathForInput(editorInput);
    if (path == null) {
        return null;
    }
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule module = ErlangEngine.getInstance().getModelFindService().findModule(model, null, null, path, IErlElementLocator.Scope.ALL_PROJECTS);
    if (module != null) {
        return module;
    }
    final Charset encoding = ErlModelUtils.getEncodingForInput(editorInput);
    final IPath p = new Path(path);
    return ErlangEngine.getInstance().getModel().getModuleFromFile(null, p.lastSegment(), p, encoding);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ErlangExternalEditorInput(org.erlide.ui.editors.util.ErlangExternalEditorInput) IErlModel(org.erlide.engine.model.root.IErlModel) IPath(org.eclipse.core.runtime.IPath) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IErlModule(org.erlide.engine.model.root.IErlModule) Charset(java.nio.charset.Charset) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 19 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class IErlModelTest method findIncludeFromModule.

// IErlModule findIncludeFromModule(IErlModule module, String includeName,
// String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromModule() throws Exception {
    File externalIncludeFile = null;
    final IErlProject myProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = myProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final Collection<IPath> includeDirs = myProject.getProperties().getIncludeDirs();
    // directory as the module
    try {
        final String xxHrl = "xx.hrl";
        externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
        final String externalIncludePath = externalIncludeFile.getAbsolutePath();
        final IPath p = new Path(externalIncludePath).removeLastSegments(1);
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        newIncludeDirs.add(p);
        ((ErlProject) myProject).setIncludeDirs(newIncludeDirs);
        final IErlModule include = ErlideTestUtils.createInclude(myProject, "yy.hrl", "-define(Y, include).\n");
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
        final IErlModule includeInModuleDir = ErlideTestUtils.createModule(myProject, "ww.hrl", "-define(WW, x).\n");
        myProject.open(null);
        // when
        // looking for includes
        final String xx = "xx";
        final IErlModule x1 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x2 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x3 = model.findIncludeFromModule(module, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String yy = "yy";
        final IErlModule y1 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y2 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y3 = model.findIncludeFromModule(module, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String zz = "zz";
        final IErlModule z1 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z2 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z3 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        myProject.open(null);
        final IErlModule z4 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z5 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z6 = model.findIncludeFromModule(module, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String ww = "ww";
        final IErlModule w1 = model.findIncludeFromModule(module, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlElementLocator mymodel = ErlangEngine.getInstance().getModel();
        final IErlModule w2 = mymodel.findIncludeFromProject(myProject, ww, null, IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // scope should be respected
        assertNotNull(x1);
        assertEquals(xxHrl, x1.getName());
        assertNotNull(x2);
        assertEquals(xxHrl, x2.getName());
        assertNotNull(x3);
        assertEquals(xxHrl, x3.getName());
        assertEquals(include, y1);
        assertEquals(include, y2);
        assertEquals(include, y3);
        assertNull(z1);
        assertEquals(referencedInclude, z2);
        assertNull(z3);
        assertNull(z4);
        assertEquals(referencedInclude, z5);
        assertEquals(referencedInclude, z6);
        assertEquals(includeInModuleDir, w1);
        assertNull(w2);
    } finally {
        if (externalIncludeFile != null && externalIncludeFile.exists()) {
            externalIncludeFile.delete();
        }
        ((ErlProject) myProject).setIncludeDirs(includeDirs);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IProject(org.eclipse.core.resources.IProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 20 with IErlElementLocator

use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.

the class ModelUtilsTest method findExternalModuleFromPath.

@Test
public void findExternalModuleFromPath() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external2.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external2).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for it
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
        // then
        // we should find it
        assertThat(module).isNotNull();
        assertThat(externalFileName).isEqualTo(module.getName());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Aggregations

IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)33 IErlModule (org.erlide.engine.model.root.IErlModule)26 Test (org.junit.Test)17 IErlProject (org.erlide.engine.model.root.IErlProject)13 ErlProject (org.erlide.engine.internal.model.root.ErlProject)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IErlElement (org.erlide.engine.model.IErlElement)6 IProject (org.eclipse.core.resources.IProject)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 IFolder (org.eclipse.core.resources.IFolder)3 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)2 ArrayList (java.util.ArrayList)2 IMarker (org.eclipse.core.resources.IMarker)2 IResource (org.eclipse.core.resources.IResource)2