From c9a728765bb24afb3192c8f02550a399c950de8e Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 12 May 2023 10:24:15 +0200 Subject: [PATCH] cleanup GitOrigin-RevId: ab8b1f51e55964d276fcdd3fdd1f6389bb72dec2 --- .../components/ExpandMacroToPathMap.java | 6 +-- .../src/TrackingPathMacroSubstitutorImpl.kt | 6 ++- .../openapi/actionSystem/Presentation.java | 53 ++++++++----------- .../intellij/diagnostic/DebugLogManager.kt | 21 ++++---- .../application/options/PathMacrosImpl.kt | 4 +- .../options/ReplacePathToMacroMap.java | 20 +++---- .../openapi/components/PathMacroManager.java | 17 +++--- 7 files changed, 59 insertions(+), 68 deletions(-) diff --git a/jps/model-serialization/src/com/intellij/openapi/components/ExpandMacroToPathMap.java b/jps/model-serialization/src/com/intellij/openapi/components/ExpandMacroToPathMap.java index 2ba20827252e..8a3a061a4858 100644 --- a/jps/model-serialization/src/com/intellij/openapi/components/ExpandMacroToPathMap.java +++ b/jps/model-serialization/src/com/intellij/openapi/components/ExpandMacroToPathMap.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.components; import com.intellij.openapi.util.TextRange; @@ -37,8 +37,8 @@ public final class ExpandMacroToPathMap extends PathMacroMap { } for (Map.Entry entry : myPlainMap.entrySet()) { - // when replacing macros with actual paths the replace utility may be used as always 'case-sensitive' - // for case-insensitive file systems there will be no unnecessary toLowerCase() transforms. + // when replacing macros with actual paths, the replace utility may be used as always 'case-sensitive' + // for case-insensitive file systems, there will be no unnecessary toLowerCase() transforms. text = StringUtil.replace(text, entry.getKey(), entry.getValue(), false); } diff --git a/platform/configuration-store-impl/src/TrackingPathMacroSubstitutorImpl.kt b/platform/configuration-store-impl/src/TrackingPathMacroSubstitutorImpl.kt index a6a234e983a7..7d5777d35717 100644 --- a/platform/configuration-store-impl/src/TrackingPathMacroSubstitutorImpl.kt +++ b/platform/configuration-store-impl/src/TrackingPathMacroSubstitutorImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.configurationStore import com.intellij.openapi.components.PathMacroManager @@ -6,7 +6,9 @@ import com.intellij.openapi.components.PathMacroSubstitutor import com.intellij.openapi.components.TrackingPathMacroSubstitutor import org.jetbrains.annotations.ApiStatus -internal fun PathMacroManager?.createTrackingSubstitutor(): TrackingPathMacroSubstitutorImpl? = if (this == null) null else TrackingPathMacroSubstitutorImpl(this) +internal fun PathMacroManager?.createTrackingSubstitutor(): TrackingPathMacroSubstitutorImpl? { + return if (this == null) null else TrackingPathMacroSubstitutorImpl(this) +} @ApiStatus.Internal class TrackingPathMacroSubstitutorImpl(internal val macroManager: PathMacroManager) : PathMacroSubstitutor by macroManager, TrackingPathMacroSubstitutor { diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java index 78eec3f5fa99..a3340cc4fec7 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/Presentation.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.actionSystem; import com.intellij.DynamicBundle; @@ -44,51 +44,51 @@ public final class Presentation implements Cloneable { * Defines tool tip for button at toolbar or text for element at menu * value: String */ - @NonNls public static final String PROP_TEXT = "text"; + public static final @NonNls String PROP_TEXT = "text"; /** * Defines tool tip for button at toolbar or text for element at menu * that includes mnemonic suffix, like "Git(G)" * value: String */ - @NonNls public static final String PROP_TEXT_WITH_SUFFIX = "textWithSuffix"; + public static final @NonNls String PROP_TEXT_WITH_SUFFIX = "textWithSuffix"; /** * value: Integer */ - @NonNls public static final String PROP_MNEMONIC_KEY = "mnemonicKey"; + public static final @NonNls String PROP_MNEMONIC_KEY = "mnemonicKey"; /** * value: Integer */ - @NonNls public static final String PROP_MNEMONIC_INDEX = "mnemonicIndex"; + public static final @NonNls String PROP_MNEMONIC_INDEX = "mnemonicIndex"; /** * value: String */ - @NonNls public static final String PROP_DESCRIPTION = "description"; + public static final @NonNls String PROP_DESCRIPTION = "description"; /** * value: Icon */ - @NonNls public static final String PROP_ICON = "icon"; + public static final @NonNls String PROP_ICON = "icon"; /** * value: Icon */ - @NonNls public static final String PROP_DISABLED_ICON = "disabledIcon"; + public static final @NonNls String PROP_DISABLED_ICON = "disabledIcon"; /** * value: Icon */ - @NonNls public static final String PROP_SELECTED_ICON = "selectedIcon"; + public static final @NonNls String PROP_SELECTED_ICON = "selectedIcon"; /** * value: Icon */ - @NonNls public static final String PROP_HOVERED_ICON = "hoveredIcon"; + public static final @NonNls String PROP_HOVERED_ICON = "hoveredIcon"; /** * value: Boolean */ - @NonNls public static final String PROP_VISIBLE = "visible"; + public static final @NonNls String PROP_VISIBLE = "visible"; /** * The actual value is a Boolean. */ - @NonNls public static final String PROP_ENABLED = "enabled"; + public static final @NonNls String PROP_ENABLED = "enabled"; - @NonNls public static final Key<@Nls String> PROP_VALUE = Key.create("value"); + public static final @NonNls Key<@Nls String> PROP_VALUE = Key.create("value"); public static final double DEFAULT_WEIGHT = 0; public static final double HIGHER_WEIGHT = 42; @@ -105,7 +105,7 @@ public final class Presentation implements Cloneable { private int myFlags = IS_ENABLED | IS_VISIBLE | IS_DISABLE_GROUP_IF_EMPTY; private @NotNull Supplier<@ActionDescription String> myDescriptionSupplier = () -> null; - private @NotNull Supplier myTextWithMnemonicSupplier = () -> null; + private @NotNull Supplier myTextWithMnemonicSupplier = () -> null; private @NotNull SmartFMap myUserMap = SmartFMap.emptyMap(); private Icon myIcon; @@ -196,9 +196,8 @@ public final class Presentation implements Cloneable { setTextWithMnemonic(getTextWithMnemonic(() -> text, mayContainMnemonic)); } - @NotNull - public Supplier getTextWithMnemonic(@NotNull Supplier<@Nls(capitalization = Nls.Capitalization.Title) String> text, - boolean mayContainMnemonic) { + public @NotNull Supplier getTextWithMnemonic(@NotNull Supplier<@Nls(capitalization = Nls.Capitalization.Title) String> text, + boolean mayContainMnemonic) { if (mayContainMnemonic) { return () -> { String s = text.get(); @@ -222,7 +221,7 @@ public final class Presentation implements Cloneable { * * @param textWithMnemonicSupplier text with mnemonic to set */ - public void setTextWithMnemonic(@NotNull Supplier textWithMnemonicSupplier) { + public void setTextWithMnemonic(@NotNull Supplier textWithMnemonicSupplier) { String oldText = getText(); String oldTextWithSuffix = getText(true); int oldMnemonic = getMnemonic(); @@ -254,15 +253,12 @@ public final class Presentation implements Cloneable { /** * @return the text with mnemonic, properly escaped, so it could be passed to {@link #setText(String)} (e.g. to copy the presentation). */ - @ActionText - @Nullable - public String getTextWithMnemonic() { + public @ActionText @Nullable String getTextWithMnemonic() { TextWithMnemonic textWithMnemonic = myTextWithMnemonicSupplier.get(); return textWithMnemonic == null ? null : textWithMnemonic.toString(); } - @NotNull - public Supplier getTextWithPossibleMnemonic() { + public @NotNull Supplier getTextWithPossibleMnemonic() { return myTextWithMnemonicSupplier; } @@ -310,7 +306,7 @@ public final class Presentation implements Cloneable { return myHoveredIcon; } - public void setHoveredIcon(@Nullable final Icon hoveredIcon) { + public void setHoveredIcon(final @Nullable Icon hoveredIcon) { Icon old = myHoveredIcon; myHoveredIcon = hoveredIcon; fireObjectPropertyChange(PROP_HOVERED_ICON, old, myHoveredIcon); @@ -528,8 +524,7 @@ public final class Presentation implements Cloneable { } } - @Nullable - public T getClientProperty(@NotNull Key key) { + public @Nullable T getClientProperty(@NotNull Key key) { //noinspection unchecked return (T)myUserMap.get(key.toString()); } @@ -540,8 +535,7 @@ public final class Presentation implements Cloneable { /** @deprecated Use {@link #getClientProperty(Key)} instead */ @Deprecated - @Nullable - public Object getClientProperty(@NonNls @NotNull String key) { + public @Nullable Object getClientProperty(@NonNls @NotNull String key) { return myUserMap.get(key); } @@ -588,9 +582,8 @@ public final class Presentation implements Cloneable { return BitUtil.isSet(myFlags, IS_MULTI_CHOICE); } - @Nls @Override - public String toString() { + public @Nls String toString() { return getText() + " (" + myDescriptionSupplier.get() + ")"; } } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/DebugLogManager.kt b/platform/platform-impl/src/com/intellij/diagnostic/DebugLogManager.kt index c3aece299756..153da9976a81 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/DebugLogManager.kt +++ b/platform/platform-impl/src/com/intellij/diagnostic/DebugLogManager.kt @@ -1,16 +1,19 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.diagnostic import com.intellij.ide.util.PropertiesComponent +import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.logger import java.util.logging.Level import java.util.logging.Logger /** - * Allows to apply & persist custom log debug categories which can be turned on by user via the [com.intellij.ide.actions.DebugLogConfigureAction]. + * Allows applying & persisting custom log debug categories + * which can be turned on by user via the [com.intellij.ide.actions.DebugLogConfigureAction]. * Applies these custom categories on startup. */ +@Service(Service.Level.APP) class DebugLogManager { enum class DebugLogLevel { DEBUG, TRACE, ALL } @@ -18,7 +21,7 @@ class DebugLogManager { companion object { @JvmStatic - fun getInstance() = service() + fun getInstance(): DebugLogManager = service() } // java.util.logging keeps only weak references to loggers, so we need to store strong references to loggers we've customized to ensure @@ -28,7 +31,7 @@ class DebugLogManager { init { val categories = mutableListOf() categories.addAll(getSavedCategories()) - // add categories from system properties (e.g. for tests on CI server) + // add categories from system properties (e.g., for tests on CI server) categories.addAll(fromString(System.getProperty(LOG_DEBUG_CATEGORIES_SYSTEM_PROPERTY), DebugLogLevel.DEBUG)) categories.addAll(fromString(System.getProperty(LOG_TRACE_CATEGORIES_SYSTEM_PROPERTY), DebugLogLevel.TRACE)) categories.addAll(fromString(System.getProperty(LOG_ALL_CATEGORIES_SYSTEM_PROPERTY), DebugLogLevel.ALL)) @@ -65,13 +68,13 @@ class DebugLogManager { } .distinct() .toList() - filtered.forEach { - val logger = Logger.getLogger(it) + for (name in filtered) { + val logger = Logger.getLogger(name) logger.level = loggerLevel customizedLoggers.add(logger) } if (filtered.isNotEmpty()) { - LOG.info("Set ${level.name} for the following categories: ${filtered.joinToString()}") + logger().info("Set ${level.name} for the following categories: ${filtered.joinToString()}") } } @@ -106,6 +109,4 @@ private const val LOG_TRACE_CATEGORIES = "log.trace.categories" private const val LOG_ALL_CATEGORIES = "log.all.categories" private const val LOG_DEBUG_CATEGORIES_SYSTEM_PROPERTY = "idea.$LOG_DEBUG_CATEGORIES" private const val LOG_TRACE_CATEGORIES_SYSTEM_PROPERTY = "idea.$LOG_TRACE_CATEGORIES" -private const val LOG_ALL_CATEGORIES_SYSTEM_PROPERTY = "idea.$LOG_ALL_CATEGORIES" - -private val LOG = logger() \ No newline at end of file +private const val LOG_ALL_CATEGORIES_SYSTEM_PROPERTY = "idea.$LOG_ALL_CATEGORIES" \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.kt b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.kt index acd767d8084d..24a73c07a545 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.kt +++ b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.application.options import com.intellij.openapi.application.PathMacroContributor @@ -50,7 +50,7 @@ open class PathMacrosImpl @JvmOverloads constructor(private val loadContributors ) @JvmStatic - fun getInstanceEx() = getInstance() as PathMacrosImpl + fun getInstanceEx(): PathMacrosImpl = getInstance() as PathMacrosImpl } override fun getUserMacroNames() = macros.keys diff --git a/platform/projectModel-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java b/platform/projectModel-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java index c1dff288a9dd..fcaea4ade5f5 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java +++ b/platform/projectModel-impl/src/com/intellij/application/options/ReplacePathToMacroMap.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.application.options; import com.intellij.openapi.application.ApplicationManager; @@ -24,7 +24,7 @@ import java.util.Map; * @see com.intellij.openapi.components.PathMacroManager */ public final class ReplacePathToMacroMap extends PathMacroMap { - private List myPathsIndex = null; + private List pathIndex = null; private final Map myMacroMap = new LinkedHashMap<>(); public static final String[] PROTOCOLS; @@ -70,7 +70,7 @@ public final class ReplacePathToMacroMap extends PathMacroMap { @Override public @NotNull String substitute(@NotNull String text, boolean caseSensitive) { - for (final String path : getPathIndex()) { + for (String path : getPathIndex()) { text = replacePathMacro(text, path, caseSensitive); } return text; @@ -86,7 +86,7 @@ public final class ReplacePathToMacroMap extends PathMacroMap { } //check that this is complete path (ends with "/" or "!/") - // do not collapse partial paths, i.e. do not substitute "/a/b/cd" in paths like "/a/b/cdeFgh" + // do not collapse partial paths, i.e., do not substitute "/a/b/cd" in paths like "/a/b/cdeFgh" int endOfOccurrence = path.length(); final boolean isWindowsRoot = path.endsWith(":/"); if (!isWindowsRoot && @@ -146,7 +146,7 @@ public final class ReplacePathToMacroMap extends PathMacroMap { } } if (occurrenceOfPath < 0) { - if (newText.length() == 0) { + if (newText.isEmpty()) { return text; } newText.append(text, i, text.length()); @@ -185,8 +185,8 @@ public final class ReplacePathToMacroMap extends PathMacroMap { } private @NotNull List getPathIndex() { - if (myPathsIndex != null && myPathsIndex.size() == myMacroMap.size()) { - return myPathsIndex; + if (pathIndex != null && pathIndex.size() == myMacroMap.size()) { + return pathIndex; } List> entries = new ArrayList<>(myMacroMap.entrySet()); @@ -197,8 +197,8 @@ public final class ReplacePathToMacroMap extends PathMacroMap { } entries.sort((o1, o2) -> weights.getInt(o2.getKey()) - weights.getInt(o1.getKey())); - myPathsIndex = ContainerUtil.map(entries, entry -> entry.getKey()); - return myPathsIndex; + pathIndex = ContainerUtil.map(entries, entry -> entry.getKey()); + return pathIndex; } public boolean equals(Object obj) { @@ -217,6 +217,6 @@ public final class ReplacePathToMacroMap extends PathMacroMap { @Override public String toString() { - return "macroMap: " + myMacroMap + "\n\npathsIndex: " + StringUtil.join(myPathsIndex, "\n"); + return "macroMap: " + myMacroMap + "\n\npathsIndex: " + StringUtil.join(pathIndex, "\n"); } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/PathMacroManager.java b/platform/projectModel-impl/src/com/intellij/openapi/components/PathMacroManager.java index ec3dff22302d..cdf29e0c13ee 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/PathMacroManager.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/PathMacroManager.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-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.components; import com.intellij.application.options.PathMacrosCollector; @@ -41,8 +41,7 @@ public class PathMacroManager implements PathMacroSubstitutor { myPathMacros = (PathMacrosImpl)pathMacros; } - @NotNull - public PathMacroFilter getMacroFilter() { + public @NotNull PathMacroFilter getMacroFilter() { return Holder.createFilter(); } @@ -75,8 +74,7 @@ public class PathMacroManager implements PathMacroSubstitutor { } } - @NotNull - public ExpandMacroToPathMap getExpandMacroMap() { + public @NotNull ExpandMacroToPathMap getExpandMacroMap() { ExpandMacroToPathMap result = new ExpandMacroToPathMap(); getPathMacros().addMacroExpands(result); for (Map.Entry entry : PathMacroUtil.getGlobalSystemMacros().entrySet()) { @@ -85,8 +83,7 @@ public class PathMacroManager implements PathMacroSubstitutor { return result; } - @NotNull - public final synchronized ReplacePathToMacroMap getReplacePathMap() { + public final synchronized @NotNull ReplacePathToMacroMap getReplacePathMap() { long pathMacrosModificationCount = getPathMacros().getModificationCount(); if (myReplacePathToMacroMap != null && pathMacrosModificationCount == myPathMacrosModificationCount) { return myReplacePathToMacroMap; @@ -97,8 +94,7 @@ public class PathMacroManager implements PathMacroSubstitutor { return myReplacePathToMacroMap; } - @NotNull - protected ReplacePathToMacroMap computeReplacePathMap() { + protected @NotNull ReplacePathToMacroMap computeReplacePathMap() { ReplacePathToMacroMap result = new ReplacePathToMacroMap(); getPathMacros().addMacroReplacements(result); for (Map.Entry entry : PathMacroUtil.getGlobalSystemMacros().entrySet()) { @@ -143,8 +139,7 @@ public class PathMacroManager implements PathMacroSubstitutor { map.substitute(element, SystemInfoRt.isFileSystemCaseSensitive, recursively, Holder.createFilter()); } - @NotNull - private PathMacrosImpl getPathMacros() { + private @NotNull PathMacrosImpl getPathMacros() { if (myPathMacros == null) { myPathMacros = PathMacrosImpl.getInstanceEx(); }