IJPL-310 hasAnyExtensions - return false if no point instead of NPE

GitOrigin-RevId: df60845218edaf0a52eb527091f007e3f7e68792
This commit is contained in:
Vladimir Krivosheev
2023-10-26 16:48:33 +02:00
committed by intellij-monorepo-bot
parent 0585d0d4d1
commit 4ff58bfb3f
3 changed files with 10 additions and 5 deletions

View File

@@ -75,7 +75,10 @@ class ExtensionPointName<T : Any>(name: @NonNls String) : BaseExtensionPointName
@Deprecated("Use {@code getExtensionList().stream()}", ReplaceWith("getExtensionList().stream()"), DeprecationLevel.ERROR)
fun extensions(): Stream<T> = getPointImpl(null).asSequence().asStream()
fun hasAnyExtensions(): Boolean = getPointImpl(null).size() != 0
fun hasAnyExtensions(): Boolean {
@Suppress("DEPRECATION")
return (Extensions.getRootArea().getExtensionPointIfRegistered<T>(name) ?: return false).size() != 0
}
/**
* Consider using [ProjectExtensionPointName.getExtensions]
@@ -90,6 +93,7 @@ class ExtensionPointName<T : Any>(name: @NonNls String) : BaseExtensionPointName
@Deprecated("Use app-level app extension point.", level = DeprecationLevel.ERROR)
fun extensions(areaInstance: AreaInstance?): Stream<T> {
@Suppress("SSBasedInspection")
return getPointImpl(areaInstance).extensionList.stream()
}

View File

@@ -1,8 +1,9 @@
// 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.openapi.extensions;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
public interface ExtensionsArea {
@@ -32,7 +33,7 @@ public interface ExtensionsArea {
@NotNull <T> ExtensionPoint<@NotNull T> getExtensionPoint(@NonNls @NotNull String extensionPointName);
<T> ExtensionPoint<@NotNull T> getExtensionPointIfRegistered(@NotNull String extensionPointName);
<T> @Nullable ExtensionPoint<@NotNull T> getExtensionPointIfRegistered(@NotNull String extensionPointName);
@NotNull <T> ExtensionPoint<@NotNull T> getExtensionPoint(@NotNull ExtensionPointName<T> extensionPointName);
}

View File

@@ -433,7 +433,7 @@ class DynamicPluginsTest {
assertThat(ep).isNotNull()
loadPluginWithText(barBuilder).use {
assertThat(ep.extensionList).hasSize(1)
assertThat(ep!!.extensionList).hasSize(1)
val extension = ep.extensionList.single()
assertThat(extension.key).isEqualTo("foo")
@@ -443,7 +443,7 @@ class DynamicPluginsTest {
.isEqualTo(findEnabledModuleByName("intellij.foo.bar"))
}
assertThat(ep.extensionList).isEmpty()
assertThat(ep!!.extensionList).isEmpty()
}
}