From 5aaa4edcf818f5620eca1fc4a2417074491c92da Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 29 May 2018 15:19:44 +0200 Subject: [PATCH] API for unregistering extension without creating its instance --- .../openapi/extensions/ExtensionPoint.java | 9 ++++--- .../extensions/impl/ExtensionPointImpl.java | 27 +++++++++---------- .../edu/PyCharmEduInitialConfigurator.java | 22 ++------------- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/ExtensionPoint.java b/platform/extensions/src/com/intellij/openapi/extensions/ExtensionPoint.java index ff70a3bf7fa8..ed48f70f4453 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/ExtensionPoint.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/ExtensionPoint.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.extensions; import com.intellij.openapi.Disposable; @@ -29,6 +27,11 @@ public interface ExtensionPoint { void unregisterExtension(@NotNull T extension); + /** + * Unregisters an extension of the specified type. + */ + void unregisterExtension(@NotNull Class extensionClass); + void addExtensionPointListener(@NotNull ExtensionPointListener listener, @NotNull Disposable parentDisposable); void addExtensionPointListener(@NotNull ExtensionPointListener listener); diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java index a5e0334717e6..737604ee0855 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java @@ -1,18 +1,4 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.extensions.impl; import com.intellij.openapi.Disposable; @@ -320,6 +306,17 @@ public class ExtensionPointImpl implements ExtensionPoint { unregisterExtension(extension, null); } + @Override + public void unregisterExtension(@NotNull Class extensionClass) { + for (ExtensionComponentAdapter adapter : ContainerUtil.concat(myExtensionAdapters, myLoadedAdapters)) { + if (adapter.getAssignableToClassName().equals(extensionClass.getCanonicalName())) { + unregisterExtensionAdapter(adapter); + return; + } + } + throw new IllegalArgumentException("Extension to be removed not found: " + extensionClass); + } + private int getExtensionIndex(@NotNull T extension) { for (int i = 0; i < myLoadedAdapters.size(); i++) { ExtensionComponentAdapter adapter = myLoadedAdapters.get(i); diff --git a/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java b/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java index 82923c3d8aeb..7c321af9283b 100644 --- a/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java +++ b/python/educational-python/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2013 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.edu; import com.google.common.collect.Sets; @@ -329,11 +315,7 @@ public class PyCharmEduInitialConfigurator { } } - for (DirectoryProjectConfigurator ep : Extensions.getExtensions(DirectoryProjectConfigurator.EP_NAME)) { - if (ep instanceof PlatformProjectViewOpener) { - rootArea.getExtensionPoint(DirectoryProjectConfigurator.EP_NAME).unregisterExtension(ep); - } - } + rootArea.getExtensionPoint(DirectoryProjectConfigurator.EP_NAME).unregisterExtension(PlatformProjectViewOpener.class); // unregister unrelated tips for (TipAndTrickBean tip : Extensions.getExtensions(TipAndTrickBean.EP_NAME)) {