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;
}
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())));
}
}
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()]));
}
Aggregations