Search in sources :

Example 1 with IOtpRpc

use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.

the class DialyzerUtils method doDialyze.

public static void doDialyze(final IProgressMonitor monitor, final Set<IErlModule> modules, final Set<IErlProject> projects, final IBackend backend) throws InvocationTargetException, DialyzerErrorException {
    if (backend == null) {
        ErlLogger.warn("Trying to dialyze with null backend");
        return;
    }
    try {
        for (final IErlModule module : modules) {
            DialyzerMarkerUtils.removeDialyzerMarkersFor(module.getResource());
        }
        // TODO handle preferences from multiple projects
        final DialyzerPreferences prefs = DialyzerPreferences.get(null);
        final Collection<String> pltPaths = prefs.getPltPaths();
        // prefs.getFromSource();
        final boolean fromSource = false;
        // prefs.getNoCheckPLT();
        final boolean noCheckPLT = true;
        final List<String> files = Lists.newArrayList();
        final List<IPath> includeDirs = Lists.newArrayList();
        final List<String> names = Lists.newArrayList();
        DialyzerUtils.collectFilesAndIncludeDirs(modules, projects, files, names, includeDirs, fromSource);
        if (names.isEmpty()) {
            return;
        }
        final String fileNames = names.size() + " modules [" + DialyzerUtils.getFileNames(names) + "]";
        monitor.subTask(fileNames);
        ErlLogger.trace("dialyzer", "run %s", fileNames);
        final IOtpRpc b = backend.getOtpRpc();
        final RpcFuture future = ErlideDialyze.dialyze(b, files, pltPaths, includeDirs, fromSource, noCheckPLT);
        while (!future.isDone()) {
            // check cancellation
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            // check backend down
            if (!backend.isRunning()) {
                throw new BackendException("Dialyzer: backend " + backend.getName() + " is down");
            }
            OtpErlangObject r = null;
            try {
                r = future.checkedGet(500, TimeUnit.MILLISECONDS);
            } catch (final TimeoutException e) {
            } catch (final RpcTimeoutException e) {
            }
            if (r != null) {
                DialyzerUtils.processResult(b, r);
            }
        }
    } catch (final RpcException e) {
        throw new InvocationTargetException(e);
    } catch (final BackendException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) BackendException(org.erlide.backend.api.BackendException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) IErlModule(org.erlide.engine.model.root.IErlModule) RpcFuture(org.erlide.runtime.rpc.RpcFuture) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with IOtpRpc

use of org.erlide.runtime.rpc.IOtpRpc 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 IOtpRpc

use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.

the class Activator method initWrangler.

/**
 * Loads the necessary *.ebin files to the Erlang node for the plug-in.
 *
 * @throws CoreException
 *             detailed exception about the loading process errors
 */
private void initWrangler() throws CoreException {
    final IOtpRpc mb = getBackend();
    RpcResult res = mb.call_noexception("wrangler_refacs", "init_eclipse", "", new Object[0]);
    ErlLogger.debug("Wrangler app started:\n" + res);
    res = mb.call_noexception("wrangler_error_logger", "init", "x", new OtpErlangList());
    ErlLogger.debug("Error logger started:" + res);
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcResult(org.erlide.runtime.rpc.RpcResult) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 4 with IOtpRpc

use of org.erlide.runtime.rpc.IOtpRpc 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)

Example 5 with IOtpRpc

use of org.erlide.runtime.rpc.IOtpRpc in project erlide_eclipse by erlang.

the class ProcessHelper method getProcsOnTracedNodes.

/**
 * Returns list of processes on all traced nodes.
 *
 * @return list of processes
 */
public static TracedProcess[] getProcsOnTracedNodes() {
    try {
        final IOtpRpc backend = TraceBackend.getInstance().getBackend(true).getOtpRpc();
        final List<OtpErlangAtom> nodeAtoms = new ArrayList<>();
        for (final Object o : TraceBackend.getInstance().getTracedNodesArray()) {
            final TracedNode tracedNode = (TracedNode) o;
            if (tracedNode.isEnabled()) {
                nodeAtoms.add(new OtpErlangAtom(tracedNode.getNodeName()));
            }
        }
        final OtpErlangList nodesList = new OtpErlangList(nodeAtoms.toArray(new OtpErlangAtom[nodeAtoms.size()]));
        final OtpErlangList procList = (OtpErlangList) backend.call(ProcessHelper.MODULE_NAME, ProcessHelper.FUNCTION_NAME, "x", nodesList);
        final TracedProcess[] processes = new TracedProcess[procList.arity()];
        for (int i = 0; i < procList.arity(); i++) {
            final OtpErlangTuple tuple = (OtpErlangTuple) procList.elementAt(i);
            processes[i] = new TracedProcess(tuple);
        }
        return processes;
    } catch (final RpcException e) {
        ErlLogger.error(e);
    }
    return null;
}
Also used : TracedProcess(org.erlide.tracing.core.mvc.model.TracedProcess) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Aggregations

IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)16 IErlProject (org.erlide.engine.model.root.IErlProject)6 RpcException (org.erlide.runtime.rpc.RpcException)6 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)4 Test (org.junit.Test)4 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)3 IErlModule (org.erlide.engine.model.root.IErlModule)3 DebugException (org.eclipse.debug.core.DebugException)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 OpenResult (org.erlide.engine.services.search.OpenResult)2 AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1 IProject (org.eclipse.core.resources.IProject)1