diff --git a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java index bf7b89870d83..233bb4251508 100644 --- a/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java +++ b/java/java-indexing-api/src/com/intellij/psi/search/searches/ClassInheritorsSearch.java @@ -58,7 +58,7 @@ public class ClassInheritorsSearch extends ExtensibleQueryFactory() { diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java index 84ca70fbd3b9..bae61557780e 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AllClassesSearchExecutor.java @@ -66,7 +66,7 @@ public class AllClassesSearchExecutor implements QueryExecutor final ASTNode mirrorTreeElement = SourceTreeToPsiMap.psiElementToTree(mirror); //IMPORTANT: do not take lock too early - FileDocumentManager.getInstance().saveToString() can run write action... - final NonCancelableSection section = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + final NonCancelableSection section = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { setMirror((TreeElement)mirrorTreeElement); diff --git a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java index 31c7e5b0b1eb..70e1757acea5 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java +++ b/platform/core-api/src/com/intellij/openapi/progress/ProgressIndicatorProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.progress; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -33,8 +34,23 @@ public abstract class ProgressIndicatorProvider { protected abstract void doCheckCanceled() throws ProcessCanceledException; + @Nullable + public static ProgressIndicator getGlobalProgressIndicator() { + return ourInstance != null ? ourInstance.getProgressIndicator() : null; + } + public abstract NonCancelableSection startNonCancelableSection(); + @NotNull + public static NonCancelableSection startNonCancelableSectionIfSupported() { + return ourInstance != null ? ourInstance.startNonCancelableSection() : new NonCancelableSection() { + @Override + public void done() { + // do nothing + } + }; + } + public static boolean ourNeedToCheckCancel = false; public static void checkCanceled() throws ProcessCanceledException { // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds diff --git a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index 9602e9463bc2..f98f1ffe1737 100644 --- a/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -125,25 +125,7 @@ public class CoreApplicationEnvironment { registerApplicationExtensionPoint(ContentBasedFileSubstitutor.EP_NAME, ContentBasedFileSubstitutor.class); registerExtensionPoint(Extensions.getRootArea(), BinaryFileStubBuilders.EP_NAME, FileTypeExtensionPoint.class); - ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { - @Override - public ProgressIndicator getProgressIndicator() { - return new EmptyProgressIndicator(); - } - - @Override - protected void doCheckCanceled() throws ProcessCanceledException { - } - - @Override - public NonCancelableSection startNonCancelableSection() { - return new NonCancelableSection() { - @Override - public void done() { - } - }; - } - }; + ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider(); myApplication.registerService(JobLauncher.class, new JobLauncher() { @Override @@ -194,6 +176,28 @@ public class CoreApplicationEnvironment { } + protected ProgressIndicatorProvider createProgressIndicatorProvider() { + return new ProgressIndicatorProvider() { + @Override + public ProgressIndicator getProgressIndicator() { + return new EmptyProgressIndicator(); + } + + @Override + protected void doCheckCanceled() throws ProcessCanceledException { + } + + @Override + public NonCancelableSection startNonCancelableSection() { + return new NonCancelableSection() { + @Override + public void done() { + } + }; + } + }; + } + protected VirtualFileSystem createJarFileSystem() { return new CoreJarFileSystem(); } diff --git a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java index 06fbbd248ba0..aa3cb9a2c57a 100644 --- a/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java +++ b/platform/core-impl/src/com/intellij/extapi/psi/StubBasedPsiElementBase.java @@ -73,7 +73,7 @@ public class StubBasedPsiElementBase extends ASTDelegateP synchronized (file.getStubLock()) { node = myNode; if (node == null) { - NonCancelableSection criticalSection = ProgressIndicatorProvider.getInstance().startNonCancelableSection(); + NonCancelableSection criticalSection = ProgressIndicatorProvider.startNonCancelableSectionIfSupported(); try { if (!file.isValid()) throw new PsiInvalidElementAccessException(this); FileElement treeElement = file.getTreeElement(); diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index eb8e7e9aaf3a..36f78f255abe 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -1053,8 +1053,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder, AS final MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null); final MyComparator comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure); - final ProgressIndicatorProvider provider = ProgressIndicatorProvider.getInstance(); - final ProgressIndicator indicator = provider != null ? provider.getProgressIndicator() : null; + final ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator); return diffLog; } diff --git a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java index 8e14a3bb733d..5b7dff1258d3 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java @@ -230,8 +230,7 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements @Nullable protected static ProgressIndicator getProgressIndicator() { - final ProgressIndicatorProvider progressManager = ProgressIndicatorProvider.getInstance(); - return progressManager != null ? progressManager.getProgressIndicator() : null; + return ProgressIndicatorProvider.getGlobalProgressIndicator(); } protected double getPercentageOfComponentsLoaded() { 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 096e4958d37b..90f411c3b023 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 @@ -119,7 +119,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (text.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (searchScope instanceof GlobalSearchScope) { StringSearcher searcher = new StringSearcher(text, caseSensitively, true); @@ -344,7 +344,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { if (qName.length() == 0) { throw new IllegalArgumentException("Cannot search for elements with empty text"); } - final ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); int dotIndex = qName.lastIndexOf('.'); int dollarIndex = qName.lastIndexOf('$'); @@ -487,7 +487,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { appendCollectorsFromQueryRequests(collectors); - ProgressIndicator progress = ProgressIndicatorProvider.getInstance().getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); do { final MultiMap, RequestWithProcessor> globals = new MultiMap, RequestWithProcessor>(); final List> customs = ContainerUtil.newArrayList(); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 2884248ba360..62ea139d6561 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -199,7 +199,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project protected void loadModules(final ModuleModelImpl moduleModel) { if (myModulePaths != null && myModulePaths.size() > 0) { - final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getInstance().getProgressIndicator(); + final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progressIndicator != null) { progressIndicator.setText("Loading modules..."); progressIndicator.setText2(""); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 6844fc83e74d..d6b4c35c6824 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -634,8 +634,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { } protected void doInitialize(boolean reverseAllSets/* for testing order independence*/) { - final ProgressIndicatorProvider progressIndicatorProvider = ProgressIndicatorProvider.getInstance(); - ProgressIndicator progress = progressIndicatorProvider == null ? null : progressIndicatorProvider.getProgressIndicator(); + ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator(); if (progress == null) progress = new EmptyProgressIndicator(); progress.pushState();