prefer to not use ExtensionPointName.extensions()

In Kotlin streams should be not used, in Java extensions() maybe not performant if you in any case traverse the whole extension point

GitOrigin-RevId: f9ef0ce23617ffc8c89a4fe6df54142b8f6ca7dc
This commit is contained in:
Vladimir Krivosheev
2022-07-19 14:37:35 +02:00
committed by intellij-monorepo-bot
parent b76c7b7288
commit fe9812cfff
33 changed files with 127 additions and 145 deletions

View File

@@ -88,8 +88,8 @@ public abstract class CompilerReferenceServiceBase<Reader extends CompilerRefere
this.project = project;
myReaderFactory = readerFactory;
myProjectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
myFileTypes = LanguageCompilerRefAdapter.EP_NAME.extensions().flatMap(a -> a.getFileTypes().stream()).collect(Collectors.toSet());
Set<FileType> affectedFileTypes = LanguageCompilerRefAdapter.EP_NAME.extensions().flatMap(a -> a.getAffectedFileTypes().stream()).collect(Collectors.toSet());
myFileTypes = LanguageCompilerRefAdapter.EP_NAME.getExtensionList().stream().flatMap(a -> a.getFileTypes().stream()).collect(Collectors.toSet());
Set<FileType> affectedFileTypes = LanguageCompilerRefAdapter.EP_NAME.getExtensionList().stream().flatMap(a -> a.getAffectedFileTypes().stream()).collect(Collectors.toSet());
myDirtyScopeHolder = new DirtyScopeHolder(project,
affectedFileTypes,
myProjectFileIndex,

View File

@@ -1,4 +1,4 @@
// 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.jarRepository
import com.intellij.openapi.extensions.ExtensionPointName
@@ -30,7 +30,7 @@ interface JarRepositoryAuthenticationDataProvider {
@RequiresBackgroundThread
internal fun obtainAuthenticationData(url: String): ArtifactRepositoryManager.ArtifactAuthenticationData? {
for (extension in JarRepositoryAuthenticationDataProvider.KEY.extensions()) {
for (extension in JarRepositoryAuthenticationDataProvider.KEY.extensionList) {
val authData = extension.provideAuthenticationData(url)
if (authData != null) {
return ArtifactRepositoryManager.ArtifactAuthenticationData(authData.userName, authData.password)

View File

@@ -1,4 +1,4 @@
// 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.jetbrains.jsonSchema.impl;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
@@ -157,7 +157,7 @@ public class JsonSchemaServiceImpl implements JsonSchemaService, ModificationTra
@Nullable
public VirtualFile getDynamicSchemaForFile(@NotNull PsiFile psiFile) {
return ContentAwareJsonSchemaFileProvider.EP_NAME.extensions()
return ContentAwareJsonSchemaFileProvider.EP_NAME.getExtensionList().stream()
.map(provider -> provider.getSchemaFile(psiFile))
.filter(schemaFile -> schemaFile != null)
.findFirst()

View File

@@ -1,4 +1,4 @@
// 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 org.jetbrains.builtInWebServer
import com.github.benmanes.caffeine.cache.CacheLoader
@@ -23,7 +23,6 @@ import com.intellij.util.SmartList
import com.intellij.util.io.exists
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import kotlin.streams.asSequence
private const val cacheSize: Long = 4096 * 4
@@ -143,7 +142,7 @@ class WebServerPathToFileManager(private val project: Project) {
fun getPathInfo(child: VirtualFile): PathInfo? {
var result = virtualFileToPathInfo.getIfPresent(child)
if (result == null) {
result = WebServerRootsProvider.EP_NAME.extensions().asSequence().map { it.getPathInfo(child, project) }.find { it != null }
result = WebServerRootsProvider.EP_NAME.extensionList.asSequence().map { it.getPathInfo(child, project) }.find { it != null }
if (result != null) {
virtualFileToPathInfo.put(child, result)
}

View File

@@ -84,7 +84,7 @@ class ModuleStoreTest {
@Test
fun `must be empty if classpath storage`() {
Assume.assumeTrue("eclipse plugin is not found in classpath",
ClasspathStorageProvider.EXTENSION_POINT_NAME.extensions().anyMatch { it.id == "eclipse" })
ClasspathStorageProvider.EXTENSION_POINT_NAME.extensionList.any { it.id == "eclipse" })
runBlocking<Unit> {
// we must not use VFS here, file must not be created
val moduleFile = tempDirManager.newPath("module", refreshVfs = true).resolve("test.iml")

View File

@@ -136,7 +136,11 @@ fun Project.guessProjectDir() : VirtualFile? {
if (isDefault) {
return null
}
val customBaseDir = BASE_DIRECTORY_SUGGESTER_EP_NAME.extensions().map { it.suggestBaseDirectory(this) }.filter(Objects::nonNull).findFirst().orElse(null)
val customBaseDir = BASE_DIRECTORY_SUGGESTER_EP_NAME.extensionList.asSequence()
.map { it.suggestBaseDirectory(this) }
.filterNotNull()
.firstOrNull()
if (customBaseDir != null) {
return customBaseDir
}

View File

@@ -1,10 +1,9 @@
// 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.codeInsight.hints
import com.intellij.configurationStore.deserializeInto
import com.intellij.configurationStore.serialize
import com.intellij.lang.Language
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.SettingsCategory
@@ -231,16 +230,11 @@ class InlayHintsSettings : PersistentStateComponent<InlayHintsSettings.State> {
}
private fun computeIsEnabledByDefault(id: String) : Boolean {
val bean = InlayHintsProviderExtension.inlayProviderName.extensions()
.filter { val keyId = it.settingsKeyId
if (keyId == null) {
return@filter false
}
val bean = InlayHintsProviderExtension.inlayProviderName.extensionList
.firstOrNull {
val keyId = it.settingsKeyId ?: return@firstOrNull false
SettingsKey.getFullId(it.language!!, keyId) == id
}
.findAny()
.orElse(null)
if (bean == null) return true
} ?: return true
return bean.isEnabledByDefault
}

View File

@@ -1,10 +1,10 @@
// 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.codeInsight.hints
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.psi.PsiFile
internal val PARAMETER_HINTS_SUPPRESSORS_EP = ExtensionPointName.create<ParameterNameHintsSuppressor>("com.intellij.codeInsight.parameterNameHintsSuppressor")
internal val PARAMETER_HINTS_SUPPRESSORS_EP = ExtensionPointName<ParameterNameHintsSuppressor>("com.intellij.codeInsight.parameterNameHintsSuppressor")
/**
* Allows programmatic suppression of parameter hints in specific places.
@@ -15,7 +15,8 @@ interface ParameterNameHintsSuppressor {
fun isSuppressedFor(file: PsiFile, inlayInfo: InlayInfo): Boolean
companion object All {
fun isSuppressedFor(file: PsiFile, inlayInfo: InlayInfo): Boolean =
PARAMETER_HINTS_SUPPRESSORS_EP.extensions().anyMatch { it.isSuppressedFor(file, inlayInfo) }
fun isSuppressedFor(file: PsiFile, inlayInfo: InlayInfo): Boolean {
return PARAMETER_HINTS_SUPPRESSORS_EP.extensionList.any { it.isSuppressedFor(file, inlayInfo) }
}
}
}

View File

@@ -353,7 +353,7 @@ private class EditorCodeEditingConfigurable : BoundCompositeConfigurable<ErrorOp
row { checkBox(cdShowQuickDocOnMouseMove) }
}
}
if (!EditorOptionsPageCustomizer.EP_NAME.extensions().anyMatch { it.shouldHideRefactoringsSection() }) {
if (!EditorOptionsPageCustomizer.EP_NAME.extensionList.any { it.shouldHideRefactoringsSection() }) {
group(message("group.refactorings")) {
buttonsGroup(message("radiogroup.rename.local.variables")) {
row { radioButton(message("radiobutton.rename.local.variables.inplace"), value = true) }

View File

@@ -1,11 +1,8 @@
// Copyright 2000-2022 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.codeInsight.codeVision
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project
import java.util.stream.Stream
import kotlin.streams.toList
/**
* Factory allows creating programmatically [CodeVisionProvider] for the given project.
@@ -13,14 +10,12 @@ import kotlin.streams.toList
interface CodeVisionProviderFactory {
companion object {
const val EP_NAME = "com.intellij.codeInsight.codeVisionProviderFactory"
val extensionPoint = ExtensionPointName.create<CodeVisionProviderFactory>(EP_NAME)
val extensionPoint = ExtensionPointName<CodeVisionProviderFactory>(EP_NAME)
fun createAllProviders(project: Project): List<CodeVisionProvider<*>> {
return extensionPoint.extensions()
.flatMap { it.createProviders(project) }
.toList()
return extensionPoint.extensionList.flatMap { it.createProviders(project) }
}
}
fun createProviders(project: Project): Stream<CodeVisionProvider<*>>
fun createProviders(project: Project): Sequence<CodeVisionProvider<*>>
}

View File

@@ -1,11 +1,10 @@
// 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.codeInsight.codeVision
import com.intellij.openapi.project.Project
import java.util.stream.Stream
class DefaultCodeVisionProviderFactory : CodeVisionProviderFactory {
override fun createProviders(project: Project): Stream<CodeVisionProvider<*>> {
return CodeVisionProvider.providersExtensionPoint.extensions()
internal class DefaultCodeVisionProviderFactory : CodeVisionProviderFactory {
override fun createProviders(project: Project): Sequence<CodeVisionProvider<*>> {
return CodeVisionProvider.providersExtensionPoint.extensionList.asSequence()
}
}

View File

@@ -23,7 +23,6 @@ import com.intellij.psi.presentation.java.SymbolPresentationUtil
import com.intellij.util.Processor
import org.jetbrains.annotations.TestOnly
import java.awt.Component
import kotlin.streams.asSequence
open class ShowTypeDefinitionAction : ShowRelatedElementsActionBase() {
override fun getActionUpdateThread(): ActionUpdateThread {
@@ -90,7 +89,7 @@ open class ShowTypeDefinitionAction : ShowRelatedElementsActionBase() {
private fun searchTypeDefinitions(element: PsiElement): List<PsiImplementationViewElement> {
val search = ThrowableComputable<List<PsiElement>, Exception> {
TypeDeclarationProvider.EP_NAME.extensions().asSequence()
TypeDeclarationProvider.EP_NAME.extensionList.asSequence()
.mapNotNull { provider ->
ReadAction.compute<List<PsiElement>?, Throwable> {
provider.getSymbolTypeDeclarations(element)?.mapNotNull { it?.navigationElement }
@@ -101,7 +100,7 @@ open class ShowTypeDefinitionAction : ShowRelatedElementsActionBase() {
}
val message = CodeInsightBundle.message("searching.for.definitions")
val definitions = ProgressManager.getInstance().runProcessWithProgressSynchronously(search, message, true, element.project)
return definitions.map { PsiImplementationViewElement(it) }
return definitions.map(::PsiImplementationViewElement)
}
}
}

View File

@@ -40,7 +40,7 @@ class InlayProviderUsageCollector : ProjectUsagesCollector() {
models.add("oc.type.hints")
models.add("tms.local.md.hints")
for (extension in InlayHintsProviderFactory.EP.extensions()) {
for (extension in InlayHintsProviderFactory.EP.extensionList) {
LOG.debug("JavaClass in InlayHintsProviderFactory is ${extension.javaClass.canonicalName}")
for (providersInfo in extension.getProvidersInfo()) {
LOG.debug("Value for 'model' in InlayHintsProviderFactory is ${providersInfo.provider.key.id}")
@@ -66,8 +66,7 @@ class InlayProviderUsageCollector : ProjectUsagesCollector() {
override val validationRule: List<String>
get() {
val options = ArrayList<String>()
val languagesWithSupport = PARAMETER_NAME_HINTS_EP.extensions().map { it.language }
for (languageId in languagesWithSupport) {
for (languageId in PARAMETER_NAME_HINTS_EP.extensionList.map { it.language }) {
LOG.debug("LanguageId in PARAMETER_NAME_HINTS_EP is ${languageId}")
val language = Language.findLanguageByID(languageId)
if (language != null) {

View File

@@ -22,7 +22,6 @@ import com.intellij.util.Processor
import com.jetbrains.rd.util.reactive.adviseUntil
import org.jetbrains.annotations.ApiStatus.Internal
import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Collectors
/**
* Prepares data for [com.intellij.codeInsight.codeVision.CodeVisionHost].
@@ -89,9 +88,8 @@ class CodeVisionPass(
override fun doCollectInformation(progress: ProgressIndicator) {
val settings = CodeVisionSettings.instance()
val providers = DaemonBoundCodeVisionProvider.extensionPoint.extensions()
val providers = DaemonBoundCodeVisionProvider.extensionPoint.extensionList
.filter { settings.isProviderEnabled(it.groupId) }
.collect(Collectors.toList())
collect(progress, editor, myFile, providerIdToLenses, providers)
}

View File

@@ -1,13 +1,12 @@
// 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.codeInsight.hints.codeVision
import com.intellij.codeInsight.codeVision.CodeVisionProvider
import com.intellij.codeInsight.codeVision.CodeVisionProviderFactory
import com.intellij.openapi.project.Project
import java.util.stream.Stream
class DaemonBoundCodeVisionProviderFactory : CodeVisionProviderFactory {
override fun createProviders(project: Project): Stream<CodeVisionProvider<*>> {
return DaemonBoundCodeVisionProvider.extensionPoint.extensions().map { CodeVisionProviderAdapter(it) }
internal class DaemonBoundCodeVisionProviderFactory : CodeVisionProviderFactory {
override fun createProviders(project: Project): Sequence<CodeVisionProvider<*>> {
return DaemonBoundCodeVisionProvider.extensionPoint.extensionList.asSequence().map(::CodeVisionProviderAdapter)
}
}

View File

@@ -1,14 +1,17 @@
// 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.codeInsight.hints.settings
import com.intellij.codeInsight.hints.*
import com.intellij.codeInsight.hints.InlayHintsProviderFactory
import com.intellij.codeInsight.hints.InlayHintsSettings
import com.intellij.codeInsight.hints.InlayParameterHintsExtension
import com.intellij.codeInsight.hints.settings.language.SingleLanguageInlayHintsConfigurable
import com.intellij.codeInsight.hints.withSettings
import com.intellij.ide.ui.search.SearchableOptionContributor
import com.intellij.ide.ui.search.SearchableOptionProcessor
private class InlayHintsSettingsSearchableContributor : SearchableOptionContributor() {
override fun processOptions(processor: SearchableOptionProcessor) {
for (providerInfo in InlayHintsProviderFactory.EP.extensions().flatMap { it.getProvidersInfo().stream() }) {
for (providerInfo in InlayHintsProviderFactory.EP.extensionList.flatMap(InlayHintsProviderFactory::getProvidersInfo)) {
val provider = providerInfo.provider
val name = provider.name
val id = SingleLanguageInlayHintsConfigurable.getId(providerInfo.language)

View File

@@ -51,9 +51,7 @@ final class UnindexedFilesFinder {
myFileBasedIndex = fileBasedIndex;
myFileTypeIndex = fileBasedIndex.getIndex(FileTypeIndex.NAME);
myStateProcessors = FileBasedIndexInfrastructureExtension
.EP_NAME
.extensions()
myStateProcessors = FileBasedIndexInfrastructureExtension.EP_NAME.getExtensionList().stream()
.map(ex -> ex.createFileIndexingStatusProcessor(project))
.filter(Objects::nonNull)
.collect(Collectors.toList());

View File

@@ -301,13 +301,10 @@ public final class ChangedFilesCollector extends IndexedFilesListener {
RegisteredIndexes registeredIndexes = myFileBasedIndex.getRegisteredIndexes();
List<ID<?, ?>> contentDependentIndexes;
if (registeredIndexes == null) {
Set<? extends ID<?, ?>> allContentDependentIndexes =
FileBasedIndexExtension
.EXTENSION_POINT_NAME
.extensions()
.filter(ex -> ex.dependsOnFileContent())
.map(ex -> ex.getName())
.collect(Collectors.toSet());
Set<? extends ID<?, ?>> allContentDependentIndexes = FileBasedIndexExtension.EXTENSION_POINT_NAME.getExtensionList().stream()
.filter(ex -> ex.dependsOnFileContent())
.map(ex -> ex.getName())
.collect(Collectors.toSet());
contentDependentIndexes = ContainerUtil.filter(indexedStates, id -> !allContentDependentIndexes.contains(id));
}
else {

View File

@@ -1,4 +1,4 @@
// 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.ide.browsers.actions
import com.intellij.icons.AllIcons
@@ -30,7 +30,7 @@ internal class BaseOpenInBrowserAction(private val browser: WebBrowser) : DumbAw
@JvmStatic
fun doUpdate(event: AnActionEvent): OpenInBrowserRequest? {
val request = createRequest(event.dataContext, isForceFileUrlIfNoUrlProvider = false)
val applicable = request != null && WebBrowserServiceImpl.getProviders(request).findAny().isPresent
val applicable = request != null && WebBrowserServiceImpl.getProviders(request).any()
event.presentation.isEnabledAndVisible = applicable
return if (applicable) request else null
}

View File

@@ -1,4 +1,4 @@
// 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.ide.browsers.impl
import com.intellij.ide.browsers.*
@@ -10,15 +10,14 @@ import com.intellij.util.Url
import com.intellij.util.Urls
import com.intellij.util.containers.ContainerUtil
import java.util.*
import java.util.stream.Stream
private val URL_PROVIDER_EP = ExtensionPointName<WebBrowserUrlProvider>("com.intellij.webBrowserUrlProvider")
class WebBrowserServiceImpl : WebBrowserService() {
companion object {
fun getProviders(request: OpenInBrowserRequest): Stream<WebBrowserUrlProvider> {
fun getProviders(request: OpenInBrowserRequest): Sequence<WebBrowserUrlProvider> {
val dumbService = DumbService.getInstance(request.project)
return URL_PROVIDER_EP.extensions().filter {
return URL_PROVIDER_EP.extensionList.asSequence().filter {
(!dumbService.isDumb || DumbService.isDumbAware(it)) && it.canHandleElement(request)
}
}
@@ -34,8 +33,9 @@ class WebBrowserServiceImpl : WebBrowserService() {
request.isAppendAccessToken = false
request.reloadMode = ReloadMode.DISABLED
return getProviders(request)
.map { getUrls(it, request) }
.filter(Collection<*>::isNotEmpty).findFirst().orElse(Collections.emptyList())
.map { getUrls(it, request) }
.filter(Collection<*>::isNotEmpty).firstOrNull()
?: emptyList()
}
}
catch (ignored: WebBrowserUrlProvider.BrowserException) {

View File

@@ -1,4 +1,4 @@
// 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.openapi.keymap.impl.ui;
import com.intellij.icons.AllIcons;
@@ -89,7 +89,7 @@ public final class ActionsTreeUtil {
.unique().toList();
for (PluginId pluginId : pluginsIds) {
if (PluginManagerCore.CORE_ID.equals(pluginId)
|| KeymapExtension.EXTENSION_POINT_NAME.extensions().anyMatch(e -> e.skipPluginGroup(pluginId))) {
|| KeymapExtension.EXTENSION_POINT_NAME.getExtensionList().stream().anyMatch(e -> e.skipPluginGroup(pluginId))) {
continue;
}
String[] pluginActions = actionManager.getPluginActions(pluginId);

View File

@@ -33,7 +33,6 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.concurrent.atomic.AtomicBoolean
import java.util.stream.Collectors
@ApiStatus.Internal
class WorkspaceModelCacheImpl(private val project: Project) : Disposable, WorkspaceModelCache {
@@ -213,12 +212,10 @@ class WorkspaceModelCacheImpl(private val project: Project) : Disposable, Worksp
}
}
private val WORKSPACE_MODEL_CACHE_VERSION_EP = ExtensionPointName.create<WorkspaceModelCacheVersion>("com.intellij.workspaceModel.cache.version")
private val WORKSPACE_MODEL_CACHE_VERSION_EP = ExtensionPointName<WorkspaceModelCacheVersion>("com.intellij.workspaceModel.cache.version")
fun collectExternalCacheVersions(): Map<String, String> {
return WORKSPACE_MODEL_CACHE_VERSION_EP
.extensions()
.collect(Collectors.toMap(WorkspaceModelCacheVersion::getId, WorkspaceModelCacheVersion::getVersion))
return WORKSPACE_MODEL_CACHE_VERSION_EP.extensionList.associate { it.getId() to it.getVersion() }
}
fun forceEnableCaching(disposable: Disposable) {

View File

@@ -1,7 +1,6 @@
// 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.workspaceModel.ide.impl.jps.serialization
import com.intellij.diagnostic.AttachmentFactory
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.extensions.ExtensionPointName
@@ -15,7 +14,6 @@ import com.intellij.util.io.exists
import com.intellij.workspaceModel.ide.*
import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryNameGenerator
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl
import com.intellij.workspaceModel.ide.impl.virtualFile
import com.intellij.workspaceModel.storage.*
import com.intellij.workspaceModel.storage.bridgeEntities.*
import com.intellij.workspaceModel.storage.bridgeEntities.api.*
@@ -31,7 +29,6 @@ import org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer
import org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.*
import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer.*
import org.jetbrains.jps.util.JpsPathUtil
import com.intellij.workspaceModel.storage.bridgeEntities.api.modifyEntity
import java.io.StringReader
import java.nio.file.Path
import java.util.*
@@ -101,7 +98,7 @@ internal open class ModuleImlFileEntitiesSerializer(internal val modulePath: Mod
externalSystemId = pair.second
customRootsSerializer = moduleOptions[JpsProjectLoader.CLASSPATH_ATTRIBUTE]?.let { customSerializerId ->
val serializer = CustomModuleRootsSerializer.EP_NAME.extensions().filter { it.id == customSerializerId }.findAny().orElse(null)
val serializer = CustomModuleRootsSerializer.EP_NAME.extensionList.firstOrNull { it.id == customSerializerId }
if (serializer == null) {
errorReporter.reportError(ProjectModelBundle.message("error.message.unknown.classpath.provider", fileUrl.fileName, customSerializerId), fileUrl)
}
@@ -144,7 +141,7 @@ internal open class ModuleImlFileEntitiesSerializer(internal val modulePath: Mod
builder.addModuleCustomImlDataEntity(null, customModuleOptions, moduleEntity, entitySource)
}
CUSTOM_MODULE_COMPONENT_SERIALIZER_EP.extensions().forEach {
CUSTOM_MODULE_COMPONENT_SERIALIZER_EP.extensionList.forEach {
it.loadComponent(builder, moduleEntity, reader, fileUrl, errorReporter, virtualFileManager)
}
// Don't forget to load external system options even if custom root serializer exist
@@ -388,7 +385,7 @@ internal open class ModuleImlFileEntitiesSerializer(internal val modulePath: Mod
val moduleOptions = customImlData?.customModuleOptions
val customSerializerId = moduleOptions?.get(JpsProjectLoader.CLASSPATH_ATTRIBUTE)
if (customSerializerId != null) {
val serializer = CustomModuleRootsSerializer.EP_NAME.extensions().filter { it.id == customSerializerId }.findAny().orElse(null)
val serializer = CustomModuleRootsSerializer.EP_NAME.extensionList.firstOrNull { it.id == customSerializerId }
if (serializer != null) {
val customDir = moduleOptions[JpsProjectLoader.CLASSPATH_DIR_ATTRIBUTE]
serializer.saveRoots(module, entities, writer, customDir, fileUrl, storage, virtualFileManager)
@@ -401,7 +398,7 @@ internal open class ModuleImlFileEntitiesSerializer(internal val modulePath: Mod
else {
saveRootManagerElement(module, customImlData, entities, writer)
}
CUSTOM_MODULE_COMPONENT_SERIALIZER_EP.extensions().forEach {
for (it in CUSTOM_MODULE_COMPONENT_SERIALIZER_EP.extensionList) {
it.saveComponent(module, fileUrl, writer)
}
}

View File

@@ -8,14 +8,13 @@ import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.extensions.Extensions
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.TestOnly
import kotlin.streams.toList
@ApiStatus.Internal
interface ExperimentModelProvider : RankingModelProvider {
fun experimentGroupNumber(): Int
companion object {
private val EP_NAME: ExtensionPointName<RankingModelProvider> = ExtensionPointName("com.intellij.completion.ml.model")
private val EP_NAME = ExtensionPointName<RankingModelProvider>("com.intellij.completion.ml.model")
@JvmStatic
fun findProvider(language: Language, groupNumber: Int): RankingModelProvider? {
@@ -35,11 +34,11 @@ interface ExperimentModelProvider : RankingModelProvider {
fun RankingModelProvider.match(language: Language, groupNumber: Int): Boolean =
isLanguageSupported(language) && (this !is ExperimentModelProvider || experimentGroupNumber() == groupNumber)
fun availableProviders(): List<RankingModelProvider> = EP_NAME.extensions().toList()
fun availableProviders(): List<RankingModelProvider> = EP_NAME.extensionList
@JvmStatic
fun enabledByDefault(): List<String> {
return availableProviders().filter { it.isEnabledByDefault }.map { it.id }.toList()
return availableProviders().asSequence().filter { it.isEnabledByDefault }.map { it.id }.toList()
}
@TestOnly

View File

@@ -36,7 +36,6 @@ import org.intellij.plugins.markdown.ui.preview.PreviewStaticServer
import org.intellij.plugins.markdown.ui.preview.ResourceProvider
import org.intellij.plugins.markdown.ui.preview.html.MarkdownUtil
import java.util.concurrent.ConcurrentHashMap
import kotlin.streams.asSequence
internal class CommandRunnerExtension(val panel: MarkdownHtmlPanel,
private val provider: Provider)
@@ -296,7 +295,7 @@ internal class CommandRunnerExtension(val panel: MarkdownHtmlPanel,
val dataContext = createDataContext(project, localSession, workingDirectory)
return runReadAction {
RunAnythingProvider.EP_NAME.extensions().asSequence()
RunAnythingProvider.EP_NAME.extensionList.asSequence()
.filter { checkForCLI(it, allowRunConfigurations) }
.any { provider -> provider.findMatchingValue(dataContext, trimmedCmd) != null }
}
@@ -313,7 +312,7 @@ internal class CommandRunnerExtension(val panel: MarkdownHtmlPanel,
val dataContext = createDataContext(project, localSession, workingDirectory, executor)
val trimmedCmd = command.trim()
return runReadAction {
for (provider in RunAnythingProvider.EP_NAME.extensions()) {
for (provider in RunAnythingProvider.EP_NAME.extensionList) {
val value = provider.findMatchingValue(dataContext, trimmedCmd) ?: continue
return@runReadAction TrustedProjectUtil.executeIfTrusted(project) {
RUNNER_EXECUTED.log(project, place, RunnerType.LINE, provider.javaClass)

View File

@@ -18,7 +18,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Actual serialized data of a decorator call.
@@ -98,7 +101,7 @@ public class PyDecoratorCallElementType extends PyStubElementType<PyDecoratorStu
final QualifiedName qualifiedName = stub.getQualifiedName();
if (qualifiedName != null) {
sink.occurrence(PyDecoratorStubIndex.KEY, qualifiedName.toString());
PyCustomDecoratorIndexer.EP_NAME.extensions().forEach(extension -> {
PyCustomDecoratorIndexer.EP_NAME.getExtensionList().forEach(extension -> {
String keyForStub = extension.getKeyForStub(stub);
if (keyForStub != null) {
sink.occurrence(extension.getKey(), keyForStub);

View File

@@ -419,16 +419,18 @@ private fun firstResultWithFallback(results: SortedMap<Priority, MutableList<Psi
/**
* See [https://www.python.org/dev/peps/pep-0561/#type-checker-module-resolution-order].
*/
private fun resolvedElementPriority(element: PsiElement, module: Module?) = when {
isNamespacePackage(element) -> Priority.NAMESPACE_PACKAGE
isUserFile(element, module) -> if (PyiUtil.isPyiFileOfPackage(element)) Priority.USER_STUB else Priority.USER_CODE
isInStubPackage(element) -> Priority.STUB_PACKAGE
isInTypeShed(element) -> Priority.TYPESHED
isInSkeletons(element) -> Priority.SKELETON
PyiUtil.isPyiFileOfPackage(element) -> Priority.PROVIDED_STUB
isInInlinePackage(element, module) -> Priority.INLINE_PACKAGE
isInProvidedSdk(element) -> Priority.THIRD_PARTY_SDK
else -> Priority.OTHER
private fun resolvedElementPriority(element: PsiElement, module: Module?): Priority {
return when {
isNamespacePackage(element) -> Priority.NAMESPACE_PACKAGE
isUserFile(element, module) -> if (PyiUtil.isPyiFileOfPackage(element)) Priority.USER_STUB else Priority.USER_CODE
isInStubPackage(element) -> Priority.STUB_PACKAGE
isInTypeShed(element) -> Priority.TYPESHED
isInSkeletons(element) -> Priority.SKELETON
PyiUtil.isPyiFileOfPackage(element) -> Priority.PROVIDED_STUB
isInInlinePackage(element, module) -> Priority.INLINE_PACKAGE
isInProvidedSdk(element) -> Priority.THIRD_PARTY_SDK
else -> Priority.OTHER
}
}
fun isInSkeletons(element: PsiElement): Boolean {
@@ -438,15 +440,17 @@ fun isInSkeletons(element: PsiElement): Boolean {
}
private fun isInProvidedSdk(element: PsiElement): Boolean =
PyThirdPartySdkDetector.EP_NAME.extensions().anyMatch { it.isInThirdPartySdk(element) }
PyThirdPartySdkDetector.EP_NAME.extensionList.any { it.isInThirdPartySdk(element) }
private fun isUserFile(element: PsiElement, module: Module?) =
module != null &&
element is PsiFileSystemItem &&
element.virtualFile.let { it != null && ModuleUtilCore.moduleContainsFile(module, it, false) }
private fun isUserFile(element: PsiElement, module: Module?): Boolean {
return module != null &&
element is PsiFileSystemItem &&
element.virtualFile.let { it != null && ModuleUtilCore.moduleContainsFile(module, it, false) }
}
private fun isInTypeShed(element: PsiElement) =
PyiUtil.isPyiFileOfPackage(element) && (element as? PsiFileSystemItem)?.virtualFile.let { it != null && PyTypeShed.isInside(it) }
private fun isInTypeShed(element: PsiElement): Boolean {
return PyiUtil.isPyiFileOfPackage(element) && (element as? PsiFileSystemItem)?.virtualFile.let { it != null && PyTypeShed.isInside(it) }
}
/**
* See [https://www.python.org/dev/peps/pep-0561/#type-checker-module-resolution-order].

View File

@@ -1,4 +1,4 @@
// 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.jetbrains.python.newProject
import com.intellij.ide.highlighter.ModuleFileType
@@ -29,7 +29,6 @@ import com.jetbrains.python.sdk.add.PyAddNewVirtualEnvPanel
import com.jetbrains.python.sdk.add.PyAddSdkPanel
import com.jetbrains.python.sdk.pythonSdk
import java.nio.file.Path
import kotlin.streams.toList
/**
* A wizard for creating new pure-Python projects in IntelliJ.
@@ -203,9 +202,7 @@ private class NewEnvironmentStep<P>(parent: P)
PyAddNewVirtualEnvPanel(null, null, sdks, newProjectPath, context),
PyAddNewCondaEnvPanel(null, null, sdks, newProjectPath),
)
val providedPanels = PySdkProvider.EP_NAME.extensions()
.map { it.createNewEnvironmentPanel(null, null, sdks, newProjectPath, context) }
.toList()
val providedPanels = PySdkProvider.EP_NAME.extensionList.map { it.createNewEnvironmentPanel(null, null, sdks, newProjectPath, context) }
val panels = basePanels + providedPanels
return panels
.associateBy { it.envName }

View File

@@ -1,4 +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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.newProject.steps
import com.intellij.openapi.projectRoots.Sdk
@@ -18,11 +18,7 @@ import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer
import java.awt.BorderLayout
import java.awt.event.ItemEvent
import javax.swing.JComboBox
import kotlin.streams.toList
/**
* @author vlan
*/
class PyAddNewEnvironmentPanel(existingSdks: List<Sdk>, newProjectPath: String?, preferredType: String?) : PyAddSdkPanel() {
override val panelName: String get() = com.jetbrains.python.PyBundle.message("python.add.sdk.panel.name.new.environment.using")
override val nameExtensionComponent: JComboBox<PyAddNewEnvPanel>
@@ -95,9 +91,9 @@ class PyAddNewEnvironmentPanel(existingSdks: List<Sdk>, newProjectPath: String?,
val condaPanel = PyAddNewCondaEnvPanel(null, null, existingSdks, newProjectPath)
val venvPanel = PyAddNewVirtualEnvPanel(null, null, existingSdks, newProjectPath, context)
val envPanelsFromProviders = PySdkProvider.EP_NAME.extensions()
val envPanelsFromProviders = PySdkProvider.EP_NAME.extensionList
.map { it.createNewEnvironmentPanel(null, null, existingSdks, newProjectPath, context) }
.toList().toTypedArray()
.toTypedArray()
return if (PyCondaSdkCustomizer.instance.preferCondaEnvironments) {
listOf(condaPanel, venvPanel, *envPanelsFromProviders)

View File

@@ -1,11 +1,10 @@
// 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 org.jetbrains.uast.analysis
import com.intellij.lang.Language
import com.intellij.openapi.extensions.ExtensionPointName
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.uast.UExpression
import kotlin.streams.asSequence
/**
* Extension which allows to provide additional information (facts) about UAST expressions which could be used in analysis for all UAST languages.
@@ -16,7 +15,7 @@ interface UastAnalysisPlugin {
private val extensionPointName = ExtensionPointName<UastAnalysisPlugin>("org.jetbrains.uast.analysis.uastAnalysisPlugin")
@JvmStatic
fun byLanguage(language: Language) = extensionPointName.extensions().asSequence().firstOrNull { it.language == language }
fun byLanguage(language: Language) = extensionPointName.extensionList.firstOrNull { it.language == language }
}
/**

View File

@@ -9,7 +9,6 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.uast.*
import kotlin.streams.asSequence
/**
* Extensions which provides code generation support for generating UAST expressions.
@@ -22,7 +21,7 @@ interface UastCodeGenerationPlugin {
private val extensionPointName = ExtensionPointName<UastCodeGenerationPlugin>("org.jetbrains.uast.generate.uastCodeGenerationPlugin")
@JvmStatic
fun byLanguage(language: Language) = extensionPointName.extensions().asSequence().firstOrNull { it.language == language }
fun byLanguage(language: Language) = extensionPointName.extensionList.asSequence().firstOrNull { it.language == language }
}
/**

View File

@@ -1,17 +1,20 @@
// 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.openapi.editor;
import com.intellij.lang.Language;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.ApiStatus;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
public interface XmlTypedHandlersAdditionalSupport {
ExtensionPointName<XmlTypedHandlersAdditionalSupport> EP_NAME = new ExtensionPointName<>("com.intellij.xml.xmlTypedHandlersAdditionalSupport");
static boolean supportsTypedHandlers(@NotNull PsiFile psiFile) {
return EP_NAME.hasAnyExtensions() && EP_NAME.extensions().anyMatch(supporter -> {
if (!EP_NAME.hasAnyExtensions()) {
return false;
}
return ContainerUtil.exists(EP_NAME.getExtensionList(), supporter -> {
for (Language language : psiFile.getViewProvider().getLanguages()) {
if (supporter.isAvailable(psiFile, language)) return true;
}
@@ -20,7 +23,10 @@ public interface XmlTypedHandlersAdditionalSupport {
}
static boolean supportsTypedHandlers(@NotNull PsiFile psiFile, @NotNull Language lang) {
return EP_NAME.hasAnyExtensions() && EP_NAME.extensions().anyMatch(supporter -> supporter.isAvailable(psiFile, lang));
if (!EP_NAME.hasAnyExtensions()) {
return false;
}
return ContainerUtil.exists(EP_NAME.getExtensionList(), supporter -> supporter.isAvailable(psiFile, lang));
}
boolean isAvailable(@NotNull PsiFile psiFile, @NotNull Language lang);

View File

@@ -1,4 +1,4 @@
// 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.html.embedding
import com.intellij.lang.HtmlScriptContentProvider
@@ -31,16 +31,15 @@ interface HtmlEmbeddedContentSupport {
companion object {
@JvmField
@ApiStatus.Internal
val EP_NAME: ExtensionPointName<HtmlEmbeddedContentSupport> = ExtensionPointName.create(
"com.intellij.html.embeddedContentSupport")
val EP_NAME: ExtensionPointName<HtmlEmbeddedContentSupport> = ExtensionPointName("com.intellij.html.embeddedContentSupport")
fun getContentSupports(): @NotNull Stream<HtmlEmbeddedContentSupport> {
return EP_NAME.extensions()
return EP_NAME.extensionList.stream()
}
@JvmStatic
fun getStyleTagEmbedmentInfo(language: Language): HtmlEmbedmentInfo? =
if (LanguageUtil.isInjectableLanguage(language))
fun getStyleTagEmbedmentInfo(language: Language): HtmlEmbedmentInfo? {
return if (LanguageUtil.isInjectableLanguage(language))
EmbeddedTokenTypesProvider.getProviders()
.map { it.elementType }
.filter { language.`is`(it.language) }
@@ -49,10 +48,11 @@ interface HtmlEmbeddedContentSupport {
}
.firstOrNull()
else null
}
@JvmStatic
fun getScriptTagEmbedmentInfo(language: Language): HtmlEmbedmentInfo? =
if (LanguageUtil.isInjectableLanguage(language))
fun getScriptTagEmbedmentInfo(language: Language): HtmlEmbedmentInfo? {
return if (LanguageUtil.isInjectableLanguage(language))
LanguageHtmlScriptContentProvider.getScriptContentProvider(language)
?.let { provider ->
object: HtmlEmbedmentInfo { // weird debug name
@@ -61,6 +61,7 @@ interface HtmlEmbeddedContentSupport {
}
}
else null
}
/**
* Use this method to register support in ParsingTestCases only