Search in sources :

Example 1 with ModuleLineFunctionArityRef

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

the class ErlSearchQuery method run.

@Override
public IStatus run(final IProgressMonitor monitor) throws OperationCanceledException {
    final Object locker = new Object();
    final IRpcResultCallback callback = new IRpcResultCallback() {

        @Override
        public void start(final OtpErlangObject msg) {
            if (fSearchResult != null) {
                fSearchResult.removeAll();
            }
            final OtpErlangLong progressMaxL = (OtpErlangLong) msg;
            int progressMax;
            try {
                progressMax = progressMaxL.intValue();
            } catch (final OtpErlangRangeException e) {
                progressMax = 10;
            }
            monitor.beginTask("Searching", progressMax);
        }

        @Override
        public void stop(final OtpErlangObject msg) {
            monitor.done();
            stopped = true;
            synchronized (locker) {
                locker.notifyAll();
            }
        }

        @Override
        public void progress(final OtpErlangObject msg) {
            final OtpErlangTuple t = (OtpErlangTuple) msg;
            final OtpErlangPid backgroundSearchPid = (OtpErlangPid) t.elementAt(0);
            final OtpErlangLong progressL = (OtpErlangLong) t.elementAt(1);
            final OtpErlangObject resultO = t.elementAt(2);
            int progress = 1;
            try {
                progress = progressL.intValue();
                final List<ModuleLineFunctionArityRef> result = Lists.newArrayList();
                SearchUtil.addSearchResult(result, resultO);
                addMatches(result);
            } catch (final OtpErlangRangeException e) {
            }
            monitor.worked(progress);
            if (monitor.isCanceled()) {
                try {
                    ErlangEngine.getInstance().getSearchServerService().cancelSearch(backgroundSearchPid);
                } catch (final RpcException e) {
                }
            }
        }
    };
    try {
        final ErlSearchScope reducedScope = pattern.reduceScope(scope);
        ErlangEngine.getInstance().getSearchServerService().startFindRefs(pattern, reducedScope, ErlangEngine.getInstance().getStateDir(), callback, false);
    } catch (final RpcException e) {
        return new Status(IStatus.ERROR, ErlideUIPlugin.PLUGIN_ID, "Search error", e);
    }
    while (!stopped) {
        synchronized (locker) {
            try {
                if (!stopped) {
                    locker.wait();
                }
            } catch (final InterruptedException e) {
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IRpcResultCallback(org.erlide.runtime.rpc.IRpcResultCallback) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 2 with ModuleLineFunctionArityRef

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

the class SearchUtil method addSearchResult.

public static void addSearchResult(final List<ModuleLineFunctionArityRef> result, final OtpErlangObject r) throws OtpErlangRangeException {
    final OtpErlangTuple t = (OtpErlangTuple) r;
    final OtpErlangList l = (OtpErlangList) t.elementAt(1);
    for (final OtpErlangObject i : l) {
        /*
             * find_data([#ref{function=F, arity=A, clause=C, data=D, offset=O,
             * length=L, sub_clause=S} | Rest], Data, M, Acc) -> case D of Data
             * -> find_data(Rest, Data, M, [{M, F, A, C, S, O, L} | Acc]); _ ->
             * find_data(Rest, Data, M, Acc) end.
             */
        final OtpErlangTuple modLineT = (OtpErlangTuple) i;
        final String modName = Util.stringValue(modLineT.elementAt(0));
        final OtpErlangObject nameO = modLineT.elementAt(1);
        final OtpErlangLong arityL = (OtpErlangLong) modLineT.elementAt(2);
        final int arity = arityL.intValue();
        final String clauseHead = Util.stringValue(modLineT.elementAt(3));
        final OtpErlangAtom subClause = (OtpErlangAtom) modLineT.elementAt(4);
        final OtpErlangLong offsetL = (OtpErlangLong) modLineT.elementAt(5);
        final OtpErlangLong lengthL = (OtpErlangLong) modLineT.elementAt(6);
        final OtpErlangAtom isDef = (OtpErlangAtom) modLineT.elementAt(7);
        String name;
        if (nameO instanceof OtpErlangAtom) {
            final OtpErlangAtom nameA = (OtpErlangAtom) nameO;
            name = nameA.atomValue();
        } else {
            name = Util.stringValue(nameO);
        }
        result.add(new ModuleLineFunctionArityRef(modName, offsetL.intValue(), lengthL.intValue(), name, arity, clauseHead, Boolean.parseBoolean(subClause.atomValue()), Boolean.parseBoolean(isDef.atomValue())));
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 3 with ModuleLineFunctionArityRef

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

the class ErlSearchQuery method addMatches.

private void addMatches(final List<ModuleLineFunctionArityRef> chunk) {
    final List<Match> l = Lists.newArrayListWithCapacity(chunk.size());
    final List<ErlangSearchElement> resultAdded = Lists.newArrayListWithCapacity(chunk.size());
    for (final ModuleLineFunctionArityRef ref : chunk) {
        final Match m = SearchUtil.createMatch(ref, pathToModuleMap);
        l.add(m);
        resultAdded.add((ErlangSearchElement) m.getElement());
    }
    fSearchResult = (ErlangSearchResult) getSearchResult();
    final List<ErlangSearchElement> result = fSearchResult.getResult();
    result.addAll(resultAdded);
    fSearchResult.setResult(result);
    fSearchResult.addMatches(l.toArray(new Match[l.size()]));
}
Also used : ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) Match(org.eclipse.search.ui.text.Match)

Aggregations

ModuleLineFunctionArityRef (org.erlide.engine.services.search.ModuleLineFunctionArityRef)3 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Match (org.eclipse.search.ui.text.Match)1 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)1 IRpcResultCallback (org.erlide.runtime.rpc.IRpcResultCallback)1 RpcException (org.erlide.runtime.rpc.RpcException)1