[java] Don't use project as disposable

Introduces `JavaPluginDisposable` and migrates existing project disposables to the new project level service. #IDEA-383890 Fixed

GitOrigin-RevId: 762429b8f44959e127324d19053a8b05a818f414
This commit is contained in:
Bart van Helvert
2026-01-07 11:33:05 +00:00
committed by intellij-monorepo-bot
parent f1811ad257
commit b9b383c76e
22 changed files with 79 additions and 25 deletions
@@ -7,6 +7,7 @@ import com.intellij.compiler.impl.javaCompiler.eclipse.EclipseCompiler;
import com.intellij.compiler.impl.javaCompiler.javac.JavacCompiler;
import com.intellij.compiler.server.BuildManager;
import com.intellij.compiler.server.CompilerConfigurationUtils;
import com.intellij.java.JavaPluginDisposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.compiler.JavaCompilerBundle;
@@ -135,12 +136,12 @@ public final class CompilerConfigurationImpl extends CompilerConfiguration imple
}
BackendCompiler.EP_NAME.getPoint(project).addChangeListener(() -> {
myRegisteredCompilers = collectCompilers();
}, project);
}, JavaPluginDisposable.getInstance(project));
}
private static @NotNull ExcludedEntriesConfiguration createExcludedEntriesConfiguration(@NotNull Project project) {
final ExcludedEntriesConfiguration cfg = new ExcludedEntriesConfiguration(project.getMessageBus().syncPublisher(ExcludedEntriesListener.TOPIC));
Disposer.register(project, cfg);
Disposer.register(JavaPluginDisposable.getInstance(project), cfg);
project.getMessageBus().connect().subscribe(ExcludedEntriesListener.TOPIC, new ExcludedEntriesListener() {
@Override
public void onEntryAdded(@NotNull ExcludeEntryDescription description) {
@@ -7,6 +7,7 @@ import com.intellij.compiler.server.BuildManager;
import com.intellij.execution.process.ProcessIOExecutorService;
import com.intellij.execution.wsl.WSLDistribution;
import com.intellij.ide.IdleTracker;
import com.intellij.java.JavaPluginDisposable;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.*;
@@ -85,7 +86,7 @@ public class CompilerManagerImpl extends CompilerManager {
myEventPublisher = project.getMessageBus().syncPublisher(CompilerTopics.COMPILATION_STATUS);
// predefined compilers
for (ProjectExtensionPointName<?> ep : Arrays.asList(COMPILABLE_TYPE_EP, BackendCompiler.EP_NAME)) {
ep.addChangeListener(project, () -> {myCachedCompilableTypes = null;}, project);
ep.addChangeListener(project, () -> {myCachedCompilableTypes = null;}, JavaPluginDisposable.getInstance(project));
}
COMPILER_FACTORY_EP.getPoint(project).addExtensionPointListener(new ExtensionPointListener<>() {
@Override
@@ -118,7 +119,7 @@ public class CompilerManagerImpl extends CompilerManager {
projectGeneratedSrcRoot.mkdirs();
final LocalFileSystem lfs = LocalFileSystem.getInstance();
myWatchRoots = lfs.addRootsToWatch(Collections.singletonList(FileUtil.toCanonicalPath(projectGeneratedSrcRoot.getPath())), true);
Disposer.register(project, () -> {
Disposer.register(JavaPluginDisposable.getInstance(project), () -> {
final ExternalJavacManager manager = myExternalJavacManager;
myExternalJavacManager = null;
if (manager != null) {
@@ -2,6 +2,7 @@
package com.intellij.compiler.impl;
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.java.JavaPluginDisposable;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -28,7 +29,7 @@ public abstract class ExcludeFromCompileAction extends AnAction {
public void actionPerformed(@NotNull AnActionEvent e) {
VirtualFile file = getFile();
if (file != null && file.isValid()) {
ExcludeEntryDescription description = new ExcludeEntryDescription(file, false, true, myProject);
ExcludeEntryDescription description = new ExcludeEntryDescription(file, false, true, JavaPluginDisposable.getInstance(myProject));
CompilerConfiguration.getInstance(myProject).getExcludedEntriesConfiguration().addExcludeEntryDescription(description);
}
}
@@ -3,6 +3,7 @@
package com.intellij.compiler.options;
import com.intellij.build.FileNavigatable;
import com.intellij.java.JavaPluginDisposable;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -27,9 +28,11 @@ public class ExcludeFromValidationAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) return;
final Pair<ExcludesConfiguration, VirtualFile> pair = getExcludedConfigurationAndFile(e, project);
if (pair == null) return;
final ExcludeEntryDescription description = new ExcludeEntryDescription(pair.getSecond(), false, true, project);
final ExcludeEntryDescription description =
new ExcludeEntryDescription(pair.getSecond(), false, true, JavaPluginDisposable.getInstance(project));
pair.getFirst().addExcludeEntryDescription(description);
}