From 72efd72cf0f45a39325e4e9900b42a1476576f2a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sun, 10 Mar 2024 10:17:09 +0100 Subject: [PATCH] reduce the usage of kotlinx-immutable-collections GitOrigin-RevId: f5a8cc34ffff305e2793ea2a109156dcde4014b0 --- .../impl/intellij.java.compiler.impl.iml | 1 + .../elements/PackagingElementFactoryImpl.java | 98 +++++++------------ .../psi/LanguageAnnotationSupport.java | 5 +- json/intellij.json.iml | 1 + .../LightweightJsonSchemaObjectMerger.kt | 1 - platform/core-api/intellij.platform.core.iml | 2 +- .../com/intellij/lang/LanguageExtension.java | 20 ++-- .../intellij/openapi/project/DumbService.kt | 9 +- .../intellij/openapi/util/ClassExtension.java | 4 +- .../openapi/util/KeyedExtensionCollector.java | 11 ++- .../core-impl/intellij.platform.core.impl.iml | 1 - .../ide/plugins/IdeaPluginDescriptorImpl.kt | 6 +- .../plugins/ModuleDependenciesDescriptor.kt | 6 +- .../com/intellij/ide/plugins/ModuleGraph.kt | 5 +- .../intellij/ide/plugins/PluginManagerCore.kt | 13 +-- .../intellij/ide/plugins/PluginSetBuilder.kt | 13 +-- .../src/com/intellij/ide/plugins/XmlReader.kt | 18 ++-- .../intellij/ide/plugins/brokenPluginFile.kt | 6 +- .../FileTypeEditorHighlighterProviders.java | 6 +- .../SyntaxHighlighterLanguageFactory.java | 6 +- .../lang/findUsages/LanguageFindUsages.java | 3 +- .../lang-impl/intellij.platform.lang.impl.iml | 1 + .../intellij.platform.ide.impl.iml | 1 + .../intellij/diagnostic/IdeaFreezeReporter.kt | 6 +- .../diagnostic/PerformanceWatcherImpl.kt | 6 +- .../com/intellij/diagnostic/SamplingTask.kt | 7 +- .../project/UnindexedFilesScannerExecutor.kt | 8 +- .../platform/ide/bootstrap/Java11ShimImpl.kt | 5 +- .../serviceContainer/ComponentManagerImpl.kt | 9 +- .../src/com/intellij/util/containers/util.kt | 26 ++++- .../vcs/impl/CheckinHandlersManagerImpl.kt | 6 +- .../intellij.platform.workspace.jps.tests.iml | 1 + ...ellij.platform.workspace.storage.tests.iml | 1 + .../indices/MavenSystemIndicesManager.kt | 5 +- 34 files changed, 146 insertions(+), 171 deletions(-) diff --git a/java/compiler/impl/intellij.java.compiler.impl.iml b/java/compiler/impl/intellij.java.compiler.impl.iml index 0025a164495c..67db63ddd429 100644 --- a/java/compiler/impl/intellij.java.compiler.impl.iml +++ b/java/compiler/impl/intellij.java.compiler.impl.iml @@ -49,6 +49,7 @@ + diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java index ba117a82c808..fe613bd918ca 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.packaging.impl.elements; import com.intellij.openapi.diagnostic.Logger; @@ -103,39 +103,33 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return toPersistentList(PackagingElementType.EP_NAME.getExtensionList()).addAll(STANDARD_TYPES); } - @NotNull @Override - public PackagingElement createArtifactElement(@NotNull Artifact artifact, @NotNull Project project) { + public @NotNull PackagingElement createArtifactElement(@NotNull Artifact artifact, @NotNull Project project) { return new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact)); } - @NotNull @Override - public PackagingElement createArtifactElement(@NotNull String artifactName, @NotNull Project project) { + public @NotNull PackagingElement createArtifactElement(@NotNull String artifactName, @NotNull Project project) { return new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifactName)); } @Override - @NotNull - public DirectoryPackagingElement createDirectory(@NotNull @NonNls String directoryName) { + public @NotNull DirectoryPackagingElement createDirectory(@NotNull @NonNls String directoryName) { return new DirectoryPackagingElement(directoryName); } - @NotNull @Override - public ArtifactRootElement createArtifactRootElement() { + public @NotNull ArtifactRootElement createArtifactRootElement() { return new ArtifactRootElementImpl(); } @Override - @NotNull - public CompositePackagingElement getOrCreateDirectory(@NotNull CompositePackagingElement parent, @NotNull String relativePath) { + public @NotNull CompositePackagingElement getOrCreateDirectory(@NotNull CompositePackagingElement parent, @NotNull String relativePath) { return getOrCreateDirectoryOrArchive(parent, relativePath, true, false); } - @NotNull @Override - public CompositePackagingElement getOrCreateArchive(@NotNull CompositePackagingElement parent, @NotNull String relativePath) { + public @NotNull CompositePackagingElement getOrCreateArchive(@NotNull CompositePackagingElement parent, @NotNull String relativePath) { return getOrCreateDirectoryOrArchive(parent, relativePath, false, false); } @@ -161,10 +155,9 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { } } - @NotNull - private CompositePackagingElement getOrCreateDirectoryOrArchive(@NotNull CompositePackagingElement root, - @NotNull @NonNls String path, - final boolean directory, boolean addAsFirstChild) { + private @NotNull CompositePackagingElement getOrCreateDirectoryOrArchive(@NotNull CompositePackagingElement root, + @NotNull @NonNls String path, + final boolean directory, boolean addAsFirstChild) { path = StringUtil.trimStart(StringUtil.trimEnd(path, "/"), "/"); if (path.isEmpty()) { return root; @@ -185,43 +178,37 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { } @Override - @NotNull - public PackagingElement createModuleOutput(@NotNull String moduleName, @NotNull Project project) { + public @NotNull PackagingElement createModuleOutput(@NotNull String moduleName, @NotNull Project project) { final ModulePointer pointer = ModulePointerManager.getInstance(project).create(moduleName); return new ProductionModuleOutputPackagingElement(project, pointer); } - @NotNull @Override - public PackagingElement createModuleOutput(@NotNull Module module) { + public @NotNull PackagingElement createModuleOutput(@NotNull Module module) { final ModulePointer modulePointer = ModulePointerManager.getInstance(module.getProject()).create(module); return new ProductionModuleOutputPackagingElement(module.getProject(), modulePointer); } - @NotNull @Override - public PackagingElement createModuleSource(@NotNull Module module) { + public @NotNull PackagingElement createModuleSource(@NotNull Module module) { final ModulePointer modulePointer = ModulePointerManager.getInstance(module.getProject()).create(module); return new ProductionModuleSourcePackagingElement(module.getProject(), modulePointer); } - @NotNull @Override - public PackagingElement createTestModuleOutput(@NotNull String moduleName, @NotNull Project project) { + public @NotNull PackagingElement createTestModuleOutput(@NotNull String moduleName, @NotNull Project project) { ModulePointer pointer = ModulePointerManager.getInstance(project).create(moduleName); return new TestModuleOutputPackagingElement(project, pointer); } - @NotNull @Override - public PackagingElement createTestModuleOutput(@NotNull Module module) { + public @NotNull PackagingElement createTestModuleOutput(@NotNull Module module) { ModulePointer pointer = ModulePointerManager.getInstance(module.getProject()).create(module); return new TestModuleOutputPackagingElement(module.getProject(), pointer); } - @NotNull @Override - public List> createLibraryElements(@NotNull Library library) { + public @NotNull List> createLibraryElements(@NotNull Library library) { final LibraryTable table = library.getTable(); final String libraryName = library.getName(); if (table != null) { @@ -241,9 +228,8 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return elements; } - @NotNull @Override - public List> createLibraryElements(@NotNull LibraryEntity libraryEntity, String moduleName) { + public @NotNull List> createLibraryElements(@NotNull LibraryEntity libraryEntity, String moduleName) { final String libraryType = libraryEntity.getTableId().getLevel(); final String libraryName = libraryEntity.getName(); if (PROJECT_LEVEL.equals(libraryType) || APPLICATION_LEVEL.equals(libraryType)) { @@ -253,26 +239,22 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return Collections.singletonList(createLibraryFiles(libraryName, libraryType, moduleName)); } - @NotNull @Override - public PackagingElement createArtifactElement(@NotNull ArtifactPointer artifactPointer, @NotNull Project project) { + public @NotNull PackagingElement createArtifactElement(@NotNull ArtifactPointer artifactPointer, @NotNull Project project) { return new ArtifactPackagingElement(project, artifactPointer); } - @NotNull @Override - public PackagingElement createLibraryFiles(@NotNull String libraryName, @NotNull String level, String moduleName) { + public @NotNull PackagingElement createLibraryFiles(@NotNull String libraryName, @NotNull String level, String moduleName) { return new LibraryPackagingElement(level, libraryName, moduleName); } @Override - @NotNull - public CompositePackagingElement createArchive(@NotNull @NonNls String archiveFileName) { + public @NotNull CompositePackagingElement createArchive(@NotNull @NonNls String archiveFileName) { return new ArchivePackagingElement(archiveFileName); } - @Nullable - private static PackagingElement findArchiveOrDirectoryByName(@NotNull CompositePackagingElement parent, @NotNull String name) { + private static @Nullable PackagingElement findArchiveOrDirectoryByName(@NotNull CompositePackagingElement parent, @NotNull String name) { for (PackagingElement element : parent.getChildren()) { if (element instanceof ArchivePackagingElement && ((ArchivePackagingElement)element).getArchiveFileName().equals(name) || element instanceof DirectoryPackagingElement && ((DirectoryPackagingElement)element).getDirectoryName().equals(name)) { @@ -282,8 +264,7 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return null; } - @NotNull - public static String suggestFileName(@NotNull CompositePackagingElement parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) { + public static @NotNull String suggestFileName(@NotNull CompositePackagingElement parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) { String name = prefix + suffix; int i = 2; while (findArchiveOrDirectoryByName(parent, name) != null) { @@ -292,39 +273,34 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return name; } - @NotNull @Override - public PackagingElement createDirectoryCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) { + public @NotNull PackagingElement createDirectoryCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) { return createParentDirectories(relativeOutputPath, new DirectoryCopyPackagingElement(filePath)); } @Override - @NotNull - public PackagingElement createExtractedDirectoryWithParentDirectories(@NotNull String jarPath, @NotNull String pathInJar, - @NotNull String relativeOutputPath) { + public @NotNull PackagingElement createExtractedDirectoryWithParentDirectories(@NotNull String jarPath, @NotNull String pathInJar, + @NotNull String relativeOutputPath) { return createParentDirectories(relativeOutputPath, new ExtractedDirectoryPackagingElement(jarPath, pathInJar)); } - @NotNull @Override - public PackagingElement createExtractedDirectory(@NotNull VirtualFile jarEntry) { + public @NotNull PackagingElement createExtractedDirectory(@NotNull VirtualFile jarEntry) { LOG.assertTrue(jarEntry.getFileSystem() instanceof JarFileSystem, "Expected file from JAR but file from " + jarEntry.getFileSystem() + " found"); final String fullPath = jarEntry.getPath(); final int jarEnd = fullPath.indexOf(JarFileSystem.JAR_SEPARATOR); return new ExtractedDirectoryPackagingElement(fullPath.substring(0, jarEnd), fullPath.substring(jarEnd + 1)); } - @NotNull @Override - public PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) { + public @NotNull PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, @NotNull String relativeOutputPath) { return createFileCopyWithParentDirectories(filePath, relativeOutputPath, null); } - @NotNull @Override - public PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, - @NotNull String relativeOutputPath, - @Nullable String outputFileName) { + public @NotNull PackagingElement createFileCopyWithParentDirectories(@NotNull String filePath, + @NotNull String relativeOutputPath, + @Nullable String outputFileName) { return createParentDirectories(relativeOutputPath, createFileCopy(filePath, outputFileName)); } @@ -333,15 +309,13 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { return new FileCopyPackagingElement(filePath, outputFileName); } - @NotNull @Override - public PackagingElement createParentDirectories(@NotNull String relativeOutputPath, @NotNull PackagingElement element) { + public @NotNull PackagingElement createParentDirectories(@NotNull String relativeOutputPath, @NotNull PackagingElement element) { return createParentDirectories(relativeOutputPath, Collections.singletonList(element)).get(0); } - @NotNull @Override - public List> createParentDirectories(@NotNull String relativeOutputPath, @NotNull List> elements) { + public @NotNull List> createParentDirectories(@NotNull String relativeOutputPath, @NotNull List> elements) { relativeOutputPath = StringUtil.trimStart(relativeOutputPath, "/"); if (relativeOutputPath.length() == 0) { return elements; @@ -375,15 +349,13 @@ public final class PackagingElementFactoryImpl extends PackagingElementFactory { } @Override - @NotNull - public List> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, - @NotNull CompositePackagingElement parent) { + public @NotNull List> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, + @NotNull CompositePackagingElement parent) { throw new UnsupportedOperationException("'create' not implemented in " + getClass().getName()); } @Override - @NotNull - public ArtifactRootElement createEmpty(@NotNull Project project) { + public @NotNull ArtifactRootElement createEmpty(@NotNull Project project) { return new ArtifactRootElementImpl(); } } diff --git a/java/java-psi-api/src/com/intellij/psi/LanguageAnnotationSupport.java b/java/java-psi-api/src/com/intellij/psi/LanguageAnnotationSupport.java index 2e0df49df9bd..2afaa44c6932 100644 --- a/java/java-psi-api/src/com/intellij/psi/LanguageAnnotationSupport.java +++ b/java/java-psi-api/src/com/intellij/psi/LanguageAnnotationSupport.java @@ -1,11 +1,8 @@ -// 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.psi; import com.intellij.lang.LanguageExtension; -/** - * @author Serega.Vasiliev - */ public final class LanguageAnnotationSupport extends LanguageExtension { public static final LanguageAnnotationSupport INSTANCE = new LanguageAnnotationSupport(); diff --git a/json/intellij.json.iml b/json/intellij.json.iml index 1f3e058a0f65..34be3c3ace5a 100644 --- a/json/intellij.json.iml +++ b/json/intellij.json.iml @@ -29,5 +29,6 @@ + \ No newline at end of file diff --git a/json/src/com/jetbrains/jsonSchema/impl/light/nodes/LightweightJsonSchemaObjectMerger.kt b/json/src/com/jetbrains/jsonSchema/impl/light/nodes/LightweightJsonSchemaObjectMerger.kt index 1e50447beb47..e1b43349769c 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/light/nodes/LightweightJsonSchemaObjectMerger.kt +++ b/json/src/com/jetbrains/jsonSchema/impl/light/nodes/LightweightJsonSchemaObjectMerger.kt @@ -52,7 +52,6 @@ internal fun mergeSets(first: Set?, second: Set?): Set? { return merged.toImmutableSet() } - internal fun MergedJsonSchemaObjectView.booleanOr(memberReference: JsonSchemaObject.() -> Boolean): Boolean { val first = base.memberReference() if (first) return true diff --git a/platform/core-api/intellij.platform.core.iml b/platform/core-api/intellij.platform.core.iml index 90d771acd57f..8f8bebc70bed 100644 --- a/platform/core-api/intellij.platform.core.iml +++ b/platform/core-api/intellij.platform.core.iml @@ -32,7 +32,7 @@ - + \ No newline at end of file diff --git a/platform/core-api/src/com/intellij/lang/LanguageExtension.java b/platform/core-api/src/com/intellij/lang/LanguageExtension.java index edbc255453c0..14cd93876373 100644 --- a/platform/core-api/src/com/intellij/lang/LanguageExtension.java +++ b/platform/core-api/src/com/intellij/lang/LanguageExtension.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.lang; import com.intellij.openapi.extensions.ExtensionPointName; @@ -17,8 +17,8 @@ import java.util.*; import static kotlinx.collections.immutable.ExtensionsKt.persistentListOf; public class LanguageExtension extends KeyedExtensionCollector { - private final T myDefaultImplementation; - private final /* non static!!! */ Key myCacheKey; + private final T defaultImplementation; + private final /* non static!!! */ Key cacheKey; private final /* non static!!! */ Key> allCacheKey; public LanguageExtension(final @NotNull ExtensionPointName> epName) { @@ -35,8 +35,8 @@ public class LanguageExtension extends KeyedExtensionCollector { public LanguageExtension(@NonNls String epName, @Nullable T defaultImplementation) { super(epName); - myDefaultImplementation = defaultImplementation; - myCacheKey = Key.create("EXTENSIONS_IN_LANGUAGE_" + epName); + this.defaultImplementation = defaultImplementation; + cacheKey = Key.create("EXTENSIONS_IN_LANGUAGE_" + epName); allCacheKey = Key.create("ALL_EXTENSIONS_IN_LANGUAGE_" + epName); } @@ -71,7 +71,7 @@ public class LanguageExtension extends KeyedExtensionCollector { } private void clearCacheForLanguage(@NotNull Language language) { - language.putUserData(myCacheKey, null); + language.putUserData(cacheKey, null); language.putUserData(allCacheKey, null); super.invalidateCacheForExtension(language.getID()); } @@ -87,12 +87,12 @@ public class LanguageExtension extends KeyedExtensionCollector { } public T forLanguage(@NotNull Language l) { - T cached = l.getUserData(myCacheKey); + T cached = l.getUserData(cacheKey); if (cached != null) return cached; T result = findForLanguage(l); if (result == null) return null; - result = l.putUserDataIfAbsent(myCacheKey, result); + result = l.putUserDataIfAbsent(cacheKey, result); return result; } @@ -103,7 +103,7 @@ public class LanguageExtension extends KeyedExtensionCollector { return extensions.get(0); } } - return myDefaultImplementation; + return defaultImplementation; } /** @@ -163,7 +163,7 @@ public class LanguageExtension extends KeyedExtensionCollector { } protected T getDefaultImplementation() { - return myDefaultImplementation; + return defaultImplementation; } @Override diff --git a/platform/core-api/src/com/intellij/openapi/project/DumbService.kt b/platform/core-api/src/com/intellij/openapi/project/DumbService.kt index 0c68ae91b8a4..4e5269520f0c 100644 --- a/platform/core-api/src/com/intellij/openapi/project/DumbService.kt +++ b/platform/core-api/src/com/intellij/openapi/project/DumbService.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.project import com.intellij.openapi.Disposable @@ -15,13 +15,12 @@ import com.intellij.openapi.util.* import com.intellij.util.ThrowableRunnable import com.intellij.util.concurrency.annotations.RequiresBlockingContext import com.intellij.util.messages.Topic -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toImmutableList import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.ApiStatus.Experimental import org.jetbrains.annotations.ApiStatus.Obsolete import org.jetbrains.annotations.Contract import org.jetbrains.annotations.Unmodifiable +import java.util.* import javax.swing.JComponent /** @@ -195,7 +194,7 @@ abstract class DumbService { } return result } - return if (collection is List<*>) collection as List else collection.toImmutableList() + return if (collection is List<*>) collection as List else collection.toList() } /** @@ -435,7 +434,7 @@ abstract class DumbService { val point = extensionPoint.point val size = point.size() if (size == 0) { - return persistentListOf() + return Collections.emptyList() } if (!getInstance(project).isDumb) { diff --git a/platform/core-api/src/com/intellij/openapi/util/ClassExtension.java b/platform/core-api/src/com/intellij/openapi/util/ClassExtension.java index a9d74eb6ecaf..5bc23b888889 100644 --- a/platform/core-api/src/com/intellij/openapi/util/ClassExtension.java +++ b/platform/core-api/src/com/intellij/openapi/util/ClassExtension.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.util; import com.intellij.util.KeyedLazyInstance; @@ -23,7 +23,7 @@ public class ClassExtension extends KeyedExtensionCollector> { } @Override - protected final @NotNull PersistentList buildExtensions(@NotNull String key, @NotNull Class classKey) { + protected final @NotNull List buildExtensions(@NotNull String key, @NotNull Class classKey) { Set allSupers = new LinkedHashSet<>(); collectSupers(classKey, allSupers); return buildExtensionsWithInheritance(allSupers); diff --git a/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java b/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java index 2e2830a20a9f..88831a08c1ea 100644 --- a/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java +++ b/platform/core-api/src/com/intellij/openapi/util/KeyedExtensionCollector.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.util; import com.intellij.diagnostic.PluginException; @@ -18,6 +18,7 @@ import java.util.function.Predicate; import static com.intellij.util.containers.UtilKt.with; import static com.intellij.util.containers.UtilKt.without; import static kotlinx.collections.immutable.ExtensionsKt.persistentListOf; +import static kotlinx.collections.immutable.ExtensionsKt.toPersistentList; public class KeyedExtensionCollector implements ModificationTracker { private static final Logger LOG = Logger.getInstance(KeyedExtensionCollector.class); @@ -210,10 +211,10 @@ public class KeyedExtensionCollector implements ModificationTracker { } } - protected final @NotNull PersistentList buildExtensions(@NotNull Set keys) { + protected final @NotNull List buildExtensions(@NotNull Set keys) { List> extensions = getExtensions(); synchronized (lock) { - PersistentList explicit = buildExtensionsFromExplicitRegistration(keys::contains); + List explicit = buildExtensionsFromExplicitRegistration(keys::contains); List result = buildExtensionsFromExtensionPoint(bean -> { String key; try { @@ -226,11 +227,11 @@ public class KeyedExtensionCollector implements ModificationTracker { return keys.contains(key); }, extensions); - return explicit.addAll(result); + return toPersistentList(explicit).addAll(result); } } - protected final @NotNull PersistentList buildExtensionsFromExplicitRegistration(@NotNull Predicate isMyBean) { + protected final @NotNull List buildExtensionsFromExplicitRegistration(@NotNull Predicate isMyBean) { PersistentList result = persistentListOf(); for (Map.Entry> entry : explicitExtensions.entrySet()) { String key = entry.getKey(); diff --git a/platform/core-impl/intellij.platform.core.impl.iml b/platform/core-impl/intellij.platform.core.impl.iml index 0c6e76639a33..6141351e0a33 100644 --- a/platform/core-impl/intellij.platform.core.impl.iml +++ b/platform/core-impl/intellij.platform.core.impl.iml @@ -35,7 +35,6 @@ - diff --git a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt index fd0338417078..05ec66615ad9 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt @@ -11,8 +11,6 @@ import com.intellij.openapi.extensions.ExtensionDescriptor import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.extensions.impl.ExtensionPointImpl import com.intellij.util.Java11Shim -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toPersistentList import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.Nls import org.jetbrains.annotations.NonNls @@ -77,7 +75,7 @@ class IdeaPluginDescriptorImpl(raw: RawPluginDescriptor, // https://youtrack.jetbrains.com/issue/IDEA-206274 val list = raw.depends if (list.isNullOrEmpty()) { - pluginDependencies = persistentListOf() + pluginDependencies = Java11Shim.INSTANCE.listOf() } else { val iterator = list.iterator() @@ -93,7 +91,7 @@ class IdeaPluginDescriptorImpl(raw: RawPluginDescriptor, } } } - pluginDependencies = list.toPersistentList() + pluginDependencies = list } } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ModuleDependenciesDescriptor.kt b/platform/core-impl/src/com/intellij/ide/plugins/ModuleDependenciesDescriptor.kt index 6027543a83ae..c7518b3de5db 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ModuleDependenciesDescriptor.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ModuleDependenciesDescriptor.kt @@ -1,8 +1,8 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.plugins import com.intellij.openapi.extensions.PluginId -import kotlinx.collections.immutable.persistentListOf +import com.intellij.util.Java11Shim import org.jetbrains.annotations.ApiStatus import java.util.* @@ -26,7 +26,7 @@ class ModuleDependenciesDescriptor(@JvmField val modules: List, @ApiStatus.Internal class PluginContentDescriptor(@JvmField val modules: List) { companion object { - @JvmField val EMPTY: PluginContentDescriptor = PluginContentDescriptor(persistentListOf()) + @JvmField val EMPTY: PluginContentDescriptor = PluginContentDescriptor(Java11Shim.INSTANCE.listOf()) } @ApiStatus.Internal diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ModuleGraph.kt b/platform/core-impl/src/com/intellij/ide/plugins/ModuleGraph.kt index 1321d5cef05e..518d2303e76b 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ModuleGraph.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ModuleGraph.kt @@ -1,11 +1,10 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet", "ReplaceNegatedIsEmptyWithIsNotEmpty") package com.intellij.ide.plugins import com.intellij.util.graph.DFSTBuilder import com.intellij.util.graph.Graph -import kotlinx.collections.immutable.toPersistentList import org.jetbrains.annotations.ApiStatus import java.util.* @@ -90,7 +89,7 @@ internal fun createModuleGraph(plugins: Collection): M } if (!result.isEmpty()) { - directDependencies.put(module, result.toPersistentList()) + directDependencies.put(module, result.toList()) result.clear() } } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt index 8d3dc950960c..e8d3148f37c7 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt @@ -27,9 +27,6 @@ import com.intellij.util.Java11Shim import com.intellij.util.PlatformUtils import com.intellij.util.lang.UrlClassLoader import com.intellij.util.lang.ZipFilePool -import kotlinx.collections.immutable.persistentSetOf -import kotlinx.collections.immutable.toPersistentMap -import kotlinx.collections.immutable.toPersistentSet import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred @@ -112,7 +109,7 @@ object PluginManagerCore { * Bundled plugins that were updated. * When we update a bundled plugin, it becomes non-bundled, so it is more challenging for analytics to use that data. */ - private var shadowedBundledPlugins: Set = persistentSetOf() + private var shadowedBundledPlugins: Set = Collections.emptySet() private var isRunningFromSources: Boolean? = null @@ -292,7 +289,7 @@ object PluginManagerCore { future.cancel(CancellationException("invalidatePlugins")) } invalidate() - shadowedBundledPlugins = persistentSetOf() + shadowedBundledPlugins = Collections.emptySet() } @ReviseWhenPortedToJDK(value = "10", description = "Collectors.toUnmodifiableList()") @@ -625,7 +622,7 @@ object PluginManagerCore { } val actions = prepareActions(pluginNamesToDisable = pluginsToDisable.values, pluginNamesToEnable = pluginsToEnable.values) - pluginLoadingErrors = pluginErrorsById.toPersistentMap() + pluginLoadingErrors = pluginErrorsById val errorList = preparePluginErrors(globalErrors) if (!errorList.isEmpty()) { @@ -829,7 +826,7 @@ object PluginManagerCore { parentActivity = tracerShim.getTraceActivity()) pluginsToDisable = Java11Shim.INSTANCE.copyOf(initResult.pluginIdsToDisable) pluginsToEnable = Java11Shim.INSTANCE.copyOf(initResult.pluginIdsToEnable) - shadowedBundledPlugins = loadingResult.shadowedBundledIds.toPersistentSet() + shadowedBundledPlugins = loadingResult.shadowedBundledIds //activity.setDescription("plugin count: ${initResult.pluginSet.enabledPlugins.size}") nullablePluginSet = initResult.pluginSet initResult.pluginSet @@ -981,7 +978,7 @@ private fun message(key: @PropertyKey(resourceBundle = CoreBundle.BUNDLE) String Supplier { CoreBundle.message(key!!, *params) } @Synchronized -@ApiStatus.Internal +@Internal fun tryReadPluginIdsFromFile(path: Path, log: Logger): Set { try { return readPluginIdsFromFile(path) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt index dfb55cbec9ca..d5e971e986da 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplaceGetOrSet", "ReplacePutWithAssignment", "ReplaceNegatedIsEmptyWithIsNotEmpty") package com.intellij.ide.plugins @@ -7,9 +7,6 @@ import com.intellij.core.CoreBundle import com.intellij.openapi.extensions.PluginId import com.intellij.util.Java11Shim import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap -import kotlinx.collections.immutable.mutate -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.persistentSetOf import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.Nls import org.jetbrains.annotations.PropertyKey @@ -132,8 +129,8 @@ class PluginSetBuilder(@JvmField val unsortedPlugins: Set): PluginSet { val sortedPlugins = getSortedPlugins() - // ordered - do not use persistentHashSetOf - val allPlugins = persistentSetOf().mutate { result -> + // must be ordered + val allPlugins = LinkedHashSet().also { result -> result.addAll(sortedPlugins) result.addAll(incompletePlugins) } @@ -142,12 +139,12 @@ class PluginSetBuilder(@JvmField val unsortedPlugins: Set().mutate { result -> + enabledPlugins = ArrayList().also { result -> sortedPlugins.filterTo(result) { it.isEnabled } }, enabledModuleMap = java11Shim.copyOf(enabledModuleV2Ids), enabledPluginAndV1ModuleMap = java11Shim.copyOf(enabledPluginIds), - enabledModules = persistentListOf().mutate { result -> + enabledModules = ArrayList().also { result -> for (module in moduleGraph.nodes) { if (if (module.moduleName == null) module.isEnabled else enabledModuleV2Ids.containsKey(module.moduleName)) { result.add(module) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/XmlReader.kt b/platform/core-impl/src/com/intellij/ide/plugins/XmlReader.kt index bf016e56b652..2404957bc151 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/XmlReader.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/XmlReader.kt @@ -12,13 +12,12 @@ import com.intellij.openapi.extensions.ExtensionDescriptor import com.intellij.openapi.extensions.ExtensionPointDescriptor import com.intellij.openapi.extensions.LoadingOrder import com.intellij.openapi.extensions.PluginId +import com.intellij.util.Java11Shim import com.intellij.util.messages.ListenerDescriptor import com.intellij.util.xml.dom.NoOpXmlInterner import com.intellij.util.xml.dom.XmlInterner import com.intellij.util.xml.dom.createNonCoalescingXmlStreamReader import com.intellij.util.xml.dom.readXmlAsModel -import kotlinx.collections.immutable.persistentHashSetOf -import kotlinx.collections.immutable.persistentListOf import org.codehaus.stax2.XMLStreamReader2 import org.codehaus.stax2.typed.TypedXMLStreamException import org.jetbrains.annotations.ApiStatus @@ -171,17 +170,17 @@ private fun readRootAttributes(reader: XMLStreamReader2, descriptor: RawPluginDe /** * Keep in sync with KotlinPluginUtil.KNOWN_KOTLIN_PLUGIN_IDS */ -private val KNOWN_KOTLIN_PLUGIN_IDS = persistentHashSetOf( +private val KNOWN_KOTLIN_PLUGIN_IDS = Java11Shim.INSTANCE.copyOf(listOf( "org.jetbrains.kotlin", "com.intellij.appcode.kmm", "org.jetbrains.kotlin.native.appcode" -) +)) fun isKotlinPlugin(pluginId: PluginId): Boolean { return pluginId.idString in KNOWN_KOTLIN_PLUGIN_IDS } -private val K2_ALLOWED_PLUGIN_IDS = KNOWN_KOTLIN_PLUGIN_IDS.addAll(persistentHashSetOf( +private val K2_ALLOWED_PLUGIN_IDS = Java11Shim.INSTANCE.copyOf(KNOWN_KOTLIN_PLUGIN_IDS + listOf( "fleet.backend.mercury", "fleet.backend.mercury.macos", "fleet.backend.mercury.kotlin.macos", @@ -779,8 +778,8 @@ private fun readContent(reader: XMLStreamReader2, descriptor: RawPluginDescripto } private fun readDependencies(reader: XMLStreamReader2, descriptor: RawPluginDescriptor, readContext: ReadModuleContext) { - var modules = persistentListOf() - var plugins = persistentListOf() + val modules = ArrayList() + val plugins = ArrayList() reader.consumeChildElements { elementName -> when (elementName) { "module" -> { @@ -791,7 +790,7 @@ private fun readDependencies(reader: XMLStreamReader2, descriptor: RawPluginDesc } } - modules = modules.add(ModuleDependenciesDescriptor.ModuleReference(name!!)) + modules.add(ModuleDependenciesDescriptor.ModuleReference(name!!)) } "plugin" -> { var id: String? = null @@ -801,12 +800,13 @@ private fun readDependencies(reader: XMLStreamReader2, descriptor: RawPluginDesc } } - plugins = plugins.add(ModuleDependenciesDescriptor.PluginReference(PluginId.getId(id!!))) + plugins.add(ModuleDependenciesDescriptor.PluginReference(PluginId.getId(id!!))) } else -> throw RuntimeException("Unknown content item type: $elementName") } reader.skipElement() } + descriptor.dependencies = ModuleDependenciesDescriptor(modules, plugins) assert(reader.isEndElement) } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/brokenPluginFile.kt b/platform/core-impl/src/com/intellij/ide/plugins/brokenPluginFile.kt index 33af2c7d15bd..2b35cd53db13 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/brokenPluginFile.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/brokenPluginFile.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplacePutWithAssignment") package com.intellij.ide.plugins @@ -6,8 +6,6 @@ package com.intellij.ide.plugins import com.intellij.openapi.application.PathManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.extensions.PluginId -import kotlinx.collections.immutable.mutate -import kotlinx.collections.immutable.persistentHashSetOf import org.jetbrains.annotations.ApiStatus.Internal import java.io.BufferedInputStream import java.io.BufferedOutputStream @@ -111,7 +109,7 @@ private fun tryReadBrokenPluginsFile(brokenPluginsStorage: Path): Map>(count) for (i in 0 until count) { val pluginId = PluginId.getId(stream.readUTF()) - result.put(pluginId, persistentHashSetOf().mutate { r -> + result.put(pluginId, HashSet().also { r -> repeat(stream.readUnsignedShort()) { r.add(stream.readUTF()) } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/FileTypeEditorHighlighterProviders.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/FileTypeEditorHighlighterProviders.java index 00d96270c7f3..77a717294074 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/FileTypeEditorHighlighterProviders.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/FileTypeEditorHighlighterProviders.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.fileTypes; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -13,8 +13,6 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -import static kotlinx.collections.immutable.ExtensionsKt.persistentListOf; - public final class FileTypeEditorHighlighterProviders extends FileTypeExtension { public static final ExtensionPointName> EP_NAME = ExtensionPointName.create("com.intellij.editorHighlighterProvider"); public static final FileTypeEditorHighlighterProviders INSTANCE = new FileTypeEditorHighlighterProviders(); @@ -40,7 +38,7 @@ public final class FileTypeEditorHighlighterProviders extends FileTypeExtension< SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, virtualFile), colors); } }; - return persistentListOf(defaultProvider); + return List.of(defaultProvider); } return fromEP; } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java index 5260c9f7bd15..6ebd198be376 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.fileTypes; import com.intellij.lang.Language; @@ -12,8 +12,6 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -import static kotlinx.collections.immutable.ExtensionsKt.persistentListOf; - public final class SyntaxHighlighterLanguageFactory extends LanguageExtension { public static final ExtensionPointName> EP_NAME = new ExtensionPointName<>("com.intellij.lang.syntaxHighlighterFactory"); @@ -33,7 +31,7 @@ public final class SyntaxHighlighterLanguageFactory extends LanguageExtension { public static final LanguageFindUsages INSTANCE = new LanguageFindUsages() { @NotNull diff --git a/platform/lang-impl/intellij.platform.lang.impl.iml b/platform/lang-impl/intellij.platform.lang.impl.iml index 0fcced38eb08..aa8efc1bc9fb 100644 --- a/platform/lang-impl/intellij.platform.lang.impl.iml +++ b/platform/lang-impl/intellij.platform.lang.impl.iml @@ -98,5 +98,6 @@ + \ No newline at end of file diff --git a/platform/platform-impl/intellij.platform.ide.impl.iml b/platform/platform-impl/intellij.platform.ide.impl.iml index 0690230687bb..0e622f5b3d17 100644 --- a/platform/platform-impl/intellij.platform.ide.impl.iml +++ b/platform/platform-impl/intellij.platform.ide.impl.iml @@ -144,5 +144,6 @@ + \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.kt b/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.kt index 2eae1a523cbc..7685cffe689e 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.kt +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeaFreezeReporter.kt @@ -128,7 +128,7 @@ internal class IdeaFreezeReporter : PerformanceListener { val edtStack = dump.edtStackTrace if (edtStack != null) { stacktraceCommonPart = if (stacktraceCommonPart == null) { - @Suppress("ReplaceJavaStaticMethodWithKotlinAnalog", "RemoveRedundantQualifierName") + @Suppress("ReplaceJavaStaticMethodWithKotlinAnalog") java.util.List.of(*edtStack) } else { @@ -191,7 +191,7 @@ internal class IdeaFreezeReporter : PerformanceListener { reportDir: Path?, performanceWatcher: PerformanceWatcher, finished: Boolean): IdeaLoggingEvent? { - var infos: List> = dumpTask.threadInfos + var infos = dumpTask.threadInfos.toList() val dumpInterval = (if (infos.isEmpty()) performanceWatcher.dumpInterval else dumpTask.dumpInterval).toLong() if (infos.isEmpty()) { infos = currentDumps.map { it.threadInfos } @@ -314,7 +314,7 @@ private class CallTreeNode(private val stackTraceElement: StackTraceElement?, fun findDominantCommonStack(threshold: Long): CallTreeNode? { var node: CallTreeNode? = getMostHitChild() ?: return null - while (node != null && !node.children.isNullOrEmpty()) { + while (node != null && !node.children.isEmpty()) { val mostHitChild = node.getMostHitChild() if (mostHitChild == null || mostHitChild.time <= threshold) break node = mostHitChild diff --git a/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcherImpl.kt b/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcherImpl.kt index f6a5dac4bc53..be7ff7d38532 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcherImpl.kt +++ b/platform/platform-impl/src/com/intellij/diagnostic/PerformanceWatcherImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplaceGetOrSet", "JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") package com.intellij.diagnostic @@ -451,7 +451,7 @@ private fun postProcessReportFolder(durationMs: Long, task: SamplingTask, dir: P private fun getFreezePlaceSuffix(task: SamplingTask): String { var stacktraceCommonPart: List? = null - for (info in task.threadInfos) { + for (info in task.threadInfos.asIterable()) { val edt = info.firstOrNull(ThreadDumper::isEDT) ?: continue val edtStack = edt.stackTrace ?: continue stacktraceCommonPart = if (stacktraceCommonPart == null) { @@ -466,7 +466,7 @@ private fun getFreezePlaceSuffix(task: SamplingTask): String { return "" } - val element = stacktraceCommonPart[0] + val element = stacktraceCommonPart.first() return "-${sanitizeFileName(StringUtilRt.getShortName(element.className))}.${sanitizeFileName(element.methodName)}" } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/SamplingTask.kt b/platform/platform-impl/src/com/intellij/diagnostic/SamplingTask.kt index 9c6586879577..f93b50d1a2c0 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/SamplingTask.kt +++ b/platform/platform-impl/src/com/intellij/diagnostic/SamplingTask.kt @@ -1,9 +1,8 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.diagnostic +import com.intellij.util.containers.UList import com.sun.management.OperatingSystemMXBean -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.* import java.lang.management.ManagementFactory import java.lang.management.ThreadInfo @@ -14,7 +13,7 @@ import kotlin.time.Duration.Companion.milliseconds internal open class SamplingTask(@JvmField internal val dumpInterval: Int, maxDurationMs: Int, coroutineScope: CoroutineScope) { private val maxDumps: Int = maxDurationMs / dumpInterval - var threadInfos: PersistentList> = persistentListOf() + var threadInfos: UList> = UList() private set private val job: Job? diff --git a/platform/platform-impl/src/com/intellij/openapi/project/UnindexedFilesScannerExecutor.kt b/platform/platform-impl/src/com/intellij/openapi/project/UnindexedFilesScannerExecutor.kt index 81b0bd13c495..87278d807c53 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/UnindexedFilesScannerExecutor.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/UnindexedFilesScannerExecutor.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.project import com.intellij.openapi.Disposable @@ -48,11 +48,11 @@ class UnindexedFilesScannerExecutor(project: Project) thisLogger().debug(Throwable("submit task, thread=${Thread.currentThread()}")) // Two tasks with limited checks should be just run one after another. - // A case of a full check followed by a limited change cancelling first one and making a full check anew results + // A case of a full check followed by a limited change cancelling the first one and making a full check anew results // in endless restart of full checks on Windows with empty Maven cache. // So only in case the second one is a full check should the first one be cancelled. if (task.isFullIndexUpdate()) { - // we don't want to execute any of the existing tasks - the only task we want to execute will be submitted few lines below + // we don't want to execute any of the existing tasks - the only task we want to execute will be submitted the few lines below cancelAllTasks() cancelRunningScannerTaskInDumbQueue() } @@ -90,7 +90,7 @@ class UnindexedFilesScannerExecutor(project: Project) } fun cancelAllTasksAndWait() { - cancelAllTasks() // this also cancels running task even if they paused by ProgressSuspender + cancelAllTasks() // this also cancels a running task even if they paused by ProgressSuspender while (isRunning.value && !project.isDisposed) { PingProgress.interactWithEdtProgress() LockSupport.parkNanos(50_000_000) diff --git a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/Java11ShimImpl.kt b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/Java11ShimImpl.kt index af7c5e70c318..73e42971c821 100644 --- a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/Java11ShimImpl.kt +++ b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/Java11ShimImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.ide.bootstrap import com.intellij.concurrency.ConcurrentCollectionFactory @@ -45,8 +45,7 @@ class Java11ShimImpl : Java11Shim() { 9 -> java.util.List.of(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8]) 10 -> java.util.List.of(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8], array[9]) 11 -> java.util.List.of(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8], array[9], array[10]) - 12 -> java.util.List.of(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8], array[9], array[10], - array[11]) + 12 -> java.util.List.of(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8], array[9], array[10], array[11]) else -> { if (array.size == size) { java.util.List.of(*array) diff --git a/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt b/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt index 7ebd1b42af81..157cfd2cc82e 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt @@ -35,12 +35,11 @@ import com.intellij.platform.instanceContainer.internal.* import com.intellij.platform.util.coroutines.namedChildScope import com.intellij.util.concurrency.ThreadingAssertions import com.intellij.util.concurrency.annotations.RequiresBlockingContext +import com.intellij.util.containers.UList import com.intellij.util.messages.* import com.intellij.util.messages.impl.MessageBusEx import com.intellij.util.messages.impl.MessageBusImpl import com.intellij.util.runSuppressing -import kotlinx.collections.immutable.PersistentList -import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.* import org.jetbrains.annotations.ApiStatus.Internal import org.jetbrains.annotations.TestOnly @@ -1408,7 +1407,7 @@ abstract class ComponentManagerImpl( private class PluginServicesStore { private val regularServices = ConcurrentHashMap() - private val dynamicServices = ConcurrentHashMap>() + private val dynamicServices = ConcurrentHashMap>() fun putServicesUnregisterHandle(descriptor: IdeaPluginDescriptor, handle: UnregisterHandle) { val prev = regularServices.put(descriptor, handle) @@ -1421,12 +1420,12 @@ private class PluginServicesStore { fun addDynamicService(descriptor: IdeaPluginDescriptor, holder: InstanceHolder) { dynamicServices.compute(descriptor) { _, instances -> - (instances ?: persistentListOf()).add(holder) + (instances ?: UList()).add(holder) } } fun removeDynamicServices(descriptor: IdeaPluginDescriptor): List { - return dynamicServices.remove(descriptor) ?: java.util.List.of() + return dynamicServices.remove(descriptor)?.toList() ?: java.util.List.of() } } diff --git a/platform/util/src/com/intellij/util/containers/util.kt b/platform/util/src/com/intellij/util/containers/util.kt index 6f7aad278410..a8191062236c 100644 --- a/platform/util/src/com/intellij/util/containers/util.kt +++ b/platform/util/src/com/intellij/util/containers/util.kt @@ -1,9 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplacePutWithAssignment") package com.intellij.util.containers import com.intellij.openapi.diagnostic.Logger +import com.intellij.util.ArrayUtil +import com.intellij.util.ArrayUtilRt import com.intellij.util.Java11Shim import com.intellij.util.SmartList import com.intellij.util.lang.CompoundRuntimeException @@ -14,6 +16,28 @@ import java.util.stream.Stream import kotlin.collections.ArrayDeque import kotlin.collections.isNullOrEmpty +@Internal +@Experimental +@JvmInline +value class UList(private val array: Array = ArrayUtilRt.EMPTY_OBJECT_ARRAY) { + val size: Int + get() = array.size + + fun add(item: T): UList { + return UList(ArrayUtil.append(/* src = */ array, /* element = */ item, /* factory = */ ArrayUtil.OBJECT_ARRAY_FACTORY)) + } + + fun remove(item: T): UList { + return UList(ArrayUtil.remove(/* src = */ array, /* element = */ item, /* factory = */ ArrayUtil.OBJECT_ARRAY_FACTORY)) + } + + @Suppress("UNCHECKED_CAST") + fun toList(): List = Java11Shim.INSTANCE.listOf(array, array.size) as List + + @Suppress("UNCHECKED_CAST") + fun asIterable(): Iterable = array.asIterable() as Iterable +} + fun MutableMap>.remove(key: K, value: V) { val list = get(key) if (list != null && list.remove(value) && list.isEmpty()) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CheckinHandlersManagerImpl.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CheckinHandlersManagerImpl.kt index ec9c9b7a1a23..ab31de9b9dfc 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CheckinHandlersManagerImpl.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CheckinHandlersManagerImpl.kt @@ -1,17 +1,15 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.vcs.impl import com.intellij.openapi.vcs.AbstractVcs import com.intellij.openapi.vcs.checkin.BaseCheckinHandlerFactory import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory import com.intellij.openapi.vcs.checkin.VcsCheckinHandlerFactory -import kotlinx.collections.immutable.mutate -import kotlinx.collections.immutable.persistentListOf class CheckinHandlersManagerImpl : CheckinHandlersManager() { override fun getRegisteredCheckinHandlerFactories(vcses: Array): List { val vcsesKeys = vcses.mapTo(HashSet()) { it.keyInstanceMethod } - return persistentListOf().mutate { builder -> + return ArrayList().also { builder -> VcsCheckinHandlerFactory.EP_NAME.extensionList.filterTo(builder) { it.key in vcsesKeys } builder.addAll(CheckinHandlerFactory.EP_NAME.extensionList) } diff --git a/platform/workspace/jps/tests/intellij.platform.workspace.jps.tests.iml b/platform/workspace/jps/tests/intellij.platform.workspace.jps.tests.iml index b31e423ebfbf..3df5334a0422 100644 --- a/platform/workspace/jps/tests/intellij.platform.workspace.jps.tests.iml +++ b/platform/workspace/jps/tests/intellij.platform.workspace.jps.tests.iml @@ -27,6 +27,7 @@ + \ No newline at end of file diff --git a/platform/workspace/storage/tests/intellij.platform.workspace.storage.tests.iml b/platform/workspace/storage/tests/intellij.platform.workspace.storage.tests.iml index cc339c830604..02b532d4189d 100644 --- a/platform/workspace/storage/tests/intellij.platform.workspace.storage.tests.iml +++ b/platform/workspace/storage/tests/intellij.platform.workspace.storage.tests.iml @@ -17,6 +17,7 @@ + \ No newline at end of file diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenSystemIndicesManager.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenSystemIndicesManager.kt index 615813a697e2..bf2ee88f30c4 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenSystemIndicesManager.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/indices/MavenSystemIndicesManager.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.idea.maven.indices import com.intellij.openapi.application.ApplicationManager @@ -18,7 +18,6 @@ import com.intellij.platform.ide.progress.withBackgroundProgress import com.intellij.util.PathUtilRt import com.intellij.util.messages.Topic import com.intellij.util.xmlb.annotations.OptionTag -import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -307,7 +306,7 @@ class MavenSystemIndicesManager(val cs: CoroutineScope) : PersistentStateCompone @TestOnly fun getAllGavIndices(): List { - return inMemoryIndices.values.toImmutableList() + return java.util.List.copyOf(inMemoryIndices.values) } fun updateIndexContent(repositoryInfo: MavenRepositoryInfo, project: Project) {