diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index 115d3885eb42..4965a0dbd23d 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -87,6 +87,20 @@
+
+
+
+
+
+
@@ -259,7 +273,6 @@
-
diff --git a/.idea/libraries/sass_stdlib.xml b/.idea/libraries/sass_stdlib.xml
new file mode 100644
index 000000000000..fa4e8b4d2cd9
--- /dev/null
+++ b/.idea/libraries/sass_stdlib.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platform/core-api/src/com/intellij/concurrency/AsyncFutureFactory.java b/platform/core-api/src/com/intellij/concurrency/AsyncFutureFactory.java
index 23b10de3d77e..68906607de20 100644
--- a/platform/core-api/src/com/intellij/concurrency/AsyncFutureFactory.java
+++ b/platform/core-api/src/com/intellij/concurrency/AsyncFutureFactory.java
@@ -37,6 +37,5 @@ public abstract class AsyncFutureFactory {
return result;
}
-
public abstract AsyncFutureResult createAsyncFutureResult();
}
diff --git a/platform/core-api/src/com/intellij/concurrency/DoWhile.java b/platform/core-api/src/com/intellij/concurrency/DoWhile.java
new file mode 100644
index 000000000000..15560b0c87ca
--- /dev/null
+++ b/platform/core-api/src/com/intellij/concurrency/DoWhile.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.concurrency;
+
+/**
+ * Author: dmitrylomov
+ */
+public abstract class DoWhile {
+ private AsyncFutureResult myResult;
+
+ public DoWhile() {
+ }
+
+ public AsyncFutureResult getResult() {
+ if (myResult == null) {
+ myResult = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+ body().addConsumer(SameThreadExecutor.INSTANCE, new MyConsumer());
+ }
+ return myResult;
+ }
+
+ protected abstract AsyncFuture body();
+ protected abstract boolean condition();
+
+ private class MyConsumer extends DefaultResultConsumer {
+ public MyConsumer() {
+ super(DoWhile.this.myResult);
+ }
+
+ @Override
+ public void onSuccess(Boolean value) {
+ if (!value.booleanValue()) {
+ myResult.set(false);
+ }
+ else {
+ if(!condition()) {
+ myResult.set(true);
+ }
+ else {
+ body().addConsumer(SameThreadExecutor.INSTANCE, this);
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/platform/core-api/src/com/intellij/concurrency/Iterate.java b/platform/core-api/src/com/intellij/concurrency/Iterate.java
new file mode 100644
index 000000000000..a6fe317cc647
--- /dev/null
+++ b/platform/core-api/src/com/intellij/concurrency/Iterate.java
@@ -0,0 +1,32 @@
+package com.intellij.concurrency;
+
+import java.util.Iterator;
+
+/**
+ * Author: dmitrylomov
+ */
+public abstract class Iterate extends DoWhile {
+ private final Iterator myIterator;
+ private boolean myIsDone;
+
+ public Iterate(Iterable iterable) {
+ myIterator = iterable.iterator();
+ myIsDone = false;
+ }
+
+ @Override
+ protected final AsyncFuture body() {
+ if (!myIterator.hasNext()) {
+ myIsDone = true;
+ return AsyncFutureFactory.wrap(true);
+ }
+ return process(myIterator.next());
+ }
+
+ protected abstract AsyncFuture process(T t);
+
+ @Override
+ protected boolean condition() {
+ return !myIsDone;
+ }
+}
diff --git a/platform/util/src/com/intellij/util/AbstractQuery.java b/platform/core-api/src/com/intellij/util/AbstractQuery.java
similarity index 71%
rename from platform/util/src/com/intellij/util/AbstractQuery.java
rename to platform/core-api/src/com/intellij/util/AbstractQuery.java
index c93da2840652..fc1df3744aad 100644
--- a/platform/util/src/com/intellij/util/AbstractQuery.java
+++ b/platform/core-api/src/com/intellij/util/AbstractQuery.java
@@ -15,6 +15,10 @@
*/
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
+import com.intellij.concurrency.AsyncFutureFactory;
+import com.intellij.concurrency.AsyncFutureResult;
+import com.intellij.concurrency.FinallyFuture;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -76,5 +80,27 @@ public abstract class AbstractQuery implements Query {
}
}
+ @Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ assertNotProcessing();
+ myIsProcessing = true;
+ return new FinallyFuture(processResultsAsync(consumer), new Runnable() {
+ @Override
+ public void run() {
+ myIsProcessing = false;
+ }
+ });
+ }
+
protected abstract boolean processResults(@NotNull Processor consumer);
+
+ protected AsyncFuture processResultsAsync(@NotNull Processor consumer) {
+ final AsyncFutureResult result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+ try {
+ result.set(processResults(consumer));
+ } catch (Throwable t) {
+ result.setException(t);
+ }
+ return result;
+ }
}
diff --git a/platform/util/src/com/intellij/util/ArrayQuery.java b/platform/core-api/src/com/intellij/util/ArrayQuery.java
similarity index 74%
rename from platform/util/src/com/intellij/util/ArrayQuery.java
rename to platform/core-api/src/com/intellij/util/ArrayQuery.java
index ef1502b92094..df8dcad7fd12 100644
--- a/platform/util/src/com/intellij/util/ArrayQuery.java
+++ b/platform/core-api/src/com/intellij/util/ArrayQuery.java
@@ -16,6 +16,9 @@
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
+import com.intellij.concurrency.AsyncFutureFactory;
+import com.intellij.concurrency.AsyncFutureResult;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -46,6 +49,17 @@ public class ArrayQuery implements Query {
return ContainerUtil.process(myArray, consumer);
}
+ public AsyncFuture forEachAsync(@NotNull final Processor consumer) {
+ final AsyncFutureResult result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+ try {
+ result.set(forEach(consumer));
+ } catch (Throwable t){
+ result.setException(t);
+ }
+ return result;
+ }
+
+
public T[] toArray(final T[] a) {
return myArray;
}
diff --git a/platform/util/src/com/intellij/util/CollectionQuery.java b/platform/core-api/src/com/intellij/util/CollectionQuery.java
similarity index 76%
rename from platform/util/src/com/intellij/util/CollectionQuery.java
rename to platform/core-api/src/com/intellij/util/CollectionQuery.java
index 09d5758a25b7..38db8f570707 100644
--- a/platform/util/src/com/intellij/util/CollectionQuery.java
+++ b/platform/core-api/src/com/intellij/util/CollectionQuery.java
@@ -16,6 +16,9 @@
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
+import com.intellij.concurrency.AsyncFutureFactory;
+import com.intellij.concurrency.AsyncFutureResult;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -49,6 +52,17 @@ public class CollectionQuery implements Query {
return ContainerUtil.process(myCollection, consumer);
}
+ @Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ AsyncFutureResult result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+ try {
+ result.set(forEach(consumer));
+ } catch (Throwable t) {
+ result.setException(t);
+ }
+ return result;
+ }
+
@Override
public T[] toArray(final T[] a) {
return findAll().toArray(a);
diff --git a/platform/util/src/com/intellij/util/EmptyQuery.java b/platform/core-api/src/com/intellij/util/EmptyQuery.java
similarity index 85%
rename from platform/util/src/com/intellij/util/EmptyQuery.java
rename to platform/core-api/src/com/intellij/util/EmptyQuery.java
index f28ce27dafbe..7d48cd9a43d7 100644
--- a/platform/util/src/com/intellij/util/EmptyQuery.java
+++ b/platform/core-api/src/com/intellij/util/EmptyQuery.java
@@ -15,6 +15,8 @@
*/
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
+import com.intellij.concurrency.AsyncFutureFactory;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -40,6 +42,11 @@ public class EmptyQuery implements Query {
return true;
}
+ @Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ return AsyncFutureFactory.wrap(true);
+ }
+
public R[] toArray(final R[] a) {
return findAll().toArray(a);
}
diff --git a/platform/util/src/com/intellij/util/ExecutorsQuery.java b/platform/core-api/src/com/intellij/util/ExecutorsQuery.java
similarity index 100%
rename from platform/util/src/com/intellij/util/ExecutorsQuery.java
rename to platform/core-api/src/com/intellij/util/ExecutorsQuery.java
diff --git a/platform/util/src/com/intellij/util/FilteredQuery.java b/platform/core-api/src/com/intellij/util/FilteredQuery.java
similarity index 75%
rename from platform/util/src/com/intellij/util/FilteredQuery.java
rename to platform/core-api/src/com/intellij/util/FilteredQuery.java
index 8bb540caeadf..108d4a1bc871 100644
--- a/platform/util/src/com/intellij/util/FilteredQuery.java
+++ b/platform/core-api/src/com/intellij/util/FilteredQuery.java
@@ -16,6 +16,7 @@
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
import com.intellij.openapi.util.Condition;
import org.jetbrains.annotations.NotNull;
@@ -43,17 +44,15 @@ public class FilteredQuery implements Query {
@Override
public boolean forEach(@NotNull final Processor consumer) {
- myOriginal.forEach(new Processor() {
- @Override
- public boolean process(final T t) {
- return !myFilter.value(t) || consumer.process(t);
- }
- });
-
+ myOriginal.forEach(new MyProcessor(consumer));
return true;
}
@Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ return myOriginal.forEachAsync(new MyProcessor(consumer));
+ }
+
@NotNull
public Collection findAll() {
CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor();
@@ -70,4 +69,19 @@ public class FilteredQuery implements Query {
public Iterator iterator() {
return findAll().iterator();
}
+
+ private class MyProcessor implements Processor {
+ private final Processor myConsumer;
+
+ public MyProcessor(Processor consumer) {
+ myConsumer = consumer;
+ }
+
+ public boolean process(final T t) {
+ if (!myFilter.value(t)) return true;
+ if (!myConsumer.process(t)) return false;
+
+ return true;
+ }
+ }
}
diff --git a/platform/util/src/com/intellij/util/InstanceofQuery.java b/platform/core-api/src/com/intellij/util/InstanceofQuery.java
similarity index 74%
rename from platform/util/src/com/intellij/util/InstanceofQuery.java
rename to platform/core-api/src/com/intellij/util/InstanceofQuery.java
index 72b9fe5b9c29..6d1e5042e1ba 100644
--- a/platform/util/src/com/intellij/util/InstanceofQuery.java
+++ b/platform/core-api/src/com/intellij/util/InstanceofQuery.java
@@ -15,6 +15,7 @@
*/
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -51,16 +52,12 @@ public class InstanceofQuery implements Query {
}
public boolean forEach(@NotNull final Processor consumer) {
- return myDelegate.forEach(new Processor() {
- public boolean process(Object o) {
- for (Class aClass : myClasses) {
- if (aClass.isInstance(o)) {
- return consumer.process(((T)o));
- }
- }
- return true;
- }
- });
+ return myDelegate.forEach(new MyProcessor(consumer));
+ }
+
+ @Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ return myDelegate.forEachAsync(new MyProcessor(consumer));
}
public T[] toArray(T[] a) {
@@ -71,4 +68,21 @@ public class InstanceofQuery implements Query {
public Iterator iterator() {
return new UnmodifiableIterator(findAll().iterator());
}
+
+ private class MyProcessor implements Processor {
+ private final Processor myConsumer;
+
+ public MyProcessor(Processor consumer) {
+ myConsumer = consumer;
+ }
+
+ public boolean process(T o) {
+ for (Class aClass : myClasses) {
+ if (aClass.isInstance(o)) {
+ return myConsumer.process(((T)o));
+ }
+ }
+ return true;
+ }
+ }
}
diff --git a/platform/util/src/com/intellij/util/LazyQuery.java b/platform/core-api/src/com/intellij/util/LazyQuery.java
similarity index 100%
rename from platform/util/src/com/intellij/util/LazyQuery.java
rename to platform/core-api/src/com/intellij/util/LazyQuery.java
diff --git a/platform/util/src/com/intellij/util/MergeQuery.java b/platform/core-api/src/com/intellij/util/MergeQuery.java
similarity index 66%
rename from platform/util/src/com/intellij/util/MergeQuery.java
rename to platform/core-api/src/com/intellij/util/MergeQuery.java
index 1f221aa3e10d..242e9ba51ae4 100644
--- a/platform/util/src/com/intellij/util/MergeQuery.java
+++ b/platform/core-api/src/com/intellij/util/MergeQuery.java
@@ -19,6 +19,7 @@
*/
package com.intellij.util;
+import com.intellij.concurrency.*;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -52,6 +53,27 @@ public class MergeQuery implements Query{
return processSubQuery(consumer, myQuery1) && processSubQuery(consumer, myQuery2);
}
+ public AsyncFuture forEachAsync(@NotNull final Processor consumer) {
+ final AsyncFutureResult result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+
+ final AsyncFuture fq = processSubQueryAsync(consumer, myQuery1);
+
+ fq.addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer(result) {
+ @Override
+ public void onSuccess(Boolean value) {
+ if (!value.booleanValue()) {
+ result.set(false);
+ }
+ else {
+ final AsyncFuture fq2 = processSubQueryAsync(consumer, myQuery2);
+ fq2.addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer(result));
+ }
+ }
+ });
+ return result;
+ }
+
+
private boolean processSubQuery(final Processor consumer, Query query1) {
return query1.forEach(new Processor() {
public boolean process(final V t) {
@@ -60,6 +82,14 @@ public class MergeQuery implements Query{
});
}
+ private AsyncFuture processSubQueryAsync(final Processor consumer, Query query1) {
+ return query1.forEachAsync(new Processor() {
+ public boolean process(final V t) {
+ return consumer.process(t);
+ }
+ });
+ }
+
public T[] toArray(final T[] a) {
final Collection results = findAll();
return results.toArray(a);
diff --git a/platform/util/src/com/intellij/util/Query.java b/platform/core-api/src/com/intellij/util/Query.java
similarity index 93%
rename from platform/util/src/com/intellij/util/Query.java
rename to platform/core-api/src/com/intellij/util/Query.java
index 01f084ebc317..555b285db12e 100644
--- a/platform/util/src/com/intellij/util/Query.java
+++ b/platform/core-api/src/com/intellij/util/Query.java
@@ -15,6 +15,7 @@
*/
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,5 +47,7 @@ public interface Query extends Iterable {
*/
boolean forEach(@NotNull Processor consumer);
+ AsyncFuture forEachAsync(@NotNull Processor consumer);
+
Result[] toArray(Result[] a);
}
diff --git a/platform/util/src/com/intellij/util/QueryExecutor.java b/platform/core-api/src/com/intellij/util/QueryExecutor.java
similarity index 100%
rename from platform/util/src/com/intellij/util/QueryExecutor.java
rename to platform/core-api/src/com/intellij/util/QueryExecutor.java
diff --git a/platform/util/src/com/intellij/util/QueryFactory.java b/platform/core-api/src/com/intellij/util/QueryFactory.java
similarity index 100%
rename from platform/util/src/com/intellij/util/QueryFactory.java
rename to platform/core-api/src/com/intellij/util/QueryFactory.java
diff --git a/platform/util/src/com/intellij/util/UniqueResultsQuery.java b/platform/core-api/src/com/intellij/util/UniqueResultsQuery.java
similarity index 72%
rename from platform/util/src/com/intellij/util/UniqueResultsQuery.java
rename to platform/core-api/src/com/intellij/util/UniqueResultsQuery.java
index e4d98866d809..44cce85e7027 100644
--- a/platform/util/src/com/intellij/util/UniqueResultsQuery.java
+++ b/platform/core-api/src/com/intellij/util/UniqueResultsQuery.java
@@ -16,6 +16,7 @@
package com.intellij.util;
+import com.intellij.concurrency.AsyncFuture;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
@@ -54,14 +55,20 @@ public class UniqueResultsQuery implements Query {
return process(consumer, Collections.synchronizedSet(new THashSet(myHashingStrategy)));
}
- private boolean process(final Processor consumer, final Set processedElements) {
- return myOriginal.forEach(new Processor() {
- public boolean process(final T t) {
- return !processedElements.add(myMapper.fun(t)) || consumer.process(t);
- }
- });
+ @Override
+ public AsyncFuture forEachAsync(@NotNull Processor consumer) {
+ return processAsync(consumer, Collections.synchronizedSet(new THashSet(myHashingStrategy)));
}
+ private boolean process(final Processor consumer, final Set processedElements) {
+ return myOriginal.forEach(new MyProcessor(processedElements, consumer));
+ }
+
+ private AsyncFuture processAsync(final Processor consumer, final Set processedElements) {
+ return myOriginal.forEachAsync(new MyProcessor(processedElements, consumer));
+ }
+
+
@NotNull
public Collection findAll() {
if (myMapper == Function.ID) {
@@ -84,4 +91,18 @@ public class UniqueResultsQuery implements Query {
public Iterator iterator() {
return findAll().iterator();
}
+
+ private class MyProcessor implements Processor {
+ private final Set myProcessedElements;
+ private final Processor myConsumer;
+
+ public MyProcessor(Set processedElements, Processor consumer) {
+ myProcessedElements = processedElements;
+ myConsumer = consumer;
+ }
+
+ public boolean process(final T t) {
+ return !myProcessedElements.add(myMapper.fun(t)) || myConsumer.process(t);
+ }
+ }
}
diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java
index 344de889eb9f..8abd1d29d9e0 100644
--- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java
+++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java
@@ -135,7 +135,12 @@ public class CoreApplicationEnvironment {
ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider();
- myApplication.registerService(JobLauncher.class, new JobLauncher() {
+ myApplication.registerService(JobLauncher.class, createJobLauncher());
+
+ }
+
+ protected JobLauncher createJobLauncher() {
+ return new JobLauncher() {
@Override
public boolean invokeConcurrentlyUnderProgress(@NotNull List things,
ProgressIndicator progress,
@@ -195,8 +200,7 @@ public class CoreApplicationEnvironment {
});
return null;
}
- });
-
+ };
}
protected ProgressIndicatorProvider createProgressIndicatorProvider() {
diff --git a/platform/indexing-api/src/com/intellij/psi/search/SearchRequestQuery.java b/platform/indexing-api/src/com/intellij/psi/search/SearchRequestQuery.java
index b9f31565a372..c51e984fba9b 100644
--- a/platform/indexing-api/src/com/intellij/psi/search/SearchRequestQuery.java
+++ b/platform/indexing-api/src/com/intellij/psi/search/SearchRequestQuery.java
@@ -1,5 +1,6 @@
package com.intellij.psi.search;
+import com.intellij.concurrency.AsyncFuture;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiReference;
import com.intellij.util.AbstractQuery;
@@ -18,6 +19,11 @@ public class SearchRequestQuery extends AbstractQuery {
myRequests = requests;
}
+ @Override
+ protected AsyncFuture processResultsAsync(@NotNull Processor consumer) {
+ return PsiSearchHelper.SERVICE.getInstance(myProject).processRequestsAsync(myRequests, consumer);
+ }
+
@Override
protected boolean processResults(@NotNull Processor consumer) {
return PsiSearchHelper.SERVICE.getInstance(myProject).processRequests(myRequests, consumer);
diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java
index 5147ccf3fa45..4714408b1b7c 100644
--- a/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java
+++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java
@@ -275,7 +275,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
});
final AsyncFutureResult ourResult = AsyncFutureFactory.getInstance().createAsyncFutureResult();
- completed.addConsumer(SameThreadExecutor.INSTANCE, new ResultConsumer() {
+ completed.addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer(ourResult) {
@Override
public void onSuccess(Boolean value) {
if (pceThrown.get())
@@ -510,42 +510,72 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
}
@Override
- public AsyncFuture processRequestsAsync(@NotNull SearchRequestCollector request, @NotNull Processor processor) {
- throw new UnsupportedOperationException("Not implemented");
+ public boolean processRequests(@NotNull SearchRequestCollector request, @NotNull Processor processor) {
+ return AsyncUtil.get(processRequestsAsync(request, processor));
}
@Override
- public boolean processRequests(@NotNull SearchRequestCollector collector, @NotNull Processor processor) {
- Map> collectors = ContainerUtil.newHashMap();
+ public AsyncFuture processRequestsAsync(@NotNull SearchRequestCollector collector, @NotNull Processor processor) {
+ final Map> collectors = ContainerUtil.newHashMap();
collectors.put(collector, processor);
appendCollectorsFromQueryRequests(collectors);
- ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator();
- do {
- MultiMap, RequestWithProcessor> globals = new MultiMap, RequestWithProcessor>();
- List> customs = ContainerUtil.newArrayList();
- Set locals = ContainerUtil.newLinkedHashSet();
- distributePrimitives(collectors, locals, globals, customs);
+ final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator();
+ final DoWhile doWhile = new DoWhile() {
- if (!processGlobalRequestsOptimized(globals, progress)) {
- return false;
+ @Override
+ protected AsyncFuture body() {
+ final AsyncFutureResult result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
+ MultiMap, RequestWithProcessor> globals = new MultiMap, RequestWithProcessor>();
+ final List> customs = ContainerUtil.newArrayList();
+ final Set locals = ContainerUtil.newLinkedHashSet();
+ distributePrimitives(collectors, locals, globals, customs);
+ processGlobalRequestsOptimizedAsync(globals, progress)
+ .addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer(result) {
+ @Override
+ public void onSuccess(Boolean value) {
+ if (!value.booleanValue()) {
+ result.set(value);
+ }
+ else {
+ final Iterate iterate = new Iterate(locals) {
+ @Override
+ protected AsyncFuture process(RequestWithProcessor local) {
+ return processSingleRequestAsync(local.request, local.refProcessor);
+ }
+ };
+
+ iterate.getResult()
+ .addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer(result) {
+ @Override
+ public void onSuccess(Boolean value) {
+ if (!value.booleanValue()) {
+ result.set(false);
+ return;
+ }
+ for (Computable custom : customs) {
+ if (!custom.compute()) {
+ result.set(false);
+ return;
+ }
+ }
+ result.set(true);
+ }
+ });
+ }
+ }
+ });
+ return result;
}
- for (RequestWithProcessor local : locals) {
- if (!processSingleRequest(local.request, local.refProcessor)) {
- return false;
- }
+ @Override
+ protected boolean condition() {
+ return appendCollectorsFromQueryRequests(collectors);
}
+ };
- for (Computable custom : customs) {
- if (!custom.compute()) {
- return false;
- }
- }
- } while (appendCollectorsFromQueryRequests(collectors));
-
- return true;
+ return doWhile.getResult();
}
private static boolean appendCollectorsFromQueryRequests(Map> collectors) {
@@ -563,11 +593,6 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
return changed;
}
- private boolean processGlobalRequestsOptimized(MultiMap, RequestWithProcessor> singles,
- final ProgressIndicator progress) {
- return AsyncUtil.get(processGlobalRequestsOptimizedAsync(singles, progress));
- }
-
private AsyncFuture processGlobalRequestsOptimizedAsync(MultiMap, RequestWithProcessor> singles,
final ProgressIndicator progress) {
if (singles.isEmpty()) {