Search in sources :

Example 1 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class ErlProjectTest method findFunctionInExternalFilesTest.

@Test
public void findFunctionInExternalFilesTest() throws Exception {
    // given
    // a module with calls to the lists module
    final IErlProject project = ErlProjectTest.projects[0];
    final IErlModule moduleE = ErlideTestUtils.createModule(project, "e.erl", "-module(e).\n-export([f/0]).\nf() ->\n    lists:reverse([1, 0]),\n    lists:reverse([1, 0], [2]).\n");
    final ScannerService scanner = moduleE.getScanner();
    try {
        moduleE.open(null);
        // when
        // looking for lists:reverse/2 and lists:reverse/1
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final OpenResult res = ErlangEngine.getInstance().getOpenService().open(moduleE.getScannerName(), 49, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(moduleE), project.getProperties().getExternalModules(), model.getPathVars());
        final IErlFunction function = ErlangEngine.getInstance().getModelFindService().findFunction(model, project, moduleE, res.getName(), res.getPath(), res.getFunction(), IErlElementLocator.Scope.PROJECT_ONLY);
        assertNotNull(function);
        final IErlElement module = model.findModuleFromProject(project, function.getModuleName(), res.getPath(), IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // the function should be returned and the module, in External Files
        assertNotNull(module);
        assertEquals(function.getParent(), module);
        assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(function), project);
    } finally {
        scanner.dispose();
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlElement(org.erlide.engine.model.IErlElement) IErlModel(org.erlide.engine.model.root.IErlModel) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 2 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class ErlTextHover method internalGetHoverInfo.

private static ErlangBrowserInformationControlInput internalGetHoverInfo(final AbstractErlangEditor editor, final ITextViewer textViewer, final IRegion hoverRegion) {
    if (editor == null) {
        return null;
    }
    final StringBuffer result = new StringBuffer();
    OpenResult element = null;
    // TODO our model is too coarse, here we need access to expressions
    final Collection<OtpErlangObject> fImports = ErlangEngine.getInstance().getModelUtilService().getImportsAsList(editor.getModule());
    final int offset = hoverRegion.getOffset();
    final int length = hoverRegion.getLength();
    final String debuggerVar = ErlTextHover.makeDebuggerVariableHover(textViewer, offset, length);
    if (!debuggerVar.isEmpty()) {
        result.append(debuggerVar);
    }
    final IErlProject erlProject = editor.getProject();
    String docPath = "";
    String anchor = "";
    try {
        if (erlProject == null) {
            return null;
        }
        final IOtpRpc backend = BackendCore.getBuildBackend(erlProject);
        if (backend == null) {
            return null;
        }
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final String externalModulesString = erlProject.getProperties().getExternalModules();
        final OtpErlangTuple t = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, offset, editor.getScannerName(), fImports, externalModulesString, model.getPathVars());
        if (Util.isOk(t)) {
            element = new OpenResult(t.elementAt(2));
            final String docStr = Util.stringValue(t.elementAt(1));
            result.append(docStr);
            if (t.arity() > 4) {
                docPath = Util.stringValue(t.elementAt(3));
                anchor = Util.stringValue(t.elementAt(4));
            }
        } else {
            element = new OpenResult(t);
            final Object found = new OpenUtils().findOpenResult(editor, editor.getModule(), erlProject, element, editor.getElementAt(offset, false));
            if (found instanceof IErlFunction) {
                final IErlFunction function = (IErlFunction) found;
                final String comment = DocumentationFormatter.getDocumentationString(function.getComments(), function.getTypespec());
                if (comment.isEmpty()) {
                    return null;
                }
                result.append(comment);
            } else if (found instanceof IErlPreprocessorDef) {
                final IErlPreprocessorDef preprocessorDef = (IErlPreprocessorDef) found;
                result.append(preprocessorDef.getExtra());
            }
        }
    } catch (final Exception e) {
        ErlLogger.warn(e);
        return null;
    }
    final String strResult = HoverUtil.getHTML(result);
    return new ErlangBrowserInformationControlInput(null, editor, element, strResult, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Point(org.eclipse.swt.graphics.Point) DebugException(org.eclipse.debug.core.DebugException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) ErlangBrowserInformationControlInput(org.erlide.ui.internal.information.ErlangBrowserInformationControlInput) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OpenUtils(org.erlide.ui.actions.OpenUtils) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 3 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class ErlideOpen method open.

@Override
@SuppressWarnings("boxing")
public OpenResult open(final String scannerName, final int offset, final List<OtpErlangObject> imports, final String externalModules, final OtpErlangList pathVars) throws RpcException {
    // ErlLogger.debug("open offset " + offset);
    final Collection<IPath> extra = SourcePathUtils.getExtraSourcePaths();
    final OtpErlangObject res = ideBackend.call(ErlideOpen.ERLIDE_OPEN, "open", "aix", scannerName, offset, mkContext(externalModules, null, pathVars, extra, imports));
    return new OpenResult(res);
}
Also used : IPath(org.eclipse.core.runtime.IPath) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OpenResult(org.erlide.engine.services.search.OpenResult)

Example 4 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class FindAction method run.

/*
     * Method declared on SelectionChangedAction.
     */
@Override
public void run(final ITextSelection selection) {
    try {
        final IErlModule module = fEditor.getModule();
        if (module == null) {
            return;
        }
        final ISelection sel = getSelection();
        final ITextSelection textSel = (ITextSelection) sel;
        final int offset = textSel.getOffset();
        final OpenResult res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
        ErlLogger.debug("find " + res);
        final ErlangSearchPattern ref = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, getLimitTo(), true);
        if (ref != null) {
            SearchUtil.runQuery(ref, getScope(), getScopeDescription(), getShell());
        }
    } catch (final Exception e) {
        handleException(e);
    }
}
Also used : OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ISelection(org.eclipse.jface.viewers.ISelection) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ITextSelection(org.eclipse.jface.text.ITextSelection) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class HandleEdocLinksLocationListener method changing.

@Override
public void changing(final LocationEvent event) {
    ErlangBrowserInformationControlInput input = null;
    if (control != null) {
        input = control.getInput();
    } else if (edocView != null) {
        input = edocView.getInput();
    }
    if (input != null) {
        final AbstractErlangEditor editor = input.getEditor();
        String moduleName = "";
        final Object inputElement = input.getInputElement();
        if (inputElement instanceof OpenResult) {
            final OpenResult or = (OpenResult) inputElement;
            moduleName = or.getName();
        }
        final ErlangFunctionCall functionCall = HoverUtil.eventToErlangFunctionCall(moduleName, event);
        if (functionCall != null) {
            final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(editor.getModule());
            if (project == null) {
                return;
            }
            final IOtpRpc backend = BackendCore.getBuildBackend(project);
            final OtpErlangTuple otpDoc = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, functionCall);
            if (Util.isOk(otpDoc)) {
                final String docStr = Util.stringValue(otpDoc.elementAt(1));
                final StringBuffer result = new StringBuffer(docStr);
                String docPath = "";
                String anchor = "";
                if (otpDoc.arity() > 4) {
                    docPath = Util.stringValue(otpDoc.elementAt(3));
                    anchor = Util.stringValue(otpDoc.elementAt(4));
                }
                if (result.length() > 0) {
                    final String html = HoverUtil.getHTML(result);
                    final Object element = new OpenResult(otpDoc.elementAt(2));
                    input = new ErlangBrowserInformationControlInput(input, editor, element, html, 20, HoverUtil.getDocumentationURL(docPath, anchor));
                }
            }
        }
    }
    if (input != null) {
        if (control != null) {
            if (control.hasDelayedInputChangeListener()) {
                control.notifyDelayedInputChange(input);
            } else {
                control.setInput(input);
            }
        } else if (edocView != null) {
            edocView.setInfo(input);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangFunctionCall(org.erlide.util.ErlangFunctionCall) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Aggregations

OpenResult (org.erlide.engine.services.search.OpenResult)7 IErlModule (org.erlide.engine.model.root.IErlModule)4 IErlProject (org.erlide.engine.model.root.IErlProject)4 IErlModel (org.erlide.engine.model.root.IErlModel)3 AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 CoreException (org.eclipse.core.runtime.CoreException)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IErlElement (org.erlide.engine.model.IErlElement)2 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 DebugException (org.eclipse.debug.core.DebugException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Point (org.eclipse.swt.graphics.Point)1 IEditorPart (org.eclipse.ui.IEditorPart)1