From ec2db11c209313a1ca65922e0e102e464fe0bd2e Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 20 Jul 2016 12:23:04 +0200 Subject: [PATCH] add runAsync --- .../jdk/java/util/concurrent/annotations.xml | 6 ++++++ .../InspectionProfileEntry.java | 3 +-- .../ex/InspectionProfileImpl.java | 6 ++---- .../intellij/codeInspection/ex/ToolsImpl.java | 7 ++----- .../BaseInspectionProfileManager.kt | 4 +--- .../ProjectInspectionProfileManager.kt | 3 ++- .../intellij/concurrency/completableFuture.kt | 21 +++++++++++++++++++ .../intellij/openapi/application/actions.kt | 2 +- 8 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 lib/annotations/jdk/java/util/concurrent/annotations.xml create mode 100644 platform/core-impl/src/com/intellij/concurrency/completableFuture.kt diff --git a/lib/annotations/jdk/java/util/concurrent/annotations.xml b/lib/annotations/jdk/java/util/concurrent/annotations.xml new file mode 100644 index 000000000000..b0e4e822ed3f --- /dev/null +++ b/lib/annotations/jdk/java/util/concurrent/annotations.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java index 1a545090af9b..9fd1730cc08e 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java @@ -20,7 +20,6 @@ import com.intellij.codeInspection.ex.InspectionElementsMerger; import com.intellij.lang.Language; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; @@ -190,7 +189,7 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool { } return elementLanguageSuppressor != null ? Collections.singleton(elementLanguageSuppressor) - : Collections.emptySet(); + : Collections.emptySet(); } public void cleanup(@NotNull Project project) { diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index d97c0cebcbda..df53df032e8a 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -723,11 +723,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, return; } - for (final ToolsImpl toolList : myTools.values()) { + for (ToolsImpl toolList : myTools.values()) { if (toolList.isEnabled()) { - for (InspectionToolWrapper toolWrapper : toolList.getAllTools()) { - toolWrapper.cleanup(project); - } + toolList.cleanupTools(project); } } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java index c50406bd719d..63f4d6b5f348 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java @@ -130,13 +130,10 @@ public class ToolsImpl implements Tools { return myShortName; } - @NotNull - public List getAllTools() { - List result = new ArrayList<>(); + public void cleanupTools(@NotNull Project project) { for (ScopeToolState state : getTools()) { - result.add(state.getTool()); + state.getTool().cleanup(project); } - return result; } public void writeExternal(@NotNull Element inspectionElement) throws WriteExternalException { diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt index 121d09829841..bd1c3edf31f1 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt @@ -58,9 +58,7 @@ abstract class BaseInspectionProfileManager(messageBus: MessageBus) : Inspectio internal fun cleanupSchemes(project: Project) { for (profile in schemeManager.allSchemes) { - if ((profile as InspectionProfileImpl).wasInitialized()) { - profile.cleanup(project) - } + profile.cleanup(project) } } diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt index 6019e1ece67e..7566344f916d 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt @@ -18,6 +18,7 @@ package com.intellij.profile.codeInspection import com.intellij.codeInspection.InspectionProfile import com.intellij.codeInspection.ex.InspectionProfileImpl import com.intellij.codeInspection.ex.InspectionToolRegistrar +import com.intellij.concurrency.runAsync import com.intellij.configurationStore.SchemeDataHolder import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager @@ -117,7 +118,7 @@ class ProjectInspectionProfileManager(val project: Project, initialLoadSchemesFuture = CompletableFuture.completedFuture(null) } else { - initialLoadSchemesFuture = CompletableFuture.runAsync({ schemeManager.loadSchemes() }, { app.executeOnPooledThread(it) }) + initialLoadSchemesFuture = runAsync { schemeManager.loadSchemes() } } project.messageBus.connect().subscribe(ProjectManager.TOPIC, object: ProjectManagerListener { diff --git a/platform/core-impl/src/com/intellij/concurrency/completableFuture.kt b/platform/core-impl/src/com/intellij/concurrency/completableFuture.kt new file mode 100644 index 000000000000..8cf85a6490b4 --- /dev/null +++ b/platform/core-impl/src/com/intellij/concurrency/completableFuture.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2016 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 com.intellij.util.concurrency.AppExecutorUtil +import java.util.concurrent.CompletableFuture + +inline fun runAsync(crossinline runnable: () -> Unit): CompletableFuture = CompletableFuture.runAsync(Runnable { runnable() }, AppExecutorUtil.getAppExecutorService()) \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/application/actions.kt b/platform/platform-impl/src/com/intellij/openapi/application/actions.kt index 702998b277bf..820f04dee7da 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/actions.kt +++ b/platform/platform-impl/src/com/intellij/openapi/application/actions.kt @@ -46,4 +46,4 @@ fun invokeAndWaitIfNeed(runnable: () -> Unit) { else { app.invokeAndWait(runnable, ModalityState.defaultModalityState()) } -} +} \ No newline at end of file -- 2.32.0