Commit 240537de authored by Vladimir Krivosheev's avatar Vladimir Krivosheev Committed by intellij-monorepo-bot
Browse files

cleanup

GitOrigin-RevId: 82e394f43131c7cdadbc957f31098cc8a3f15d66
parent 6ba22225
Showing with 191 additions and 247 deletions
+191 -247
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.compiler.artifacts
import com.intellij.openapi.Disposable
......@@ -118,7 +118,7 @@ class ArtifactLoadingTest {
StringUtil.convertLineSeparators(File(projectModel.baseProjectDir.root, ".idea/artifacts/Artifact.xml").readText()))
}
private inline fun <T> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
private inline fun <T : Any> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
val disposable = Disposer.newDisposable()
runInEdt {
runWriteAction {
......@@ -133,7 +133,7 @@ class ArtifactLoadingTest {
}
}
private fun <T> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
private fun <T : Any> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
val artifactTypeDisposable = Disposer.newDisposable()
Disposer.register(disposable, Disposable {
runInEdt {
......
......@@ -21,7 +21,7 @@ import javax.swing.Icon
class DynamicArtifactExtensionsLoaderTest : HeavyPlatformTestCase() {
fun `test unload and load artifact type`() {
ProjectLoadingErrorsHeadlessNotifier.setErrorHandler(testRootDisposable, {})
ProjectLoadingErrorsHeadlessNotifier.setErrorHandler(testRootDisposable) {}
val artifactManager = ArtifactManager.getInstance(myProject)
runWithRegisteredExtension(MockArtifactType(), ArtifactType.EP_NAME) {
artifactManager.addArtifact("mock", MockArtifactType.getInstance(), PackagingElementFactory.getInstance().createArtifactRootElement())
......@@ -75,7 +75,7 @@ class DynamicArtifactExtensionsLoaderTest : HeavyPlatformTestCase() {
assertEquals("data", (artifact.getProperties(MockArtifactPropertiesProvider.getInstance()) as MockArtifactProperties).data)
}
private inline fun <T> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
private inline fun <T : Any> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
val disposable = Disposer.newDisposable()
registerExtension(extension, extensionPoint, disposable)
try {
......@@ -86,7 +86,7 @@ class DynamicArtifactExtensionsLoaderTest : HeavyPlatformTestCase() {
}
}
private fun <T> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
private fun <T : Any> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
val artifactTypeDisposable = Disposer.newDisposable()
Disposer.register(disposable, Disposable {
runWriteAction {
......@@ -98,7 +98,7 @@ class DynamicArtifactExtensionsLoaderTest : HeavyPlatformTestCase() {
override fun setUp() {
super.setUp()
ProjectLoadingErrorsHeadlessNotifier.setErrorHandler(testRootDisposable, {})
ProjectLoadingErrorsHeadlessNotifier.setErrorHandler(testRootDisposable) {}
}
}
......
......@@ -33,9 +33,6 @@ import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.workspaceModel.ide.WorkspaceModel
import com.intellij.workspaceModel.ide.getInstance
import com.intellij.workspaceModel.storage.EntitySource
import com.intellij.workspaceModel.storage.bridgeEntities.addArtifactEntity
import com.intellij.workspaceModel.storage.bridgeEntities.addArtifactRootElementEntity
import com.intellij.workspaceModel.storage.bridgeEntities.addCustomPackagingElementEntity
import com.intellij.workspaceModel.storage.bridgeEntities.*
import com.intellij.workspaceModel.storage.bridgeEntities.ArtifactEntity
import com.intellij.workspaceModel.storage.bridgeEntities.ArtifactPropertiesEntity
......@@ -728,7 +725,7 @@ class ArtifactTest : ArtifactsTestCase() {
assertEmpty(newArtifact.rootElement.children)
}
private inline fun <T> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
private inline fun <T : Any> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
val disposable = Disposer.newDisposable()
registerExtension(extension, extensionPoint, disposable)
try {
......@@ -739,7 +736,7 @@ class ArtifactTest : ArtifactsTestCase() {
}
}
private fun <T> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
private fun <T : Any> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
val artifactTypeDisposable = Disposer.newDisposable()
Disposer.register(disposable, Disposable {
runWriteAction {
......
......@@ -47,10 +47,6 @@ class ArtifactTest : HeavyPlatformTestCase() {
}
private class MockArtifactTypeForRename : ArtifactType("mock", Supplier { "Mock" }) {
companion object {
fun getInstance() = EP_NAME.findExtension(MockArtifactTypeForRename::class.java)!!
}
override fun getIcon(): Icon = EmptyIcon.ICON_16
override fun getDefaultPathFor(kind: PackagingElementOutputKind): String = ""
......@@ -60,7 +56,7 @@ private class MockArtifactTypeForRename : ArtifactType("mock", Supplier { "Mock"
}
}
private inline fun <T> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
private inline fun <T : Any> runWithRegisteredExtension(extension: T, extensionPoint: ExtensionPointName<T>, action: () -> Unit) {
val disposable = Disposer.newDisposable()
registerExtension(extension, extensionPoint, disposable)
try {
......@@ -71,7 +67,7 @@ private inline fun <T> runWithRegisteredExtension(extension: T, extensionPoint:
}
}
private fun <T> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
private fun <T : Any> registerExtension(type: T, extensionPointName: ExtensionPointName<T>, disposable: Disposable) {
val artifactTypeDisposable = Disposer.newDisposable()
Disposer.register(disposable, Disposable {
runWriteAction {
......
......@@ -114,7 +114,7 @@ class LibraryPropertiesTest : ModuleRootManagerTestCase() {
Disposer.dispose(libraryTypeDisposable)
}
})
LibraryType.EP_NAME.getPoint().registerExtension(MockLibraryType(), libraryTypeDisposable)
LibraryType.EP_NAME.point.registerExtension(MockLibraryType(), libraryTypeDisposable)
}
}
......
......@@ -90,7 +90,7 @@ abstract class ComponentStoreWithExtraComponents : ComponentStoreImpl() {
}
internal open fun commitObsoleteComponents(session: SaveSessionProducerManager, isProjectLevel: Boolean) {
for (bean in OBSOLETE_STORAGE_EP.iterable) {
for (bean in OBSOLETE_STORAGE_EP.lazySequence()) {
if (bean.isProjectLevel != isProjectLevel) {
continue
}
......
......@@ -39,7 +39,7 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
private var dotIdea: Path? = null
internal fun getNameFile(): Path {
for (projectNameProvider in ProjectNameProvider.EP_NAME.iterable) {
for (projectNameProvider in ProjectNameProvider.EP_NAME.lazySequence()) {
LOG.runAndLogException { projectNameProvider.getNameFile(project)?.let { return it } }
}
return directoryStorePath!!.resolve(ProjectEx.NAME_FILE)
......@@ -208,7 +208,7 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
for (providerFactory in StreamProviderFactory.EP_NAME.getIterable(project)) {
LOG.runAndLogException {
// yes, DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION is not added in this case
providerFactory.customizeStorageSpecs(component, storageManager, stateSpec, result!!, operation)?.let { return it }
providerFactory?.customizeStorageSpecs(component, storageManager, stateSpec, result!!, operation)?.let { return it }
}
}
}
......
......@@ -7,7 +7,6 @@ import com.intellij.openapi.components.PathMacroManager
import com.intellij.openapi.components.impl.stores.IComponentStore
import com.intellij.openapi.components.impl.stores.IProjectStore
import com.intellij.openapi.diagnostic.getOrLogException
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectNameProvider
......@@ -64,7 +63,7 @@ open class ProjectStoreImpl(project: Project) : ProjectStoreBase(project) {
return storedName
}
for (projectNameProvider in ProjectNameProvider.EP_NAME.iterable) {
for (projectNameProvider in ProjectNameProvider.EP_NAME.lazySequence()) {
runCatching {
projectNameProvider.getDefaultName(project)
}
......@@ -166,7 +165,7 @@ open class ProjectWithModulesStoreImpl(project: Project) : ProjectStoreImpl(proj
isForceSavingAllSettings: Boolean,
projectSaveSessionManager: SaveSessionProducerManager): List<SaveSession> {
moduleSavingCustomizer.saveModules(projectSaveSessionManager, this)
val modules = ModuleManager.getInstance(project)?.modules ?: Module.EMPTY_ARRAY
val modules = ModuleManager.getInstance(project).modules
if (modules.isEmpty()) {
return emptyList()
}
......
......@@ -495,7 +495,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(
}
private fun findRunner(runnerId: String): ProgramRunner<*>? {
val runnersById = ProgramRunner.PROGRAM_RUNNER_EP.iterable.filter { runnerId == it.runnerId }
val runnersById = ProgramRunner.PROGRAM_RUNNER_EP.lazySequence().filter { runnerId == it.runnerId }.toList()
return when {
runnersById.isEmpty() -> null
runnersById.size == 1 -> runnersById.firstOrNull()
......
// Copyright 2000-2021 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.configuration
import com.intellij.execution.ExecutionException
......@@ -211,20 +211,16 @@ open class RunConfigurationExtensionsManager<U : RunConfigurationBase<*>, T : Ru
}
protected inline fun processApplicableExtensions(configuration: U, handler: (T) -> Unit) {
for (extension in extensionPoint.iterable) {
if (extension != null && extension.isApplicableFor(configuration)) {
for (extension in extensionPoint.lazySequence()) {
if (extension.isApplicableFor(configuration)) {
handler(extension)
}
}
}
fun forEachApplicableExtension(configuration: U, handler: (T) -> Unit) {
processApplicableExtensions(configuration, handler)
}
protected inline fun processEnabledExtensions(configuration: U, runnerSettings: RunnerSettings?, handler: (T) -> Unit) {
for (extension in extensionPoint.iterable) {
if (extension != null && extension.isApplicableFor(configuration) && extension.isEnabledFor(configuration, runnerSettings)) {
for (extension in extensionPoint.lazySequence()) {
if (extension.isApplicableFor(configuration) && extension.isEnabledFor(configuration, runnerSettings)) {
handler(extension)
}
}
......
// Copyright 2000-2022 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 com.intellij.openapi.Disposable;
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.function.*;
import java.util.stream.Stream;
@file:Suppress("DeprecatedCallableAddReplaceWith")
package com.intellij.openapi.extensions
import com.intellij.openapi.Disposable
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.computeIfAbsent
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.computeSafeIfAny
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.findFirstSafe
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.forEachExtensionSafe
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.getByGroupingKey
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.getByKey
import com.intellij.util.ThreeState
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.NonNls
import java.util.function.*
import java.util.function.Function
import java.util.stream.Stream
/**
* Provides access to an <a href="https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_extension_points.html">extension point</a>. Instances of this class can be safely stored in static final fields.
* <p>For project-level and module-level extension points use {@link ProjectExtensionPointName} instead to make it evident that corresponding
* {@link AreaInstance} must be passed.</p>
* Provides access to an [extension point](https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_extension_points.html). Instances of this class can be safely stored in static final fields.
*
* For project-level and module-level extension points use [ProjectExtensionPointName] instead to make it evident that corresponding
* [AreaInstance] must be passed.
*/
public final class ExtensionPointName<T> extends BaseExtensionPointName<T> {
public ExtensionPointName(@NotNull @NonNls String name) {
super(name);
}
public static @NotNull <T> ExtensionPointName<T> create(@NonNls @NotNull String name) {
return new ExtensionPointName<>(name);
class ExtensionPointName<T : Any>(name: @NonNls String) : BaseExtensionPointName<T>(name) {
companion object {
@JvmStatic
fun <T : Any> create(name: @NonNls String): ExtensionPointName<T> = ExtensionPointName(name)
}
/**
* Consider using {@link #getExtensionList()}.
* Consider using [.getExtensionList].
*/
public T @NotNull [] getExtensions() {
return getPointImpl(null).getExtensions();
}
val extensions: Array<T>
get() = getPointImpl(null).extensions
public @NotNull List<T> getExtensionList() {
return getPointImpl(null).getExtensionList();
}
val extensionList: List<T>
get() = getPointImpl(null).extensionList
/**
* Invokes the given consumer for each extension registered in this extension point. Logs exceptions thrown by the consumer.
*/
public void forEachExtensionSafe(@NotNull Consumer<? super T> consumer) {
ExtensionProcessingHelper.INSTANCE.forEachExtensionSafe(getPointImpl(null), consumer);
fun forEachExtensionSafe(consumer: Consumer<in T>) {
forEachExtensionSafe(getPointImpl(null), consumer)
}
public @Nullable T findFirstSafe(@NotNull Predicate<? super T> predicate) {
return ExtensionProcessingHelper.INSTANCE.findFirstSafe(predicate, getPointImpl(null));
fun findFirstSafe(predicate: Predicate<in T>): T? {
return findFirstSafe(predicate, getPointImpl(null))
}
public @Nullable <R> R computeSafeIfAny(@NotNull Function<? super T, ? extends R> processor) {
return ExtensionProcessingHelper.INSTANCE.computeSafeIfAny(processor, getPointImpl(null));
fun <R> computeSafeIfAny(processor: Function<in T, out R?>): R? {
return computeSafeIfAny(processor, getPointImpl(null))
}
public @NotNull List<T> getExtensionsIfPointIsRegistered() {
return getExtensionsIfPointIsRegistered(null);
}
val extensionsIfPointIsRegistered: List<T>
get() = getExtensionsIfPointIsRegistered(null)
public @NotNull List<T> getExtensionsIfPointIsRegistered(@Nullable AreaInstance areaInstance) {
//noinspection deprecation
ExtensionsArea area = areaInstance == null ? Extensions.getRootArea() : areaInstance.getExtensionArea();
ExtensionPoint<@NotNull T> point = area == null ? null : area.getExtensionPointIfRegistered(getName());
return point == null ? Collections.emptyList() : point.getExtensionList();
fun getExtensionsIfPointIsRegistered(areaInstance: AreaInstance?): List<T> {
@Suppress("DEPRECATION")
val area = areaInstance?.extensionArea ?: Extensions.getRootArea()
return area?.getExtensionPointIfRegistered<T>(name)?.extensionList ?: emptyList()
}
/**
* @deprecated Use {@code getExtensionList().stream()}
*/
@Deprecated
public @NotNull Stream<T> extensions() {
return getPointImpl(null).extensions();
@Deprecated("Use {@code getExtensionList().stream()}", ReplaceWith("getExtensionList().stream()"))
fun extensions(): Stream<T> {
return getPointImpl(null).extensions()
}
public boolean hasAnyExtensions() {
return getPointImpl(null).size() != 0;
}
fun hasAnyExtensions(): Boolean = getPointImpl(null).size() != 0
/**
* Consider using {@link ProjectExtensionPointName#getExtensions(AreaInstance)}
* Consider using [ProjectExtensionPointName.getExtensions]
*/
public @NotNull List<T> getExtensionList(@Nullable AreaInstance areaInstance) {
return getPointImpl(areaInstance).getExtensionList();
}
fun getExtensionList(areaInstance: AreaInstance?): List<T> = getPointImpl(areaInstance).extensionList
/**
* Consider using {@link ProjectExtensionPointName#getExtensions(AreaInstance)}
* Consider using [ProjectExtensionPointName.getExtensions]
*/
public T @NotNull [] getExtensions(@Nullable AreaInstance areaInstance) {
return getPointImpl(areaInstance).getExtensions();
}
fun getExtensions(areaInstance: AreaInstance?): Array<T> = getPointImpl(areaInstance).extensions
/**
* @deprecated Use app-level app extension point.
*/
@Deprecated
public @NotNull Stream<T> extensions(@Nullable AreaInstance areaInstance) {
return getPointImpl(areaInstance).getExtensionList().stream();
@Deprecated("Use app-level app extension point.")
fun extensions(areaInstance: AreaInstance?): Stream<T> {
return getPointImpl(areaInstance).extensionList.stream()
}
/**
* @deprecated use {@link #getPoint()} to access application-level extensions and {@link ProjectExtensionPointName#getPoint(AreaInstance)}
* to access project-level and module-level extensions
*/
@Deprecated
public @NotNull ExtensionPoint<@NotNull T> getPoint(@Nullable AreaInstance areaInstance) {
return getPointImpl(areaInstance);
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("""use {@link #getPoint()} to access application-level extensions and {@link ProjectExtensionPointName#getPoint(AreaInstance)}
to access project-level and module-level extensions""")
fun getPoint(areaInstance: AreaInstance?): ExtensionPoint<T> = getPointImpl(areaInstance)
public @NotNull ExtensionPoint<@NotNull T> getPoint() {
return getPointImpl(null);
}
val point: ExtensionPoint<T>
get() = getPointImpl(null)
public @Nullable <V extends T> V findExtension(@NotNull Class<V> instanceOf) {
return getPointImpl(null).findExtension(instanceOf, false, ThreeState.UNSURE);
fun <V : T> findExtension(instanceOf: Class<V>): V? {
return getPointImpl(null).findExtension(instanceOf, false, ThreeState.UNSURE)
}
@ApiStatus.Internal
public <V> @NotNull List<@NotNull T> findExtensions(@NotNull Class<V> instanceOf) {
return getPointImpl(null).findExtensions(instanceOf);
fun <V> findExtensions(instanceOf: Class<V>): List<T> {
return getPointImpl(null).findExtensions(instanceOf)
}
public @NotNull <V extends T> V findExtensionOrFail(@NotNull Class<V> exactClass) {
//noinspection ConstantConditions
return getPointImpl(null).findExtension(exactClass, true, ThreeState.UNSURE);
fun <V : T> findExtensionOrFail(exactClass: Class<V>): V {
return getPointImpl(null).findExtension(exactClass, true, ThreeState.UNSURE)!!
}
public @Nullable <V extends T> V findFirstAssignableExtension(@NotNull Class<V> instanceOf) {
return getPointImpl(null).findExtension(instanceOf, true, ThreeState.NO);
fun <V : T> findFirstAssignableExtension(instanceOf: Class<V>): V? {
return getPointImpl(null).findExtension(instanceOf, true, ThreeState.NO)
}
/**
* Do not use it if there is any extension point listener, because in this case behaviour is not predictable -
* events will be fired during iteration and probably it will be not expected.
* <p>
* events will be fired during iteration, and probably it will be not expected.
*
* Use only for interface extension points, not for bean.
* <p>
*
* Due to internal reasons, there is no easy way to implement hasNext in a reliable manner,
* so, `next` may return `null` (in this case stop iteration).
* <p>
*
* Possible use cases:
* 1. Conditional iteration (no need to create all extensions if iteration will be stopped due to some condition).
* 2. Iterated only once per application (no need to cache extension list internally).
*/
@ApiStatus.Internal
public @NotNull Iterable<T> getIterable() {
return getPointImpl(null);
fun getIterable(): Iterable<T?> = getPointImpl(null)
@ApiStatus.Internal
fun lazySequence(): Sequence<T> {
return getPointImpl(null).iterator().asSequence().filterNotNull()
}
@ApiStatus.Internal
public void processWithPluginDescriptor(@NotNull BiConsumer<? super T, ? super PluginDescriptor> consumer) {
getPointImpl(null).processWithPluginDescriptor(/* shouldBeSorted = */ true, consumer);
fun processWithPluginDescriptor(consumer: BiConsumer<in T, in PluginDescriptor>) {
getPointImpl(null).processWithPluginDescriptor( /* shouldBeSorted = */true, consumer)
}
public void addExtensionPointListener(@NotNull ExtensionPointListener<T> listener, @Nullable Disposable parentDisposable) {
getPointImpl(null).addExtensionPointListener(listener, false, parentDisposable);
fun addExtensionPointListener(listener: ExtensionPointListener<T>, parentDisposable: Disposable?) {
getPointImpl(null).addExtensionPointListener(listener, false, parentDisposable)
}
public void addExtensionPointListener(@NotNull ExtensionPointListener<T> listener) {
getPointImpl(null).addExtensionPointListener(listener, false, null);
fun addExtensionPointListener(listener: ExtensionPointListener<T>) {
getPointImpl(null).addExtensionPointListener(listener, false, null)
}
public void addExtensionPointListener(@NotNull AreaInstance areaInstance,
@NotNull ExtensionPointListener<T> listener) {
getPointImpl(areaInstance).addExtensionPointListener(listener, false, null);
fun addExtensionPointListener(areaInstance: AreaInstance, listener: ExtensionPointListener<T>) {
getPointImpl(areaInstance).addExtensionPointListener(listener, false, null)
}
public void removeExtensionPointListener(@NotNull ExtensionPointListener<T> listener) {
getPointImpl(null).removeExtensionPointListener(listener);
fun removeExtensionPointListener(listener: ExtensionPointListener<T>) {
getPointImpl(null).removeExtensionPointListener(listener)
}
public void addChangeListener(@NotNull Runnable listener, @Nullable Disposable parentDisposable) {
getPointImpl(null).addChangeListener(listener, parentDisposable);
fun addChangeListener(listener: Runnable, parentDisposable: Disposable?) {
getPointImpl(null).addChangeListener(listener, parentDisposable)
}
/**
* Build cache by arbitrary key using provided key to value mapper. Values with the same key merge into list. Return values by key.
* <p>
*
* To exclude extension from cache, return null key.
* <p>
* {@code cacheId} is required because it's dangerous to rely on identity of functional expressions.
*
* `cacheId` is required because it's dangerous to rely on identity of functional expressions.
* JLS doesn't specify whether a new instance is produced or some common instance is reused for lambda expressions (see 15.27.4).
*/
@ApiStatus.Experimental
public <K extends @NotNull Object> @NotNull List<T> getByGroupingKey(@NotNull K key,
@NotNull Class<?> cacheId,
@NotNull Function<@NotNull T, @Nullable K> keyMapper) {
return ExtensionProcessingHelper.INSTANCE.getByGroupingKey(getPointImpl(null), cacheId, key, keyMapper);
fun <K : Any> getByGroupingKey(key: K, cacheId: Class<*>, keyMapper: Function<T, K?>): List<T> {
return getByGroupingKey(point = getPointImpl(null), cacheId = cacheId, key = key, keyMapper = keyMapper)
}
/**
* Build cache by arbitrary key using provided key to value mapper. Return value by key.
* <p>
*
* To exclude extension from cache, return null key.
*/
@ApiStatus.Experimental
public <K extends @NotNull Object> @Nullable T getByKey(@NotNull K key,
@NotNull Class<?> cacheId,
@NotNull Function<@NotNull T, @Nullable K> keyMapper) {
return ExtensionProcessingHelper.INSTANCE.getByKey(getPointImpl(null), key, cacheId, keyMapper);
fun <K : Any> getByKey(key: K, cacheId: Class<*>, keyMapper: Function<T, K?>): T? {
return getByKey(getPointImpl(null), key, cacheId, keyMapper)
}
/**
* Build cache by arbitrary key using provided key to value mapper. Return value by key.
* <p>
*
* To exclude extension from cache, return null key.
*/
@ApiStatus.Experimental
public <K extends @NotNull Object, V extends @NotNull Object> @Nullable V getByKey(@NotNull K key,
@NotNull Class<?> cacheId,
@NotNull Function<@NotNull T, @Nullable K> keyMapper,
@NotNull Function<@NotNull T, @Nullable V> valueMapper) {
return ExtensionProcessingHelper.INSTANCE.getByKey(getPointImpl(null), key, cacheId, keyMapper, valueMapper);
fun <K : Any, V : Any> getByKey(key: K,
cacheId: Class<*>,
keyMapper: Function<T, K?>,
valueMapper: Function<T, V?>): V? {
return getByKey(point = getPointImpl(null), key = key, cacheId = cacheId, keyMapper = keyMapper, valueMapper = valueMapper)
}
@ApiStatus.Experimental
public <K extends @NotNull Object, V extends @NotNull Object> @NotNull V computeIfAbsent(@NotNull K key,
@NotNull Class<?> cacheId,
@NotNull Function<@NotNull K, @NotNull V> valueMapper) {
return ExtensionProcessingHelper.INSTANCE.computeIfAbsent(getPointImpl(null), key, cacheId, valueMapper);
fun <K : Any, V : Any> computeIfAbsent(key: K, cacheId: Class<*>, valueMapper: Function<K, V>): V {
return computeIfAbsent(point = getPointImpl(null), key = key, cacheId = cacheId, valueProducer = valueMapper)
}
/**
* Cache some value per extension point.
*/
@ApiStatus.Experimental
public <V extends @NotNull Object> @NotNull V computeIfAbsent(@NotNull Class<?> cacheId, @NotNull Supplier<@NotNull V> valueMapper) {
return ExtensionProcessingHelper.INSTANCE.computeIfAbsent(getPointImpl(null), cacheId, valueMapper);
fun <V : Any> computeIfAbsent(cacheId: Class<*>, valueMapper: Supplier<V>): V {
return computeIfAbsent(getPointImpl(null), cacheId, valueMapper)
}
}
}
\ No newline at end of file
// Copyright 2000-2022 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 com.intellij.openapi.Disposable;
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
package com.intellij.openapi.extensions
import com.intellij.openapi.Disposable
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.computeSafeIfAny
import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper.findFirstSafe
import com.intellij.util.ThreeState
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.NonNls
import java.util.function.BiConsumer
import java.util.function.Function
import java.util.function.Predicate
import java.util.stream.Stream
/**
* Do not use.
* <p>
*
* Provides access to a project-level or module-level extension point. Since extensions are supposed to be stateless, storing different
* instances of an extension for each project or module just waste the memory and complicates code, so <strong>it's strongly recommended not
* to introduce new project-level and module-level extension points</strong>. If you need to have {@link com.intellij.openapi.project.Project Project}
* or {@link com.intellij.openapi.module.Module Module} instance in some extension's method, just pass it as a parameter and use the default
* instances of an extension for each project or module just waste the memory and complicates code, so **it's strongly recommended not
* to introduce new project-level and module-level extension points**. If you need to have [Project][com.intellij.openapi.project.Project]
* or [Module][com.intellij.openapi.module.Module] instance in some extension's method, just pass it as a parameter and use the default
* application-level extension point.
*/
public final class ProjectExtensionPointName<T> extends BaseExtensionPointName<T> {
public ProjectExtensionPointName(@NotNull @NonNls String name) {
super(name);
}
public @NotNull ExtensionPoint<@NotNull T> getPoint(@NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance);
}
class ProjectExtensionPointName<T : Any>(name: @NonNls String) : BaseExtensionPointName<T>(name) {
fun getPoint(areaInstance: AreaInstance): ExtensionPoint<T> = getPointImpl(areaInstance)
public @NotNull List<T> getExtensions(@NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance).getExtensionList();
}
fun getExtensions(areaInstance: AreaInstance): List<T> = getPointImpl(areaInstance).extensionList
/**
* @deprecated Use {@link #getExtensions(AreaInstance)}
*/
@Deprecated
public @NotNull Stream<T> extensions(@NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance).getExtensionList().stream();
}
@Deprecated("Use {@link #getExtensions(AreaInstance)}", ReplaceWith("getExtensions(areaInstance).stream()"))
fun extensions(areaInstance: AreaInstance): Stream<T> = getPointImpl(areaInstance).extensionList.stream()
public @Nullable <V extends T> V findExtension(@NotNull Class<V> instanceOf, @NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance).findExtension(instanceOf, false, ThreeState.UNSURE);
fun <V : T> findExtension(instanceOf: Class<V>, areaInstance: AreaInstance): V? {
return getPointImpl(areaInstance).findExtension(instanceOf, false, ThreeState.UNSURE)
}
public @NotNull <V extends T> V findExtensionOrFail(@NotNull Class<V> instanceOf, @NotNull AreaInstance areaInstance) {
//noinspection ConstantConditions
return getPointImpl(areaInstance).findExtension(instanceOf, true, ThreeState.UNSURE);
fun <V : T> findExtensionOrFail(instanceOf: Class<V>, areaInstance: AreaInstance): V {
return getPointImpl(areaInstance).findExtension(instanceOf, true, ThreeState.UNSURE)!!
}
public boolean hasAnyExtensions(@NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance).size() != 0;
}
fun hasAnyExtensions(areaInstance: AreaInstance): Boolean = getPointImpl(areaInstance).size() != 0
public @Nullable T findFirstSafe(@NotNull AreaInstance areaInstance, @NotNull Predicate<? super T> predicate) {
return ExtensionProcessingHelper.INSTANCE.findFirstSafe(predicate, getPointImpl(areaInstance));
fun findFirstSafe(areaInstance: AreaInstance, predicate: Predicate<in T>): T? {
return findFirstSafe(predicate, getPointImpl(areaInstance))
}
public @Nullable <R> R computeSafeIfAny(@NotNull AreaInstance areaInstance, @NotNull Function<T, R> processor) {
return ExtensionProcessingHelper.INSTANCE.computeSafeIfAny(processor, getPointImpl(areaInstance));
fun <R> computeSafeIfAny(areaInstance: AreaInstance, processor: Function<T, R?>): R? {
return computeSafeIfAny<T, R>(processor, getPointImpl(areaInstance))
}
public void addExtensionPointListener(@NotNull AreaInstance areaInstance,
@NotNull ExtensionPointListener<T> listener,
@Nullable Disposable parentDisposable) {
getPointImpl(areaInstance).addExtensionPointListener(listener, false, parentDisposable);
fun addExtensionPointListener(areaInstance: AreaInstance, listener: ExtensionPointListener<T>, parentDisposable: Disposable?) {
getPointImpl(areaInstance).addExtensionPointListener(listener, false, parentDisposable)
}
public void addChangeListener(@NotNull AreaInstance areaInstance, @NotNull Runnable listener, @Nullable Disposable parentDisposable) {
getPointImpl(areaInstance).addChangeListener(listener, parentDisposable);
fun addChangeListener(areaInstance: AreaInstance, listener: Runnable, parentDisposable: Disposable?) {
getPointImpl(areaInstance).addChangeListener(listener, parentDisposable)
}
public void processWithPluginDescriptor(@NotNull AreaInstance areaInstance, @NotNull BiConsumer<? super T, ? super PluginDescriptor> consumer) {
getPointImpl(areaInstance).processWithPluginDescriptor(true, consumer);
fun processWithPluginDescriptor(areaInstance: AreaInstance, consumer: BiConsumer<in T, in PluginDescriptor?>) {
getPointImpl(areaInstance).processWithPluginDescriptor(true, consumer)
}
@ApiStatus.Experimental
public @NotNull Iterable<T> getIterable(@NotNull AreaInstance areaInstance) {
return getPointImpl(areaInstance);
}
}
fun getIterable(areaInstance: AreaInstance): Iterable<T?> = getPointImpl(areaInstance)
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
package com.intellij.openapi.extensions.impl
import com.intellij.openapi.extensions.ExtensionPoint
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.progress.ProcessCanceledException
import org.jetbrains.annotations.ApiStatus
import java.util.AbstractMap.SimpleImmutableEntry
......@@ -21,7 +22,7 @@ import java.util.function.Supplier
// It is not only about performance and common sense, but also supporting ability to mock extension list in tests (custom list is set).
@ApiStatus.Internal
object ExtensionProcessingHelper {
fun <T> forEachExtensionSafe(iterable: Iterable<T>, extensionConsumer: Consumer<T>) {
fun <T : Any> forEachExtensionSafe(iterable: Iterable<T?>, extensionConsumer: Consumer<T>) {
for (t in iterable) {
if (t == null) {
break
......@@ -180,4 +181,11 @@ object ExtensionProcessingHelper {
}
return cache
}
}
@ApiStatus.Internal
inline fun <T : Any> ExtensionPointName<T>.findByIdOrFromInstance(id: String, idGetter: (T) -> String?): T? {
val point = point as ExtensionPointImpl<T>
return point.sortedAdapters.firstOrNull { it.orderId == id }?.createInstance(point.componentManager)
?: lazySequence().firstOrNull { idGetter(it) == id }
}
\ No newline at end of file
// Copyright 2000-2019 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.externalSystem.model
import com.intellij.openapi.diagnostic.Logger
......@@ -13,7 +13,7 @@ fun createCacheWriteConfiguration() = WriteConfiguration(allowAnySubTypes = true
private fun createDataClassResolver(log: Logger): (name: String, hostObject: DataNode<*>?) -> Class<*>? {
val projectDataManager = ProjectDataManager.getInstance()
val managerClassLoaders = ExternalSystemManager.EP_NAME.iterable.asSequence()
val managerClassLoaders = ExternalSystemManager.EP_NAME.lazySequence()
.map { it.javaClass.classLoader }
.toSet()
return fun(name: String, hostObject: DataNode<*>?): Class<*>? {
......@@ -30,7 +30,7 @@ private fun createDataClassResolver(log: Logger): (name: String, hostObject: Dat
try {
return classLoader.loadClass(name)
}
catch (e: ClassNotFoundException) {
catch (_: ClassNotFoundException) {
}
}
......
......@@ -272,7 +272,7 @@ class UnlinkedProjectStartupActivity : ProjectPostStartupActivity {
}
}
private inline fun <T> forEachExtensionSafe(point: ExtensionPointName<T>, consumer: (T) -> Unit) {
private inline fun <T : Any> forEachExtensionSafe(point: ExtensionPointName<T>, consumer: (T) -> Unit) {
for (item in point.extensionList) {
try {
consumer(item)
......
// Copyright 2000-2019 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.externalSystem.service.remote
import com.intellij.openapi.externalSystem.ExternalSystemManager
......@@ -28,8 +28,7 @@ class CustomClassDeserializingResolver<S : ExternalSystemExecutionSettings>(
settings: S?,
resolverPolicy: ProjectResolverPolicy?): DataNode<ProjectData>? {
val rawData = rawResolverDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, settings, resolverPolicy) ?: return null
val managerClassLoaders = (ExternalSystemManager.EP_NAME.iterable.asSequence()
+ ProjectDataService.EP_NAME.extensions.asSequence())
val managerClassLoaders = (ExternalSystemManager.EP_NAME.lazySequence() + ProjectDataService.EP_NAME.extensions.asSequence())
.map { it.javaClass.classLoader }
.toSet()
......
......@@ -14,7 +14,6 @@ import com.intellij.facet.mock.MockSubFacetType
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.*
import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.application.impl.coroutineDispatchingContext
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager
import com.intellij.openapi.externalSystem.model.ProjectSystemId
import com.intellij.openapi.externalSystem.model.project.ModuleData
......@@ -765,8 +764,8 @@ class ExternalSystemStorageTest {
@Before
fun registerFacetType() {
WriteAction.runAndWait<RuntimeException> {
FacetType.EP_NAME.getPoint().registerExtension(MockFacetType(), disposableRule.disposable)
FacetType.EP_NAME.getPoint().registerExtension(MockSubFacetType(), disposableRule.disposable)
FacetType.EP_NAME.point.registerExtension(MockFacetType(), disposableRule.disposable)
FacetType.EP_NAME.point.registerExtension(MockSubFacetType(), disposableRule.disposable)
}
}
......
......@@ -32,7 +32,7 @@ class PluginFeatureService : SerializablePersistentStateComponent<PluginFeatureS
val features: Map<String, FeaturePluginList> = emptyMap(),
)
fun <T> collectFeatureMapping(
fun <T : Any> collectFeatureMapping(
featureType: String,
ep: ExtensionPointName<T>,
idMapping: (T) -> String,
......
......@@ -3,7 +3,6 @@ package com.intellij.facet.impl
import com.intellij.ProjectTopics
import com.intellij.facet.*
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.module.Module
......@@ -42,7 +41,7 @@ internal class FacetEventsPublisher(private val project: Project) {
@JvmField
internal val LISTENER_EP = ExtensionPointName<ProjectFacetListenerEP>("com.intellij.projectFacetListener")
private val LISTENER_EP_CACHE_KEY = java.util.function.Function<ProjectFacetListenerEP, String> { it.facetTypeId }
private val LISTENER_EP_CACHE_KEY = java.util.function.Function<ProjectFacetListenerEP, String?> { it.facetTypeId }
private const val ANY_TYPE = "any"
}
......@@ -171,7 +170,7 @@ internal class FacetEventsPublisher(private val project: Project) {
@Suppress("UNCHECKED_CAST")
private inline fun <F : Facet<*>> processListeners(facetType: FacetType<F, *>, action: (ProjectFacetListener<F>) -> Unit) {
for (listenerEP in LISTENER_EP.getByGroupingKey<String>(facetType.stringId, LISTENER_EP_CACHE_KEY::class.java, LISTENER_EP_CACHE_KEY)) {
for (listenerEP in LISTENER_EP.getByGroupingKey(facetType.stringId, LISTENER_EP_CACHE_KEY::class.java, LISTENER_EP_CACHE_KEY)) {
action(listenerEP.listenerInstance as ProjectFacetListener<F>)
}
manuallyRegisteredListeners.filter { it.first == facetType.id }.forEach {
......@@ -181,7 +180,7 @@ internal class FacetEventsPublisher(private val project: Project) {
@Suppress("UNCHECKED_CAST")
private inline fun processListeners(action: (ProjectFacetListener<Facet<*>>) -> Unit) {
for (listenerEP in LISTENER_EP.getByGroupingKey<String>(ANY_TYPE, LISTENER_EP_CACHE_KEY::class.java, LISTENER_EP_CACHE_KEY)) {
for (listenerEP in LISTENER_EP.getByGroupingKey(ANY_TYPE, LISTENER_EP_CACHE_KEY::class.java, LISTENER_EP_CACHE_KEY)) {
action(listenerEP.listenerInstance as ProjectFacetListener<Facet<*>>)
}
manuallyRegisteredListeners.asSequence()
......
// Copyright 2000-2020 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.facet.impl;
import com.intellij.facet.ProjectFacetListener;
......@@ -11,7 +11,7 @@ import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ProjectFacetListenerEP extends LazyExtensionInstance<ProjectFacetListener<?>> implements PluginAware {
public final class ProjectFacetListenerEP extends LazyExtensionInstance<ProjectFacetListener<?>> implements PluginAware {
@Attribute("facet-type")
@RequiredElement
public String myFacetTypeId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment