From 4b445ebc433074eb764b150ee69cbd40b979c3f6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 12 Apr 2021 08:57:47 +0200 Subject: [PATCH] use jdk9+ Map.entry API instead of AbstractMap.SimpleImmutableEntry GitOrigin-RevId: bac64af4495e36b044873f6a97625342af907bec --- .../dev-server/src/DevIdeaBuildServer.kt | 5 ++--- .../build/impl/DistributionJARsBuilder.groovy | 2 +- .../externalSystem/util/PathPrefixTreeMap.kt | 6 ++---- .../externalSystem/util/PrefixTreeMap.kt | 18 ++++++++---------- .../com/intellij/ide/gdpr/ConsentOptions.java | 4 ++-- .../src/org/jetbrains/mvstore/MVMap.java | 2 +- .../concurrency/ConcurrentHashMap.java | 4 ++-- .../java/decompiler/main/ClassWriter.java | 2 +- .../plugins/textmate/bundles/VSCBundle.java | 2 +- .../textmate/language/PreferencesReadUtil.java | 2 +- 10 files changed, 21 insertions(+), 26 deletions(-) diff --git a/platform/build-scripts/dev-server/src/DevIdeaBuildServer.kt b/platform/build-scripts/dev-server/src/DevIdeaBuildServer.kt index 1e191857eb86..dfe719470c6c 100644 --- a/platform/build-scripts/dev-server/src/DevIdeaBuildServer.kt +++ b/platform/build-scripts/dev-server/src/DevIdeaBuildServer.kt @@ -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-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. package org.jetbrains.intellij.build.devServer import com.intellij.openapi.application.PathManager @@ -24,7 +24,6 @@ import java.nio.file.ClosedWatchServiceException import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -import java.util.* import java.util.concurrent.CountDownLatch import java.util.concurrent.atomic.AtomicBoolean import kotlin.system.exitProcess @@ -200,7 +199,7 @@ fun parseQuery(url: URI): Map> { val index = it.indexOf('=') val key = if (index > 0) it.substring(0, index) else it val value = if (index > 0 && it.length > index + 1) it.substring(index + 1) else null - AbstractMap.SimpleImmutableEntry(key, value) + java.util.Map.entry(key, value) } .groupBy(keySelector = { it.key }, valueTransform = { it.value }) } diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.groovy index 8f49de2d6761..21892cae9d16 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/DistributionJARsBuilder.groovy @@ -685,7 +685,7 @@ final class DistributionJARsBuilder { } pluginsToIncludeInCustomRepository.add(new PluginRepositorySpec(pluginZip: destFile.toString(), pluginXml: pluginXml.toString())) } - toArchive.add(new AbstractMap.SimpleImmutableEntry(directory, destFile)) + toArchive.add(Map.entry(directory, destFile)) } BuildHelper.bulkZipWithPrefix(buildContext, pluginsToPublishDir, toArchive, compressPluginArchive) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PathPrefixTreeMap.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PathPrefixTreeMap.kt index 82dd4b5c8e13..63721eb7ecc5 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PathPrefixTreeMap.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PathPrefixTreeMap.kt @@ -1,8 +1,6 @@ -// 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-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. package com.intellij.openapi.externalSystem.util -import java.util.* - /** * [PrefixTreeMap] uses keys, that is specified by the paths. * @see PrefixTreeMap @@ -42,7 +40,7 @@ class PathPrefixTreeMap( fun getAllAncestorValues(path: String) = delegate.getAllAncestorValues(path.toPrefixList()) private fun Iterable, V>>.toPathEntries(): List> { - return map { AbstractMap.SimpleImmutableEntry(it.key.joinToString(pathSeparator), it.value) } + return map { java.util.Map.entry(it.key.joinToString(pathSeparator), it.value) } } private fun Iterable>.toPathKeys() = map { it.joinToString(pathSeparator) } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PrefixTreeMap.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PrefixTreeMap.kt index 1b95902a0ba7..cbc801c4cced 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PrefixTreeMap.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/PrefixTreeMap.kt @@ -1,10 +1,7 @@ -// 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-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. package com.intellij.openapi.externalSystem.util import com.intellij.util.containers.FList -import java.util.* -import kotlin.NoSuchElementException -import kotlin.collections.LinkedHashMap import kotlin.collections.component1 import kotlin.collections.component2 @@ -116,11 +113,11 @@ internal class PrefixTreeMap : Map, V> { fun getEntries(): Sequence, V>> { return sequence { if (value.isPresent) { - yield(AbstractMap.SimpleImmutableEntry(FList.emptyList(), value.get())) + yield(java.util.Map.entry(FList.emptyList(), value.get())) } for ((key, child) in children) { for ((path, value) in child.getEntries()) { - yield(AbstractMap.SimpleImmutableEntry(path.prepend(key), value)) + yield(java.util.Map.entry(path.prepend(key), value)) } } } @@ -129,19 +126,20 @@ internal class PrefixTreeMap : Map, V> { fun getAllAncestors(path: FList): Sequence, V>> { return sequence { if (value.isPresent) { - yield(AbstractMap.SimpleImmutableEntry(FList.emptyList(), value.get())) + yield(java.util.Map.entry(FList.emptyList(), value.get())) } if (path.isEmpty()) return@sequence val (head, tail) = path val child = children[head] ?: return@sequence for ((relative, value) in child.getAllAncestors(tail)) { - yield(AbstractMap.SimpleImmutableEntry(relative.prepend(head), value)) + yield(java.util.Map.entry(relative.prepend(head), value)) } } } - fun getAllDescendants(path: FList) = - root.get(path)?.getEntries()?.map { AbstractMap.SimpleImmutableEntry(path + it.key, it.value) } ?: emptySequence() + fun getAllDescendants(path: FList): Sequence, V>> { + return root.get(path)?.getEntries()?.map { java.util.Map.entry(path + it.key, it.value) } ?: emptySequence() + } } private class Value private constructor(val isPresent: Boolean, private val value: Any?) { diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java index cf0f8725646f..16eb1c2e2e66 100644 --- a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java @@ -176,7 +176,7 @@ public final class ConsentOptions { allDefaults.remove(STATISTICS_OPTION_ID); } if (allDefaults.isEmpty()) { - return new AbstractMap.SimpleImmutableEntry<>(Collections.emptyList(), Boolean.FALSE); + return Map.entry(Collections.emptyList(), Boolean.FALSE); } final Map allConfirmed = loadConfirmedConsents(); final List result = new ArrayList<>(); @@ -189,7 +189,7 @@ public final class ConsentOptions { } result.sort(Comparator.comparing(ConsentBase::getId)); boolean confirmationEnabled = Boolean.parseBoolean(System.getProperty(CONSENTS_CONFIRMATION_PROPERTY, "true")); - return new AbstractMap.SimpleImmutableEntry<>(result, confirmationEnabled && needReconfirm(allDefaults, allConfirmed)); + return Map.entry(result, confirmationEnabled && needReconfirm(allDefaults, allConfirmed)); } public void setConsents(@NotNull Collection confirmedByUser) { diff --git a/platform/util-ex/src/org/jetbrains/mvstore/MVMap.java b/platform/util-ex/src/org/jetbrains/mvstore/MVMap.java index 2dd02680b341..8c2611aab811 100644 --- a/platform/util-ex/src/org/jetbrains/mvstore/MVMap.java +++ b/platform/util-ex/src/org/jetbrains/mvstore/MVMap.java @@ -633,7 +633,7 @@ public final class MVMap extends AbstractMap implements ConcurrentMa @Override public Entry next() { K k = cursor.next(); - return new SimpleImmutableEntry<>(k, cursor.getValue()); + return Map.entry(k, cursor.getValue()); } }; } diff --git a/platform/util/concurrency/com/intellij/concurrency/ConcurrentHashMap.java b/platform/util/concurrency/com/intellij/concurrency/ConcurrentHashMap.java index 5a1f139ddaa1..a2bfde940f6f 100644 --- a/platform/util/concurrency/com/intellij/concurrency/ConcurrentHashMap.java +++ b/platform/util/concurrency/com/intellij/concurrency/ConcurrentHashMap.java @@ -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-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. package com.intellij.concurrency; /* @@ -1488,7 +1488,7 @@ final class ConcurrentHashMap extends AbstractMap for (Node p; (p = it.advance()) != null; ) { K k = p.key; V v = p.val; - Map.Entry e = new AbstractMap.SimpleImmutableEntry<>(k, v); + Map.Entry e = Map.entry(k, v); if (function.test(e) && replaceNode(k, null, v) != null) removed = true; } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 2d57c02d34e1..e71b0f8658fb 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -502,7 +502,7 @@ public class ClassWriter { } private static boolean isVarArgRecord(StructClass cl) { - String canonicalConstructorDescriptor = + String canonicalConstructorDescriptor = cl.getRecordComponents().stream().map(c -> c.getDescriptor()).collect(Collectors.joining("", "(", ")V")); StructMethod init = cl.getMethod(CodeConstants.INIT_NAME, canonicalConstructorDescriptor); return init != null && init.hasModifier(CodeConstants.ACC_VARARGS); diff --git a/plugins/textmate/core/src/org/jetbrains/plugins/textmate/bundles/VSCBundle.java b/plugins/textmate/core/src/org/jetbrains/plugins/textmate/bundles/VSCBundle.java index ee566941ca82..d8aa2e51560e 100644 --- a/plugins/textmate/core/src/org/jetbrains/plugins/textmate/bundles/VSCBundle.java +++ b/plugins/textmate/core/src/org/jetbrains/plugins/textmate/bundles/VSCBundle.java @@ -137,7 +137,7 @@ public class VSCBundle extends Bundle { //noinspection SSBasedInspection return configToScopes.get(FileUtilRt.toSystemIndependentName( Objects.requireNonNull(FileUtilRt.getRelativePath(bundleFile, file)))).stream() - .map(scope -> new AbstractMap.SimpleImmutableEntry<>(scope, fromJson)) + .map(scope -> Map.entry(scope, fromJson)) .collect(Collectors.toList()); } diff --git a/plugins/textmate/core/src/org/jetbrains/plugins/textmate/language/PreferencesReadUtil.java b/plugins/textmate/core/src/org/jetbrains/plugins/textmate/language/PreferencesReadUtil.java index 38c71f4e0629..8bd08441b301 100644 --- a/plugins/textmate/core/src/org/jetbrains/plugins/textmate/language/PreferencesReadUtil.java +++ b/plugins/textmate/core/src/org/jetbrains/plugins/textmate/language/PreferencesReadUtil.java @@ -30,7 +30,7 @@ public final class PreferencesReadUtil { settingsValuePlist = settingsValue.getPlist(); } } - return settingsValuePlist != null ? new AbstractMap.SimpleImmutableEntry<>(scopeName, settingsValuePlist) : null; + return settingsValuePlist != null ? Map.entry(scopeName, settingsValuePlist) : null; } @Nullable