reduce usage of ApplicationComponent.disposeComponent (to dispose in a correct order (as Disposer))

This commit is contained in:
Vladimir Krivosheev
2017-01-11 14:45:53 +01:00
parent 042d942131
commit d82be8763b
14 changed files with 53 additions and 169 deletions
@@ -17,14 +17,13 @@ package org.jetbrains.ide;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.util.Url;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.URLConnection;
public abstract class BuiltInServerManager extends ApplicationComponent.Adapter {
public abstract class BuiltInServerManager {
public static BuiltInServerManager getInstance() {
return ApplicationManager.getApplication().getComponent(BuiltInServerManager.class);
}
@@ -7,6 +7,7 @@ import com.intellij.notification.NotificationType;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullLazyValue;
@@ -31,7 +32,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
public class BuiltInServerManagerImpl extends BuiltInServerManager {
public class BuiltInServerManagerImpl extends BuiltInServerManager implements ApplicationComponentAdapter {
private static final Logger LOG = Logger.getInstance(BuiltInServerManager.class);
public static final NotNullLazyValue<NotificationGroup> NOTIFICATION_GROUP = new NotNullLazyValue<NotificationGroup>() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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,10 @@
package com.intellij.ide;
import com.intellij.Patches;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ClipboardUtil;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
@@ -58,7 +59,7 @@ import java.util.function.Supplier;
*
* @author nik
*/
public class ClipboardSynchronizer implements ApplicationComponent {
public class ClipboardSynchronizer implements ApplicationComponentAdapter, Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.ClipboardSynchronizer");
private final ClipboardHandler myClipboardHandler;
@@ -88,16 +89,10 @@ public class ClipboardSynchronizer implements ApplicationComponent {
}
@Override
public void disposeComponent() {
public void dispose() {
myClipboardHandler.dispose();
}
@NotNull
@Override
public String getComponentName() {
return "ClipboardSynchronizer";
}
public void areDataFlavorsAvailableAsync(@NotNull Consumer<Boolean> callback, @NotNull DataFlavor... flavors) {
final Supplier<Boolean> availabilitySupplier =
() -> ClipboardUtil.handleClipboardSafely(() -> myClipboardHandler.areDataFlavorsAvailable(flavors),() -> false);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -13,22 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.ui.laf;
import com.intellij.ide.ui.LafManager;
import com.intellij.ide.ui.LafManagerListener;
import com.intellij.openapi.components.ApplicationComponent;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* User: anna
* Date: 17-May-2006
*/
public class HeadlessLafManagerImpl extends LafManager implements ApplicationComponent {
public class HeadlessLafManagerImpl extends LafManager {
public UIManager.LookAndFeelInfo[] getInstalledLookAndFeels() {
return new UIManager.LookAndFeelInfo[0];
}
@@ -55,16 +47,4 @@ public class HeadlessLafManagerImpl extends LafManager implements ApplicationCom
public void removeLafManagerListener(LafManagerListener l) {
}
@NonNls
@NotNull
public String getComponentName() {
return "HeadlessLafManagerImpl";
}
public void initComponent() {
}
public void disposeComponent() {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -40,8 +40,7 @@ import java.util.concurrent.TimeUnit;
name = "StatisticsApplicationUsages",
storages = @Storage(value = "statistics.application.usages.xml", roamingType = RoamingType.DISABLED)
)
public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence implements ApplicationComponentAdapter, PersistentStateComponent<Element> {
private boolean persistOnClosing = !ApplicationManager.getApplication().isUnitTestMode();
private static final String TOKENIZER = ",";
@@ -156,13 +155,6 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis
}, TOKENIZER);
}
@Override
@NonNls
@NotNull
public String getComponentName() {
return "ApplicationStatisticsPersistenceComponent";
}
@Override
public void initComponent() {
ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() {
@@ -194,8 +186,4 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis
UsagesCollector.doPersistProjectUsages(project);
}
}
@Override
public void disposeComponent() {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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,7 +18,7 @@ package com.intellij.openapi.command.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.undo.DocumentReference;
import com.intellij.openapi.command.undo.DocumentReferenceManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Key;
@@ -39,7 +39,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DocumentReferenceManagerImpl extends DocumentReferenceManager implements ApplicationComponent {
public class DocumentReferenceManagerImpl extends DocumentReferenceManager implements ApplicationComponentAdapter {
private static final Key<List<VirtualFile>> DELETED_FILES = Key.create(DocumentReferenceManagerImpl.class.getName() + ".DELETED_FILES");
private final Map<Document, DocumentReference> myDocToRef = new WeakKeyWeakValueHashMap<>();
@@ -48,12 +48,6 @@ public class DocumentReferenceManagerImpl extends DocumentReferenceManager imple
private static final Key<DocumentReference> FILE_TO_STRONG_REF_KEY = Key.create("FILE_TO_STRONG_REF_KEY");
private final Map<FilePath, DocumentReference> myDeletedFilePathToRef = new WeakValueHashMap<>();
@Override
@NotNull
public String getComponentName() {
return getClass().getSimpleName();
}
@Override
public void initComponent() {
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
@@ -105,10 +99,6 @@ public class DocumentReferenceManagerImpl extends DocumentReferenceManager imple
return files;
}
@Override
public void disposeComponent() {
}
@NotNull
@Override
public DocumentReference create(@NotNull Document document) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -23,7 +23,7 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
@@ -82,7 +82,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@State(name = "FileTypeManager", storages = @Storage("filetypes.xml"), additionalExportFile = FileTypeManagerImpl.FILE_SPEC )
public class FileTypeManagerImpl extends FileTypeManagerEx implements PersistentStateComponent<Element>, ApplicationComponent, Disposable {
public class FileTypeManagerImpl extends FileTypeManagerEx implements PersistentStateComponent<Element>, ApplicationComponentAdapter, Disposable {
private static final Logger LOG = Logger.getInstance(FileTypeManagerImpl.class);
// You must update all existing default configurations accordingly
@@ -475,10 +475,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
return stdFileType != null ? stdFileType.fileType : PlainTextFileType.INSTANCE;
}
@Override
public void disposeComponent() {
}
@Override
public void initComponent() {
if (!myUnresolvedMappings.isEmpty()) {
@@ -1459,11 +1455,6 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
// Setup
// -------------------------------------------------------------------------
@Override
@NotNull
public String getComponentName() {
return getFileTypeComponentName();
}
@NotNull
public static String getFileTypeComponentName() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2017 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,28 +15,17 @@
*/
package com.intellij.openapi.util;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.ui.mac.foundation.Foundation;
import org.jetbrains.annotations.NotNull;
/**
* User: spLeaner
*/
public class FoundationLoader implements ApplicationComponent {
@NotNull
public String getComponentName() {
return "FoundationLoader";
}
public class FoundationLoader implements ApplicationComponentAdapter {
@Override
public void initComponent() {
if (SystemInfo.isMac) {
Foundation.init();
}
}
public void disposeComponent() {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2017 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.remoteServer.impl.configuration.deployment;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.remoteServer.ServerType;
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class DeployToServerConfigurationTypesRegistrar implements ApplicationComponent {
public class DeployToServerConfigurationTypesRegistrar implements ApplicationComponentAdapter {
@Override
public void initComponent() {
//todo[nik] improve this: configuration types should be loaded lazily
@@ -47,14 +47,4 @@ public class DeployToServerConfigurationTypesRegistrar implements ApplicationCom
}
throw new IllegalArgumentException("Cannot find run configuration type for " + serverType.getClass());
}
@Override
public void disposeComponent() {
}
@NotNull
@Override
public String getComponentName() {
return "DeployToServerConfigurationTypesRegistrar";
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -260,15 +260,12 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
private void runUpdateMappings() {
// TODO: Not clear so far why read action is used here - may be because of ROOTS_RELOADED message sent?
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed()) return;
ApplicationManager.getApplication().runReadAction(() -> {
if (myProject.isDisposed()) return;
boolean mappingsChanged = updateMappings();
boolean mappingsChanged = updateMappings();
notifyRootsReloaded(mappingsChanged);
}
notifyRootsReloaded(mappingsChanged);
});
}
@@ -349,7 +346,7 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
return result;
}
private SvnCopyRootSimple convert(final RootUrlInfo info) {
private static SvnCopyRootSimple convert(final RootUrlInfo info) {
final SvnCopyRootSimple copy = new SvnCopyRootSimple();
copy.myVcsRoot = FileUtil.toSystemDependentName(info.getRoot().getPath());
copy.myCopyRoot = info.getIoFile().getAbsolutePath();
@@ -358,31 +355,24 @@ public class SvnFileUrlMappingImpl implements SvnFileUrlMapping, PersistentState
public void loadState(final SvnMappingSavedPart state) {
((ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject)).addInitializationRequest(
VcsInitObject.AFTER_COMMON, new DumbAwareRunnable() {
public void run() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
final SvnMapping mapping = new SvnMapping();
final SvnMapping realMapping = new SvnMapping();
try {
fillMapping(mapping, state.getMappingRoots());
fillMapping(realMapping, state.getMoreRealMappingRoots());
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable t) {
LOG.info(t);
return;
}
synchronized (myMonitor) {
myMapping.copyFrom(mapping);
myMoreRealMapping.copyFrom(realMapping);
}
}
});
VcsInitObject.AFTER_COMMON, (DumbAwareRunnable)() -> ApplicationManager.getApplication().executeOnPooledThread(() -> {
final SvnMapping mapping = new SvnMapping();
final SvnMapping realMapping = new SvnMapping();
try {
fillMapping(mapping, state.getMappingRoots());
fillMapping(realMapping, state.getMoreRealMappingRoots());
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable t) {
LOG.info(t);
return;
}
});
synchronized (myMonitor) {
myMapping.copyFrom(mapping);
myMoreRealMapping.copyFrom(realMapping);
}
}));
}
private void fillMapping(final SvnMapping mapping, final List<SvnCopyRootSimple> list) {
@@ -20,7 +20,7 @@ import com.intellij.lang.Language;
import com.intellij.lang.LanguageFormatting;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
@@ -44,7 +44,7 @@ import java.awt.*;
storages = {
@Storage("other.xml")}
)
class XsltConfigImpl extends XsltConfig implements PersistentStateComponent<XsltConfigImpl>, ApplicationComponent {
class XsltConfigImpl extends XsltConfig implements PersistentStateComponent<XsltConfigImpl>, ApplicationComponentAdapter {
public boolean SHOW_LINKED_FILES = true;
@Nullable
@@ -81,17 +81,6 @@ class XsltConfigImpl extends XsltConfig implements PersistentStateComponent<Xslt
}
}
@Override
public void disposeComponent() {
}
@Override
@NotNull
@NonNls
public String getComponentName() {
return "XSLT-Support.Configuration";
}
@Override
public boolean isShowLinkedFiles() {
return SHOW_LINKED_FILES;
@@ -20,7 +20,7 @@ import com.intellij.javaee.ResourceRegistrar;
import com.intellij.javaee.StandardResourceProvider;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ApplicationComponentAdapter;
import com.intellij.psi.PsiElement;
import com.intellij.psi.filters.AndFilter;
import com.intellij.psi.filters.ClassFilter;
@@ -38,26 +38,12 @@ import org.intellij.plugins.relaxNG.model.descriptors.RngNsDescriptor;
import org.intellij.plugins.relaxNG.validation.ValidateAction;
import org.intellij.plugins.relaxNG.xml.dom.RngDefine;
import org.intellij.plugins.relaxNG.xml.dom.impl.RngDefineMetaData;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* Created by IntelliJ IDEA.
* User: sweinreuter
* Date: 18.07.2007
*/
public class ApplicationLoader implements ApplicationComponent {
public class ApplicationLoader implements ApplicationComponentAdapter {
private static final String RNG_EXT = "rng";
private static final String VALIDATE_XML = "ValidateXml";
public static final String RNG_NAMESPACE = "http://relaxng.org/ns/structure/1.0";
@Override
@NonNls
@NotNull
public String getComponentName() {
return "Relax-NG";
}
@Override
public void initComponent() {
registerMetaData();
@@ -103,10 +89,6 @@ public class ApplicationLoader implements ApplicationComponent {
}, RngDefineMetaData.class);
}
@Override
public void disposeComponent() {
}
public static Class[] getInspectionClasses() {
return new Class[]{
RngDomInspection.class,