diff options
Diffstat (limited to 'platform/core-api/src/com/intellij/util')
5 files changed, 18 insertions, 52 deletions
diff --git a/platform/core-api/src/com/intellij/util/AbstractQuery.java b/platform/core-api/src/com/intellij/util/AbstractQuery.java index 1c29ef6437ac..219aae614140 100644 --- a/platform/core-api/src/com/intellij/util/AbstractQuery.java +++ b/platform/core-api/src/com/intellij/util/AbstractQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,9 +16,7 @@ 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 com.intellij.concurrency.AsyncUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -84,26 +82,13 @@ public abstract class AbstractQuery<Result> implements Query<Result> { @NotNull @Override public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<Result> consumer) { - assertNotProcessing(); - myIsProcessing = true; - return new FinallyFuture<Boolean>(processResultsAsync(consumer), new Runnable() { - @Override - public void run() { - myIsProcessing = false; - } - }); + return AsyncUtil.wrapBoolean(forEach(consumer)); } protected abstract boolean processResults(@NotNull Processor<Result> consumer); @NotNull protected AsyncFuture<Boolean> processResultsAsync(@NotNull Processor<Result> consumer) { - final AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult(); - try { - result.set(processResults(consumer)); - } catch (Throwable t) { - result.setException(t); - } - return result; + return AsyncUtil.wrapBoolean(processResults(consumer)); } } diff --git a/platform/core-api/src/com/intellij/util/ArrayQuery.java b/platform/core-api/src/com/intellij/util/ArrayQuery.java index abe2f1001fe0..1b7760146de6 100644 --- a/platform/core-api/src/com/intellij/util/ArrayQuery.java +++ b/platform/core-api/src/com/intellij/util/ArrayQuery.java @@ -17,8 +17,7 @@ package com.intellij.util; import com.intellij.concurrency.AsyncFuture; -import com.intellij.concurrency.AsyncFutureFactory; -import com.intellij.concurrency.AsyncFutureResult; +import com.intellij.concurrency.AsyncUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -55,13 +54,7 @@ public class ArrayQuery<T> implements Query<T> { @NotNull @Override public AsyncFuture<Boolean> forEachAsync(@NotNull final Processor<T> consumer) { - final AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult(); - try { - result.set(forEach(consumer)); - } catch (Throwable t){ - result.setException(t); - } - return result; + return AsyncUtil.wrapBoolean(forEach(consumer)); } diff --git a/platform/core-api/src/com/intellij/util/CollectionQuery.java b/platform/core-api/src/com/intellij/util/CollectionQuery.java index cd90ab55edd9..253182cef0c1 100644 --- a/platform/core-api/src/com/intellij/util/CollectionQuery.java +++ b/platform/core-api/src/com/intellij/util/CollectionQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -17,8 +17,7 @@ package com.intellij.util; import com.intellij.concurrency.AsyncFuture; -import com.intellij.concurrency.AsyncFutureFactory; -import com.intellij.concurrency.AsyncFutureResult; +import com.intellij.concurrency.AsyncUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -55,13 +54,7 @@ public class CollectionQuery<T> implements Query<T> { @NotNull @Override public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<T> consumer) { - AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult(); - try { - result.set(forEach(consumer)); - } catch (Throwable t) { - result.setException(t); - } - return result; + return AsyncUtil.wrapBoolean(forEach(consumer)); } @NotNull diff --git a/platform/core-api/src/com/intellij/util/EmptyQuery.java b/platform/core-api/src/com/intellij/util/EmptyQuery.java index 465100505450..18a32a5a94b4 100644 --- a/platform/core-api/src/com/intellij/util/EmptyQuery.java +++ b/platform/core-api/src/com/intellij/util/EmptyQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,7 +16,7 @@ package com.intellij.util; import com.intellij.concurrency.AsyncFuture; -import com.intellij.concurrency.AsyncFutureFactory; +import com.intellij.concurrency.AsyncUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -48,7 +48,7 @@ public class EmptyQuery<R> implements Query<R> { @NotNull @Override public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<R> consumer) { - return AsyncFutureFactory.wrap(true); + return AsyncUtil.wrapBoolean(true); } @NotNull diff --git a/platform/core-api/src/com/intellij/util/MergeQuery.java b/platform/core-api/src/com/intellij/util/MergeQuery.java index 699659b93055..35d122639cd3 100644 --- a/platform/core-api/src/com/intellij/util/MergeQuery.java +++ b/platform/core-api/src/com/intellij/util/MergeQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -66,13 +66,13 @@ public class MergeQuery<T> implements Query<T>{ fq.addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer<Boolean>(result) { @Override public void onSuccess(Boolean value) { - if (!value.booleanValue()) { - result.set(false); - } - else { + if (value.booleanValue()) { final AsyncFuture<Boolean> fq2 = processSubQueryAsync(consumer, myQuery2); fq2.addConsumer(SameThreadExecutor.INSTANCE, new DefaultResultConsumer<Boolean>(result)); } + else { + result.set(false); + } } }); return result; @@ -85,12 +85,7 @@ public class MergeQuery<T> implements Query<T>{ } private <V extends T> AsyncFuture<Boolean> processSubQueryAsync(@NotNull final Processor<T> consumer, @NotNull Query<V> query1) { - return query1.forEachAsync(new Processor<V>() { - @Override - public boolean process(final V t) { - return consumer.process(t); - } - }); + return query1.forEachAsync((Processor<V>)consumer); } @NotNull |