Search in sources :

Example 66 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 67 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 68 with IErlModule

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

the class ErlModelUtils method openFunctionInEditor.

/**
 * Activate editor and select erlang function
 */
public static boolean openFunctionInEditor(final ErlangFunction erlangFunction, final IEditorPart editor) throws CoreException {
    final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
    final IErlModule module = erlangEditor.getModule();
    if (module == null) {
        return false;
    }
    module.open(null);
    final IErlFunction function = module.findFunction(erlangFunction);
    if (function == null) {
        return false;
    }
    EditorUtility.revealInEditor(editor, function);
    return true;
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 69 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 70 with IErlModule

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

the class IErlImportTest method getImportModule.

// public String getImportModule();
@Test
public void getImportModule() throws Exception {
    final IErlModule module2 = ErlideTestUtils.createModule(project, "zz.erl", "-module(zz).\n" + "-import(lists, [foldl/3, reverse/1, reverse/2]).\n");
    module2.open(null);
    final List<IErlElement> imports = module2.getChildrenOfKind(ErlElementKind.IMPORT);
    final IErlImport import1 = (IErlImport) imports.get(0);
    final String importModule = import1.getImportModule();
    assertEquals("lists", importModule);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9