get rid of createDisposable

GitOrigin-RevId: 14e43ccef1179ae0436e63622be1a030375430d4
This commit is contained in:
Vladimir Krivosheev
2023-05-16 09:53:30 +02:00
committed by intellij-monorepo-bot
parent e25387ea42
commit 27028c3aa6
6 changed files with 45 additions and 63 deletions

View File

@@ -1,9 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.intellij.lang.regexp.intention;
import com.intellij.codeInsight.highlighting.HighlightManager;
import com.intellij.icons.AllIcons;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
@@ -14,6 +13,7 @@ import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
@@ -112,7 +112,7 @@ public final class CheckRegExpForm {
@Override
protected void onEditorAdded(@NotNull Editor editor) {
super.onEditorAdded(editor);
disposable = PluginManager.getInstance().createDisposable(CheckRegExpForm.class);
disposable = ApplicationManager.getApplication().getService(RegExpDisposable.class);
editor.getCaretModel().addCaretListener(new CaretListener() {
@Override
@@ -164,15 +164,14 @@ public final class CheckRegExpForm {
});
setupIcon(myRegExp, myRegExpIcon);
final String sampleText =
PropertiesComponent.getInstance(project).getValue(LAST_EDITED_REGEXP, RegExpBundle.message("checker.sample.text"));
String sampleText = PropertiesComponent.getInstance(project).getValue(LAST_EDITED_REGEXP, RegExpBundle.message("checker.sample.text"));
mySampleText = new EditorTextField(sampleText, project, PlainTextFileType.INSTANCE) {
private Disposable disposable;
@Override
protected void onEditorAdded(@NotNull Editor editor) {
super.onEditorAdded(editor);
disposable = PluginManager.getInstance().createDisposable(CheckRegExpForm.class);
disposable = ApplicationManager.getApplication().getService(RegExpDisposable.class);
editor.getCaretModel().addCaretListener(new CaretListener() {
@Override
@@ -282,7 +281,8 @@ public final class CheckRegExpForm {
if (result != RegExpMatchResult.MATCHES && result != RegExpMatchResult.FOUND) {
setMatches(regExpFile, null);
}
ApplicationManager.getApplication().invokeLater(() -> reportResult(result, regExpFile), ModalityState.any(), __ -> updater.isDisposed());
ApplicationManager.getApplication()
.invokeLater(() -> reportResult(result, regExpFile), ModalityState.any(), __ -> updater.isDisposed());
}, 0);
}
}
@@ -576,8 +576,8 @@ public final class CheckRegExpForm {
return RegExpMatchResult.BAD_REGEXP;
}
private static SmartList<RegExpMatch> collectMatches(Matcher matcher) {
final SmartList<RegExpMatch> matches = new SmartList<>();
private static List<RegExpMatch> collectMatches(Matcher matcher) {
List<RegExpMatch> matches = new SmartList<>();
do {
final RegExpMatch match = new RegExpMatch();
final int count = matcher.groupCount();
@@ -585,7 +585,15 @@ public final class CheckRegExpForm {
match.add(matcher.start(i), matcher.end(i));
}
matches.add(match);
} while (matcher.find());
}
while (matcher.find());
return matches;
}
}
@Service
final class RegExpDisposable implements Disposable {
@Override
public void dispose() {
}
}

View File

@@ -1,17 +1,14 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.plugins;
import com.intellij.ide.plugins.cl.PluginAwareClassLoader;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.components.ComponentManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginDescriptor;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -155,35 +152,6 @@ public final class PluginManager {
return PluginManagerCore.getPluginSet().findEnabledPlugin(id);
}
public @NotNull Disposable createDisposable(@NotNull Class<?> requestor) {
ClassLoader classLoader = requestor.getClassLoader();
if (!(classLoader instanceof PluginAwareClassLoader)) {
return Disposer.newDisposable();
}
int classLoaderId = ((PluginAwareClassLoader)classLoader).getInstanceId();
// must not be lambda because we care about identity in ObjectTree.myObject2NodeMap
return new PluginAwareDisposable() {
@Override
public int getClassLoaderId() {
return classLoaderId;
}
@Override
public void dispose() { }
};
}
public @NotNull Disposable createDisposable(@NotNull Class<?> requestor, @NotNull ComponentManager parentDisposable) {
Disposable disposable = createDisposable(requestor);
Disposer.register(parentDisposable, disposable);
return disposable;
}
interface PluginAwareDisposable extends Disposable {
int getClassLoaderId();
}
/**
* Convert build number like '146.9999' to '146.*' (like plugin repository does) to ensure that plugins which have such values in
* 'until-build' attribute will be compatible with 146.SNAPSHOT build.

View File

@@ -48,7 +48,6 @@ private val EMPTY_CLASS_LOADER_ARRAY = arrayOfNulls<ClassLoader>(0)
private val KOTLIN_STDLIB_CLASSES_USED_IN_SIGNATURES = computeKotlinStdlibClassesUsedInSignatures()
private var logStream: Writer? = null
private val instanceIdProducer = AtomicInteger()
private val parentListCacheIdCounter = AtomicInteger()
@ApiStatus.Internal
@@ -72,8 +71,7 @@ class PluginClassLoader(classPath: ClassPath,
private val edtTime = AtomicLong()
private val backgroundTime = AtomicLong()
private val loadedClassCounter = AtomicInteger()
private val instanceId = instanceIdProducer.incrementAndGet()
private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + CoroutineName("${pluginId.idString}@$instanceId"))
private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + CoroutineName(pluginId.idString))
private val _resolveScopeManager = resolveScopeManager ?: defaultResolveScopeManager
companion object {
@@ -133,8 +131,6 @@ class PluginClassLoader(classPath: ClassPath,
throw IllegalStateException("Unexpected state: $state")
}
override fun getInstanceId(): Int = instanceId
override fun getEdtTime(): Long = edtTime.get()
override fun getBackgroundTime(): Long = backgroundTime.get()
@@ -469,7 +465,6 @@ ${if (exception == null) "" else exception.message}""")
return "${javaClass.simpleName}(" +
"plugin=$pluginDescriptor, " +
"packagePrefix=$packagePrefix, " +
"instanceId=$instanceId, " +
"state=${if (state == PluginAwareClassLoader.ACTIVE) "active" else "unload in progress"}" +
")"
}

View File

@@ -21,8 +21,6 @@ public interface PluginAwareClassLoader {
@NotNull PluginId getPluginId();
int getInstanceId();
long getEdtTime();
long getBackgroundTime();

View File

@@ -1098,15 +1098,9 @@ private fun analyzeSnapshot(hprofPath: String, pluginId: PluginId): String {
}
private fun createDisposeTreePredicate(pluginDescriptor: IdeaPluginDescriptorImpl): Predicate<Disposable>? {
val classLoader = pluginDescriptor.pluginClassLoader as? PluginClassLoader
?: return null
val classLoader = pluginDescriptor.pluginClassLoader as? PluginClassLoader ?: return null
return Predicate {
if (it is PluginManager.PluginAwareDisposable) {
it.classLoaderId == classLoader.instanceId
}
else {
it::class.java.classLoader === classLoader
}
it::class.java.classLoader === classLoader
}
}

View File

@@ -15,7 +15,6 @@ import com.intellij.execution.target.TargetProgressIndicator;
import com.intellij.execution.target.value.TargetEnvironmentFunctions;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.ide.AppLifecycleListener;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
@@ -34,6 +33,7 @@ import com.intellij.util.NotNullFunction;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.HelperPackage;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PythonPluginDisposable;
import com.jetbrains.python.console.PydevConsoleRunnerUtil;
import com.jetbrains.python.remote.PyRemoteSdkAdditionalData;
import com.jetbrains.python.sdk.PyRemoteSdkAdditionalDataMarker;
@@ -437,10 +437,29 @@ public class PythonTask {
* Listener is removed from process stopped to prevent leak
*/
private void stopProcessWhenAppClosed(@NotNull ProcessHandler process) {
Disposable disposable = PluginManager.getInstance().createDisposable(PythonTask.class, myModule);
process.addProcessListener(new ProcessAdapter() {
Disposable disposable = Disposer.newDisposable();
Disposable a = new Disposable() {
@Override
public void processTerminated(@NotNull final ProcessEvent event) {
public void dispose() {
Disposer.dispose(disposable);
}
};
Disposable b = new Disposable() {
@Override
public void dispose() {
Disposer.dispose(disposable);
}
};
//noinspection IncorrectParentDisposable
Disposer.register(myModule, a);
Disposer.register(PythonPluginDisposable.getInstance(myModule.getProject()), b);
Disposer.register(disposable, a);
Disposer.register(disposable, b);
process.addProcessListener(new ProcessListener() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
Disposer.dispose(disposable);
}
}, disposable);