Search in sources :

Example 1 with ErlangExternalEditorInput

use of org.erlide.ui.editors.util.ErlangExternalEditorInput 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)

Aggregations

Charset (java.nio.charset.Charset)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 ErlangExternalEditorInput (org.erlide.ui.editors.util.ErlangExternalEditorInput)1