diff options
Diffstat (limited to 'platform/core-api/src/com/intellij')
17 files changed, 97 insertions, 169 deletions
diff --git a/platform/core-api/src/com/intellij/concurrency/AsyncUtil.java b/platform/core-api/src/com/intellij/concurrency/AsyncUtil.java index 93c7573c0381..72c0a85aac72 100644 --- a/platform/core-api/src/com/intellij/concurrency/AsyncUtil.java +++ b/platform/core-api/src/com/intellij/concurrency/AsyncUtil.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. @@ -18,12 +18,17 @@ package com.intellij.concurrency; import org.jetbrains.annotations.NotNull; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; /** * Author: dmitrylomov */ public class AsyncUtil { + private static final AsyncFuture<Boolean> TRUE = createConst(true); + private static final AsyncFuture<Boolean> FALSE = createConst(false); + public static <V> V get(@NotNull Future<V> result) { try { return result.get(); @@ -41,4 +46,43 @@ public class AsyncUtil { } } } + + private static AsyncFuture<Boolean> createConst(final boolean result) { + return new AsyncFuture<Boolean>() { + @Override + public void addConsumer(@NotNull Executor executor, @NotNull ResultConsumer<Boolean> consumer) { + consumer.onSuccess(result); + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public Boolean get() { + return result; + } + + @Override + public Boolean get(long timeout, @NotNull TimeUnit unit) { + return result; + } + }; + } + + @NotNull + public static AsyncFuture<Boolean> wrapBoolean(boolean result) { + return result ? TRUE : FALSE; + } } diff --git a/platform/core-api/src/com/intellij/concurrency/DefaultResultConsumer.java b/platform/core-api/src/com/intellij/concurrency/DefaultResultConsumer.java index 7230cd469e13..0e54993fe84b 100644 --- a/platform/core-api/src/com/intellij/concurrency/DefaultResultConsumer.java +++ b/platform/core-api/src/com/intellij/concurrency/DefaultResultConsumer.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. @@ -15,13 +15,15 @@ */ package com.intellij.concurrency; +import org.jetbrains.annotations.NotNull; + /** * Author: dmitrylomov */ public class DefaultResultConsumer<V> implements ResultConsumer<V> { private final AsyncFutureResult<V> myResult; - public DefaultResultConsumer(AsyncFutureResult<V> result) { + public DefaultResultConsumer(@NotNull AsyncFutureResult<V> result) { myResult = result; } @@ -31,7 +33,7 @@ public class DefaultResultConsumer<V> implements ResultConsumer<V> { } @Override - public void onFailure(Throwable t) { + public void onFailure(@NotNull Throwable t) { myResult.setException(t); } } diff --git a/platform/core-api/src/com/intellij/concurrency/DoWhile.java b/platform/core-api/src/com/intellij/concurrency/DoWhile.java deleted file mode 100644 index b77e3258c984..000000000000 --- a/platform/core-api/src/com/intellij/concurrency/DoWhile.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2000-2013 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; - -import org.jetbrains.annotations.NotNull; - -/** - * Author: dmitrylomov - */ -public abstract class DoWhile { - private final AsyncFutureResult<Boolean> myResult = AsyncFutureFactory.getInstance().createAsyncFutureResult(); - private final SameThreadExecutorWithTrampoline myExecutor = new SameThreadExecutorWithTrampoline(); - - @NotNull - public AsyncFutureResult<Boolean> getResult() { - body().addConsumer(myExecutor, new MyConsumer()); - return myResult; - } - - @NotNull - protected abstract AsyncFuture<Boolean> body(); - protected abstract boolean condition(); - - private class MyConsumer extends DefaultResultConsumer<Boolean> { - 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(myExecutor, this); - } - } - } - } - - -} diff --git a/platform/core-api/src/com/intellij/concurrency/Iterate.java b/platform/core-api/src/com/intellij/concurrency/Iterate.java deleted file mode 100644 index e158999f4da5..000000000000 --- a/platform/core-api/src/com/intellij/concurrency/Iterate.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.intellij.concurrency; - -import org.jetbrains.annotations.NotNull; - -import java.util.Iterator; - -/** - * Author: dmitrylomov - */ -public abstract class Iterate<T> extends DoWhile { - private final Iterator<T> myIterator; - private boolean myIsDone; - - public Iterate(@NotNull Iterable<T> iterable) { - myIterator = iterable.iterator(); - myIsDone = false; - } - - @NotNull - @Override - protected final AsyncFuture<Boolean> body() { - if (!myIterator.hasNext()) { - myIsDone = true; - return AsyncFutureFactory.wrap(true); - } - return process(myIterator.next()); - } - - @NotNull - protected abstract AsyncFuture<Boolean> process(T t); - - @Override - protected boolean condition() { - return !myIsDone; - } -} diff --git a/platform/core-api/src/com/intellij/concurrency/ResultConsumer.java b/platform/core-api/src/com/intellij/concurrency/ResultConsumer.java index 80618f0b9c79..409d5a9439a4 100644 --- a/platform/core-api/src/com/intellij/concurrency/ResultConsumer.java +++ b/platform/core-api/src/com/intellij/concurrency/ResultConsumer.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. @@ -15,10 +15,12 @@ */ package com.intellij.concurrency; +import org.jetbrains.annotations.NotNull; + /** * Author: dmitrylomov */ public interface ResultConsumer<V> { void onSuccess(V value); - void onFailure(Throwable t); + void onFailure(@NotNull Throwable t); } diff --git a/platform/core-api/src/com/intellij/lang/folding/CustomFoldingBuilder.java b/platform/core-api/src/com/intellij/lang/folding/CustomFoldingBuilder.java index f43c1c9b55ae..ab03627d7d6a 100644 --- a/platform/core-api/src/com/intellij/lang/folding/CustomFoldingBuilder.java +++ b/platform/core-api/src/com/intellij/lang/folding/CustomFoldingBuilder.java @@ -45,7 +45,9 @@ public abstract class CustomFoldingBuilder extends FoldingBuilderEx implements P if (CustomFoldingProvider.getAllProviders().length > 0) { myDefaultProvider = null; ASTNode rootNode = root.getNode(); - addCustomFoldingRegionsRecursively(new FoldingStack(rootNode), rootNode, descriptors, 0); + if (rootNode != null) { + addCustomFoldingRegionsRecursively(new FoldingStack(rootNode), rootNode, descriptors, 0); + } } buildLanguageFoldRegions(descriptors, root, document, quick); return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); diff --git a/platform/core-api/src/com/intellij/openapi/components/RoamingType.java b/platform/core-api/src/com/intellij/openapi/components/RoamingType.java index 0cbf78053953..ba4b6d8b36e6 100644 --- a/platform/core-api/src/com/intellij/openapi/components/RoamingType.java +++ b/platform/core-api/src/com/intellij/openapi/components/RoamingType.java @@ -16,5 +16,12 @@ package com.intellij.openapi.components; public enum RoamingType { - DISABLED, PER_PLATFORM, GLOBAL, PER_USER + DISABLED, + PER_PLATFORM, + @Deprecated + /** + * Use {@link #PER_USER} instead + */ + GLOBAL, + PER_USER } diff --git a/platform/core-api/src/com/intellij/openapi/options/SchemeProcessor.java b/platform/core-api/src/com/intellij/openapi/options/SchemeProcessor.java index 94ec194b9f89..5acdbe7cacf6 100644 --- a/platform/core-api/src/com/intellij/openapi/options/SchemeProcessor.java +++ b/platform/core-api/src/com/intellij/openapi/options/SchemeProcessor.java @@ -19,18 +19,22 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import org.jdom.Document; import org.jdom.JDOMException; +import org.jdom.Parent; import org.jetbrains.annotations.NotNull; import java.io.IOException; public interface SchemeProcessor<T extends ExternalizableScheme> { T readScheme(@NotNull Document schemeContent) throws InvalidDataException, IOException, JDOMException; - Document writeScheme(@NotNull T scheme) throws WriteExternalException; + + Parent writeScheme(@NotNull T scheme) throws WriteExternalException; boolean shouldBeSaved(@NotNull T scheme); + void initScheme(@NotNull T scheme); void onSchemeAdded(@NotNull T scheme); + void onSchemeDeleted(@NotNull T scheme); void onCurrentSchemeChanged(final Scheme oldCurrentScheme); diff --git a/platform/core-api/src/com/intellij/openapi/options/SchemesManagerFactory.java b/platform/core-api/src/com/intellij/openapi/options/SchemesManagerFactory.java index a0c0ee7dad62..abd37269985f 100644 --- a/platform/core-api/src/com/intellij/openapi/options/SchemesManagerFactory.java +++ b/platform/core-api/src/com/intellij/openapi/options/SchemesManagerFactory.java @@ -25,9 +25,8 @@ public abstract class SchemesManagerFactory { public static final ExtensionPointName<ServiceBean> SCHEME_OWNER = ExtensionPointName.create("com.intellij.schemeOwner"); public abstract <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(@NotNull String fileSpec, - @NotNull SchemeProcessor<E> processor, - @NotNull RoamingType roamingType); - + @NotNull SchemeProcessor<E> processor, @NotNull RoamingType roamingType); + @NotNull public static SchemesManagerFactory getInstance() { return ServiceManager.getService(SchemesManagerFactory.class); } diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressManager.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressManager.java index 3f0601ba951b..377bcc520e27 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/ProgressManager.java +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressManager.java @@ -34,6 +34,7 @@ public abstract class ProgressManager extends ProgressIndicatorProvider { private static final ProgressManager ourInstance = ServiceManager.getService(ProgressManager.class); } + @NotNull public static ProgressManager getInstance() { return ProgressManagerHolder.ourInstance; } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/ex/http/HttpFileSystem.java b/platform/core-api/src/com/intellij/openapi/vfs/ex/http/HttpFileSystem.java index a42441fe49de..af6c670ab22a 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/ex/http/HttpFileSystem.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/ex/http/HttpFileSystem.java @@ -23,13 +23,6 @@ import com.intellij.util.io.URLUtil; import org.jetbrains.annotations.NotNull; public abstract class HttpFileSystem extends DeprecatedVirtualFileSystem { - @Deprecated - @SuppressWarnings("UnusedDeclaration") - /** - * @deprecated use {@link com.intellij.util.io.URLUtil#HTTP_PROTOCOL} - */ - public static final String PROTOCOL = URLUtil.HTTP_PROTOCOL; - public static HttpFileSystem getInstance() { return (HttpFileSystem)VirtualFileManager.getInstance().getFileSystem(URLUtil.HTTP_PROTOCOL); } @@ -43,4 +36,4 @@ public abstract class HttpFileSystem extends DeprecatedVirtualFileSystem { public abstract void removeFileListener(@NotNull HttpVirtualFileListener listener); public abstract VirtualFile createChild(@NotNull VirtualFile parent, @NotNull String name, boolean isDirectory); -}
\ No newline at end of file +} diff --git a/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java b/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java index a8a82bed411a..4c7c12d79906 100644 --- a/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java +++ b/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.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. @@ -42,9 +42,12 @@ public abstract class CachedValuesManager { * @param trackValue if value tracking required. T should be trackable in this case. * @return new CachedValue instance. */ + @NotNull public abstract <T> CachedValue<T> createCachedValue(@NotNull CachedValueProvider<T> provider, boolean trackValue); + @NotNull public abstract <T,P> ParameterizedCachedValue<T,P> createParameterizedCachedValue(@NotNull ParameterizedCachedValueProvider<T,P> provider, boolean trackValue); + @NotNull public <T> CachedValue<T> createCachedValue(@NotNull CachedValueProvider<T> provider) { return createCachedValue(provider, true); } @@ -54,7 +57,6 @@ public abstract class CachedValuesManager { @NotNull ParameterizedCachedValueProvider<T, P> provider, boolean trackValue, P parameter) { - ParameterizedCachedValue<T,P> value; if (dataHolder instanceof UserDataHolderEx) { @@ -100,6 +102,7 @@ public abstract class CachedValuesManager { } private final ConcurrentMap<String, Key<CachedValue>> keyForProvider = new ConcurrentHashMap<String, Key<CachedValue>>(); + @NotNull public <T> Key<CachedValue<T>> getKeyForClass(@NotNull Class<?> providerClass) { String name = providerClass.getName(); assert name != null : providerClass + " doesn't have a name; can't be used for cache value provider"; 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 |