diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java index c8d671fd8066..cdf322c78b4a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// 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.roots.ui.configuration; import com.intellij.ide.JavaUiBundle; @@ -24,13 +9,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.SimpleJavaSdkType; import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl; import com.intellij.openapi.roots.ui.configuration.projectRoot.JdkConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; import com.intellij.openapi.ui.MasterDetailsComponent; import com.intellij.openapi.ui.MasterDetailsStateService; import com.intellij.openapi.ui.NamedConfigurable; -import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.NlsContexts; import com.intellij.openapi.util.Ref; import com.intellij.ui.JBSplitter; @@ -44,9 +29,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import java.awt.*; import java.util.*; -import static com.intellij.openapi.projectRoots.SimpleJavaSdkType.notSimpleJavaSdkType; - -public class ProjectJdksConfigurable extends MasterDetailsComponent { +public final class ProjectJdksConfigurable extends MasterDetailsComponent { private final ProjectSdksModel myProjectJdksModel; private final Project myProject; @@ -115,7 +98,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent { super.apply(); boolean modifiedJdks = false; for (int i = 0; i < myRoot.getChildCount(); i++) { - final NamedConfigurable configurable = ((MyNode)myRoot.getChildAt(i)).getConfigurable(); + final NamedConfigurable configurable = ((MyNode)myRoot.getChildAt(i)).getConfigurable(); if (configurable.isModified()) { configurable.apply(); modifiedJdks = true; @@ -160,9 +143,9 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent { myProjectJdksModel.createAddActions(group, myTree, projectJdk -> { addNode(new MyNode(new JdkConfigurable(((ProjectJdkImpl)projectJdk), myProjectJdksModel, TREE_UPDATER, myHistory, myProject), false), myRoot); selectNodeInTree(findNodeByObject(myRoot, projectJdk)); - }, notSimpleJavaSdkType()); + }, SimpleJavaSdkType.notSimpleJavaSdkType()); actions.add(new MyActionGroupWrapper(group)); - actions.add(new MyDeleteAction(Conditions.alwaysTrue())); + actions.add(new MyDeleteAction()); return actions; } @@ -171,7 +154,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent { final Set jdks = new HashSet<>(); for(int i = 0; i < myRoot.getChildCount(); i++){ final DefaultMutableTreeNode node = (DefaultMutableTreeNode)myRoot.getChildAt(i); - final NamedConfigurable namedConfigurable = (NamedConfigurable)node.getUserObject(); + final NamedConfigurable namedConfigurable = (NamedConfigurable)node.getUserObject(); jdks.add(((JdkConfigurable)namedConfigurable).getEditableObject()); } final HashMap sdks = new HashMap<>(myProjectJdksModel.getProjectSdks()); @@ -210,7 +193,7 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent { } @Override - protected @NlsContexts.StatusText @Nullable String getEmptySelectionString() { + protected @NlsContexts.StatusText @NotNull String getEmptySelectionString() { return JavaUiBundle.message("project.jdks.configurable.empty.selection.string"); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java index eec295a047c8..5d2918ffb10b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseStructureConfigurable.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.openapi.roots.ui.configuration.projectRoot; import com.intellij.facet.Facet; @@ -19,7 +19,6 @@ import com.intellij.openapi.ui.MasterDetailsState; import com.intellij.openapi.ui.MasterDetailsStateService; import com.intellij.openapi.ui.NamedConfigurable; import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.NlsActions; import com.intellij.ui.TreeSpeedSearch; @@ -37,6 +36,7 @@ import javax.swing.tree.TreePath; import java.awt.*; import java.util.List; import java.util.*; +import java.util.function.Predicate; public abstract class BaseStructureConfigurable extends MasterDetailsComponent implements SearchableConfigurable, Disposable, Place.Navigator { protected StructureConfigurableContext myContext; @@ -90,15 +90,8 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i if (node == null && nodeByName == null) return ActionCallback.DONE; - final NamedConfigurable config; - if (node != null) { - config = node.getConfigurable(); - } else { - config = nodeByName.getConfigurable(); - } - - final ActionCallback result = new ActionCallback().doWhenDone(() -> myAutoScrollEnabled = true); - + NamedConfigurable config = Objects.requireNonNullElse(node, nodeByName).getConfigurable(); + ActionCallback result = new ActionCallback().doWhenDone(() -> myAutoScrollEnabled = true); myAutoScrollEnabled = false; myAutoScrollHandler.cancelAllRequests(); final MyNode nodeToSelect = node != null ? node : nodeByName; @@ -311,12 +304,11 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i return null; } - protected class MyRemoveAction extends MyDeleteAction { - public MyRemoveAction() { - //noinspection Convert2Lambda - super(new Condition<>() { + final class MyRemoveAction extends MyDeleteAction { + MyRemoveAction() { + super(new Predicate<>() { @Override - public boolean value(final Object[] objects) { + public boolean test(final Object[] objects) { List nodes = new ArrayList<>(); for (Object object : objects) { if (!(object instanceof MyNode)) return false; diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/ui/EqualsHashCodeTemplatesPanel.java b/java/java-impl/src/com/intellij/codeInsight/generation/ui/EqualsHashCodeTemplatesPanel.java index e93be0d305e4..c14e46e2de9f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/ui/EqualsHashCodeTemplatesPanel.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/ui/EqualsHashCodeTemplatesPanel.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.codeInsight.generation.ui; import com.intellij.codeInsight.generation.EqualsHashCodeTemplatesManager; @@ -13,7 +13,6 @@ import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.*; import com.intellij.ui.TitledSeparator; import com.intellij.util.ui.JBUI; -import gnu.trove.Equality; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -26,8 +25,9 @@ import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.function.BiPredicate; -public class EqualsHashCodeTemplatesPanel extends NamedItemsListEditor> { +public final class EqualsHashCodeTemplatesPanel extends NamedItemsListEditor> { private static final Namer> NAMER = new Namer<>() { @Override @@ -70,16 +70,17 @@ public class EqualsHashCodeTemplatesPanel extends NamedItemsListEditor> COMPARER = new Equality<>() { - @Override - public boolean equals(Couple o1, Couple o2) { - return equals(o1.first, o2.first) && equals(o1.second, o2.second); - } + private static final BiPredicate, Pair> COMPARER = + new BiPredicate<>() { + @Override + public boolean test(Pair o1, Pair o2) { + return equals(o1.first, o2.first) && equals(o1.second, o2.second); + } - private boolean equals(TemplateResource r1, TemplateResource r2) { - return Objects.equals(r1.getTemplate(), r2.getTemplate()) && Objects.equals(r1.getFileName(), r2.getFileName()); - } - }; + private boolean equals(TemplateResource r1, TemplateResource r2) { + return Objects.equals(r1.getTemplate(), r2.getTemplate()) && Objects.equals(r1.getFileName(), r2.getFileName()); + } + }; private final Project myProject; private final EqualsHashCodeTemplatesManager myManager; diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/tokens/ArrangementRuleAliasesListEditor.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/tokens/ArrangementRuleAliasesListEditor.java index 194b011e1418..e1880fff5313 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/tokens/ArrangementRuleAliasesListEditor.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/tokens/ArrangementRuleAliasesListEditor.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.application.options.codeStyle.arrangement.match.tokens; import com.intellij.application.options.codeStyle.arrangement.color.ArrangementColorsProvider; @@ -13,7 +13,6 @@ import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.NlsContexts; import com.intellij.psi.codeStyle.arrangement.std.ArrangementStandardSettingsManager; import com.intellij.psi.codeStyle.arrangement.std.StdArrangementRuleAliasToken; -import gnu.trove.Equality; import org.jdom.Verifier; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -22,11 +21,12 @@ import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.BiPredicate; /** * @author Svetlana.Zemlyanskaya */ -public class ArrangementRuleAliasesListEditor extends NamedItemsListEditor { +public final class ArrangementRuleAliasesListEditor extends NamedItemsListEditor { private static final Namer NAMER = new Namer<>() { @Override public String getName(StdArrangementRuleAliasToken token) { @@ -55,13 +55,14 @@ public class ArrangementRuleAliasesListEditor extends NamedItemsListEditor COMPARER = (o1, o2) -> Objects.equals(o1.getId(), o2.getId()); + private static final BiPredicate + COMPARER = (o1, o2) -> Objects.equals(o1.getId(), o2.getId()); @NotNull private final Set myUsedTokenIds; @NotNull private final ArrangementStandardSettingsManager mySettingsManager; @NotNull private final ArrangementColorsProvider myColorsProvider; - protected ArrangementRuleAliasesListEditor(@NotNull ArrangementStandardSettingsManager settingsManager, + ArrangementRuleAliasesListEditor(@NotNull ArrangementStandardSettingsManager settingsManager, @NotNull ArrangementColorsProvider colorsProvider, @NotNull List items, @NotNull Set usedTokenIds) { diff --git a/platform/platform-api/intellij.platform.ide.iml b/platform/platform-api/intellij.platform.ide.iml index 351b7f3158e8..5c95b45e8db3 100644 --- a/platform/platform-api/intellij.platform.ide.iml +++ b/platform/platform-api/intellij.platform.ide.iml @@ -45,7 +45,6 @@ - diff --git a/platform/platform-api/src/com/intellij/ide/browsers/chrome/ChromeSettings.java b/platform/platform-api/src/com/intellij/ide/browsers/chrome/ChromeSettings.java index df9b22d99cfd..6add0bad55e8 100644 --- a/platform/platform-api/src/com/intellij/ide/browsers/chrome/ChromeSettings.java +++ b/platform/platform-api/src/com/intellij/ide/browsers/chrome/ChromeSettings.java @@ -8,7 +8,6 @@ import com.intellij.util.PathUtil; import com.intellij.util.execution.ParametersListUtil; import com.intellij.util.xmlb.annotations.Tag; import com.intellij.util.xmlb.annotations.XMap; -import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -95,7 +94,7 @@ public final class ChromeSettings extends BrowserSpecificSettings { @Override public ChromeSettings clone() { ChromeSettings clone = (ChromeSettings)super.clone(); - clone.myEnvironmentVariables = new THashMap<>(myEnvironmentVariables); + clone.myEnvironmentVariables = new HashMap<>(myEnvironmentVariables); return clone; } diff --git a/platform/platform-api/src/com/intellij/ide/nls/NlsMessages.java b/platform/platform-api/src/com/intellij/ide/nls/NlsMessages.java index 7fc6e32a0db5..1ae4f5973e62 100644 --- a/platform/platform-api/src/com/intellij/ide/nls/NlsMessages.java +++ b/platform/platform-api/src/com/intellij/ide/nls/NlsMessages.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.ide.nls; import com.ibm.icu.number.FormattedNumber; @@ -11,8 +11,8 @@ import com.ibm.icu.util.Measure; import com.ibm.icu.util.MeasureUnit; import com.intellij.DynamicBundle; import com.intellij.openapi.util.text.StringUtil; -import gnu.trove.TIntArrayList; -import gnu.trove.TLongArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.longs.LongArrayList; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -43,7 +43,7 @@ public class NlsMessages { /** * @param list list of items - * @return localized narrow string representation of all items in the list with conjunction formatting. + * @return localized narrow string representation of all items in the list with conjunction formatting. * In narrow representation the conjunction could be omitted. * E.g. formatAndList(List.of("X", "Y", "Z")) will produce "X, Y, Z" in English locale. */ @@ -82,8 +82,8 @@ public class NlsMessages { */ public static @NotNull Collector joiningOr() { return Collectors.collectingAndThen(Collectors.toList(), NlsMessages::formatOrList); - } - + } + /** * Formats duration given in milliseconds as a sum of time units with at most two units * (example: {@code formatDuration(123456) = "2 m, 3 s"}). @@ -92,7 +92,7 @@ public class NlsMessages { public static @NotNull @Nls String formatDurationApproximate(long duration) { return formatDuration(duration, 2, false); } - + /** * Formats duration given in milliseconds as a sum of time units with at most two units * (example: {@code formatDuration(123456) = "2 m 3 s"}). @@ -102,7 +102,7 @@ public class NlsMessages { return formatDuration(duration, 2, true); } - /** + /** * Formats duration given in milliseconds as a sum of time units (example: {@code formatDuration(123456, "") = "2m 3s 456ms"}). * The result is localized according to the currently used language pack. */ @@ -113,8 +113,8 @@ public class NlsMessages { @Contract(pure = true) private static @NotNull @Nls String formatDuration(long duration, int maxFragments, boolean narrow) { - TLongArrayList unitValues = new TLongArrayList(); - TIntArrayList unitIndices = new TIntArrayList(); + LongArrayList unitValues = new LongArrayList(); + IntArrayList unitIndices = new IntArrayList(); long count = duration; int i = 1; @@ -124,19 +124,19 @@ public class NlsMessages { long remainder = count % multiplier; count /= multiplier; if (remainder != 0 || !unitValues.isEmpty()) { - unitValues.insert(0, remainder); - unitIndices.insert(0, i - 1); + unitValues.add(0, remainder); + unitIndices.add(0, i - 1); } } - unitValues.insert(0, count); - unitIndices.insert(0, i - 1); + unitValues.add(0, count); + unitIndices.add(0, i - 1); if (unitValues.size() > maxFragments) { - int lastUnitIndex = unitIndices.get(maxFragments - 1); + int lastUnitIndex = unitIndices.getInt(maxFragments - 1); long lastMultiplier = TIME_MULTIPLIERS[lastUnitIndex]; // Round up if needed - if (unitValues.get(maxFragments) > lastMultiplier / 2) { - long increment = lastMultiplier - unitValues.get(maxFragments); + if (unitValues.getLong(maxFragments) > lastMultiplier / 2) { + long increment = lastMultiplier - unitValues.getLong(maxFragments); for (int unit = lastUnitIndex - 1; unit > 0; unit--) { increment *= TIME_MULTIPLIERS[unit]; } @@ -149,14 +149,14 @@ public class NlsMessages { List fragments = new ArrayList<>(); LocalizedNumberFormatter formatter = NumberFormatter.withLocale(DynamicBundle.getLocale()).unitWidth(NumberFormatter.UnitWidth.SHORT); for (i = 0; i < finalCount; i++) { - fragments.add(formatter.unit(TIME_UNITS[unitIndices.get(i)]).format(unitValues.get(i)).toString().replace(' ', '\u2009')); + fragments.add(formatter.unit(TIME_UNITS[unitIndices.getInt(i)]).format(unitValues.getLong(i)).toString().replace(' ', '\u2009')); } return StringUtil.join(fragments, " "); } MeasureFormat format = MeasureFormat.getInstance(DynamicBundle.getLocale(), MeasureFormat.FormatWidth.SHORT); Measure[] measures = new Measure[finalCount]; for (i = 0; i < finalCount; i++) { - measures[i] = new Measure(unitValues.get(i), TIME_UNITS[unitIndices.get(i)]); + measures[i] = new Measure(unitValues.getLong(i), TIME_UNITS[unitIndices.getInt(i)]); } return format.formatMeasures(measures); } diff --git a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java index ee5fe9c36571..37214a1e85be 100644 --- a/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/keymap/KeymapUtil.java @@ -1,16 +1,18 @@ -// 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.keymap; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.NlsContexts; +import com.intellij.openapi.util.NlsSafe; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryValue; import com.intellij.openapi.util.registry.RegistryValueListener; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.SmartHashSet; import org.intellij.lang.annotations.JdkConstants; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -27,7 +29,6 @@ import static java.awt.event.InputEvent.ALT_DOWN_MASK; import static java.awt.event.InputEvent.CTRL_DOWN_MASK; public final class KeymapUtil { - @NonNls private static final String CANCEL_KEY_TEXT = "Cancel"; @NonNls private static final String BREAK_KEY_TEXT = "Break"; @NonNls private static final String SHIFT = "shift"; @@ -177,7 +178,7 @@ public final class KeymapUtil { private static boolean isNativeMacShortcuts() { return SystemInfo.isMac && !isSimplifiedMacShortcuts(); } - + private static boolean isSimplifiedMacShortcuts() { return SystemInfo.isMac && Registry.is("ide.macos.disable.native.shortcut.symbols", false); } @@ -576,7 +577,7 @@ public final class KeymapUtil { if (shortcuts.length == 0) { return Collections.emptySet(); } - Set result = new SmartHashSet<>(); + Set result = new HashSet<>(); for (Shortcut shortcut : shortcuts) { if (!(shortcut instanceof KeyboardShortcut)) { continue; diff --git a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java index c25544d079dd..dc88af9b1626 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.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.openapi.ui; import com.intellij.CommonBundle; @@ -34,6 +34,7 @@ import javax.swing.tree.*; import java.awt.*; import java.util.List; import java.util.*; +import java.util.function.Predicate; /** * @author anna @@ -637,14 +638,14 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom } protected final void checkForEmptyAndDuplicatedNames(String prefix, String title, - Class configurableClass) throws ConfigurationException { + Class> configurableClass) throws ConfigurationException { checkForEmptyAndDuplicatedNames(myRoot, prefix, title, configurableClass, true); } private void checkForEmptyAndDuplicatedNames(MyNode rootNode, String prefix, String title, - Class configurableClass, + Class> configurableClass, boolean recursively) throws ConfigurationException { final Set names = new HashSet<>(); for (int i = 0; i < rootNode.getChildCount(); i++) { @@ -778,13 +779,21 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom } protected class MyDeleteAction extends AnAction implements DumbAware { - private final Condition myCondition; + private final @Nullable Predicate myCondition; public MyDeleteAction() { - this(Conditions.alwaysTrue()); + this((Predicate)null); } - public MyDeleteAction(Condition availableCondition) { + /** + * @deprecated Use {@link #MyDeleteAction(Predicate)} + */ + @Deprecated + public MyDeleteAction(@Nullable Condition availableCondition) { + this(availableCondition == null ? null : (Predicate)availableCondition::value); + } + + public MyDeleteAction(@Nullable Predicate availableCondition) { super(CommonBundle.messagePointer("button.delete"), CommonBundle.messagePointer("button.delete"), PlatformIcons.DELETE_ICON); registerCustomShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE), myTree); myCondition = availableCondition; @@ -792,14 +801,23 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom @Override public void update(@NotNull AnActionEvent e) { - final Presentation presentation = e.getPresentation(); + Presentation presentation = e.getPresentation(); presentation.setEnabled(false); final TreePath[] selectionPath = myTree.getSelectionPaths(); - if (selectionPath != null) { - Object[] nodes = ContainerUtil.map2Array(selectionPath, TreePath::getLastPathComponent); - if (!myCondition.value(nodes)) return; - presentation.setEnabled(true); + if (selectionPath == null) { + return; } + + if (myCondition != null) { + Object[] result = new Object[selectionPath.length]; + for (int i = 0; i < selectionPath.length; i++) { + result[i] = selectionPath[i].getLastPathComponent(); + } + if (!myCondition.test(result)) { + return; + } + } + presentation.setEnabled(true); } @Override @@ -808,10 +826,12 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom } } - protected static Condition forAll(final Condition condition) { + protected static Predicate forAll(@NotNull Predicate condition) { return objects -> { for (Object object : objects) { - if (!condition.value(object)) return false; + if (!condition.test(object)) { + return false; + } } return true; }; diff --git a/platform/platform-api/src/com/intellij/openapi/ui/NamedConfigurable.java b/platform/platform-api/src/com/intellij/openapi/ui/NamedConfigurable.java index db3953726706..e5debe628740 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/NamedConfigurable.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/NamedConfigurable.java @@ -1,5 +1,4 @@ -// Copyright 2000-2018 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.ui; import com.intellij.ide.IdeBundle; diff --git a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java index 89b3a745a0a8..e8506d6e706f 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.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.openapi.ui; import com.intellij.ide.IdeBundle; @@ -12,7 +12,6 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.util.*; import com.intellij.util.IconUtil; import com.intellij.util.ui.tree.TreeUtil; -import gnu.trove.Equality; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,13 +24,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.function.BiPredicate; public abstract class NamedItemsListEditor extends MasterDetailsComponent { private final Namer myNamer; private final Factory myFactory; private final Cloner myCloner; private final List myItems = new ArrayList<>(); - private final Equality myComparer; + private final BiPredicate myComparer; private List myResultItems; private final List myOriginalItems; private boolean myShowIcons; @@ -39,7 +39,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { protected NamedItemsListEditor(Namer namer, Factory factory, Cloner cloner, - Equality comparer, + BiPredicate comparer, List items) { this(namer, factory, cloner, comparer, items, true); } @@ -47,7 +47,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { protected NamedItemsListEditor(Namer namer, Factory factory, Cloner cloner, - Equality comparer, + BiPredicate comparer, List items, boolean initInConstructor) { myNamer = namer; @@ -147,6 +147,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { protected List createActions(boolean fromPopup) { ArrayList result = new ArrayList<>(); result.add(new AddAction()); + //noinspection unchecked result.add(new MyDeleteAction(forAll(o -> canDelete((T)((MyNode)o).getConfigurable().getEditableObject())))); result.add(new CopyAction()); return result; @@ -181,7 +182,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { protected UnnamedConfigurable getItemConfigurable(final T item) { final Ref result = new Ref<>(); TreeUtil.traverse((TreeNode)myTree.getModel().getRoot(), node -> { - final NamedConfigurable configurable = (NamedConfigurable)((DefaultMutableTreeNode)node).getUserObject(); + final NamedConfigurable configurable = (NamedConfigurable)((DefaultMutableTreeNode)node).getUserObject(); if (configurable.getEditableObject() == item) { //noinspection unchecked result.set(((ItemConfigurable)configurable).myConfigurable); @@ -268,7 +269,9 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { if (myResultItems.size() != myItems.size()) return true; for (int i = 0; i < myItems.size(); i++) { - if (!myComparer.equals(myItems.get(i), myResultItems.get(i))) return true; + if (!myComparer.test(myItems.get(i), myResultItems.get(i))) { + return true; + } } return super.isModified(); @@ -324,7 +327,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { protected void onItemCloned(T clone) { } - private class AddAction extends DumbAwareAction { + private final class AddAction extends DumbAwareAction { AddAction() { super(IdeBundle.messagePointer("action.NamedItemsListEditor.AddAction.text.add"), IdeBundle.messagePointer("action.NamedItemsListEditor.AddAction.description.add"), IconUtil.getAddIcon()); diff --git a/platform/platform-api/src/com/intellij/openapi/vcs/LocalFilePath.java b/platform/platform-api/src/com/intellij/openapi/vcs/LocalFilePath.java index 24a4afce9572..f56d493424cb 100644 --- a/platform/platform-api/src/com/intellij/openapi/vcs/LocalFilePath.java +++ b/platform/platform-api/src/com/intellij/openapi/vcs/LocalFilePath.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.openapi.vcs; import com.intellij.openapi.editor.Document; @@ -7,13 +7,14 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.Strings; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.intellij.util.PathUtil; -import com.intellij.util.text.CaseInsensitiveStringHashingStrategy; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,9 +54,15 @@ public class LocalFilePath implements FilePath { LocalFilePath path = (LocalFilePath)o; - if (myIsDirectory != path.myIsDirectory) return false; - if (myPath.equals(path.myPath)) return true; - if (!CaseInsensitiveStringHashingStrategy.INSTANCE.equals(myPath, path.myPath)) return false; + if (myIsDirectory != path.myIsDirectory) { + return false; + } + if (myPath.equals(path.myPath)) { + return true; + } + if (!myPath.equalsIgnoreCase(path.myPath)) { + return false; + } // make sure to not query (expensive) getVirtualFile() until it's absolutely necessary, e.g. we encountered two file paths differ by case only VirtualFile file = getVirtualFile(); VirtualFile oFile = path.getVirtualFile(); @@ -65,7 +72,7 @@ public class LocalFilePath implements FilePath { @Override public int hashCode() { - int result = CaseInsensitiveStringHashingStrategy.INSTANCE.computeHashCode(myPath); + int result = Strings.stringHashCodeInsensitive(myPath); result = 31 * result + (myIsDirectory ? 1 : 0); return result; } @@ -106,7 +113,9 @@ public class LocalFilePath implements FilePath { @Nullable public VirtualFile getVirtualFile() { VirtualFile cachedFile = myCachedFile; - if (cachedFile == null || !cachedFile.isValid() || !FileUtil.PATH_HASHING_STRATEGY.equals(cachedFile.getPath(), myPath)) { + if (cachedFile == null || + !cachedFile.isValid() || + !(SystemInfoRt.isFileSystemCaseSensitive ? cachedFile.getPath().equals(myPath) : cachedFile.getPath().equalsIgnoreCase(myPath))) { myCachedFile = cachedFile = LocalFileSystem.getInstance().findFileByPath(myPath); } return cachedFile; diff --git a/platform/platform-api/src/com/intellij/ui/AnActionButton.java b/platform/platform-api/src/com/intellij/ui/AnActionButton.java index c86f4b1792a0..01a4f63a7401 100644 --- a/platform/platform-api/src/com/intellij/ui/AnActionButton.java +++ b/platform/platform-api/src/com/intellij/ui/AnActionButton.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.ui; import com.intellij.ide.DataManager; @@ -9,13 +9,13 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.NlsContexts; import com.intellij.ui.awt.RelativePoint; -import com.intellij.util.containers.SmartHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.function.Supplier; @@ -113,7 +113,7 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide public final void addCustomUpdater(@NotNull AnActionButtonUpdater updater) { if (myUpdaters == null) { - myUpdaters = new SmartHashSet<>(); + myUpdaters = new HashSet<>(); } myUpdaters.add(updater); } diff --git a/platform/platform-api/src/com/intellij/ui/ListFocusTraversalPolicy.java b/platform/platform-api/src/com/intellij/ui/ListFocusTraversalPolicy.java index 91ff74fd2b30..24ff01fbf99b 100644 --- a/platform/platform-api/src/com/intellij/ui/ListFocusTraversalPolicy.java +++ b/platform/platform-api/src/com/intellij/ui/ListFocusTraversalPolicy.java @@ -1,7 +1,7 @@ -// 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-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.ui; -import gnu.trove.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,10 +12,9 @@ import java.util.List; /** * Policy which defines explicit focus component cycle. */ -public class ListFocusTraversalPolicy extends LayoutFocusTraversalPolicy { - +public final class ListFocusTraversalPolicy extends LayoutFocusTraversalPolicy { private final Component[] myComponents; - private final TObjectIntHashMap myComponentToIndex; + private final Object2IntOpenHashMap myComponentToIndex; public ListFocusTraversalPolicy(@NotNull List components) { myComponents = components.toArray(new Component[0]); @@ -42,7 +41,7 @@ public class ListFocusTraversalPolicy extends LayoutFocusTraversalPolicy { if (!myComponentToIndex.containsKey(aComponent)) { return null; } - return getNextComponent(myComponentToIndex.get(aComponent) + 1); + return getNextComponent(myComponentToIndex.getInt(aComponent) + 1); } @Override @@ -50,7 +49,7 @@ public class ListFocusTraversalPolicy extends LayoutFocusTraversalPolicy { if (!myComponentToIndex.containsKey(aComponent)) { return null; } - return getPreviousComponent(myComponentToIndex.get(aComponent) - 1); + return getPreviousComponent(myComponentToIndex.getInt(aComponent) - 1); } @Nullable @@ -87,15 +86,12 @@ public class ListFocusTraversalPolicy extends LayoutFocusTraversalPolicy { return null; } - @NotNull - private static TObjectIntHashMap indexMap(X @NotNull [] array) { - TObjectIntHashMap map = new TObjectIntHashMap<>(array.length); + private static @NotNull Object2IntOpenHashMap indexMap(X @NotNull [] array) { + Object2IntOpenHashMap map = new Object2IntOpenHashMap<>(array.length); for (X x : array) { - if (!map.contains(x)) { - map.put(x, map.size()); - } + map.putIfAbsent(x, map.size()); } - map.compact(); + map.trim(); return map; } } diff --git a/plugins/generate-tostring/src/org/jetbrains/java/generate/view/TemplatesPanel.java b/plugins/generate-tostring/src/org/jetbrains/java/generate/view/TemplatesPanel.java index da3a62a8879c..4dc100a0292d 100644 --- a/plugins/generate-tostring/src/org/jetbrains/java/generate/view/TemplatesPanel.java +++ b/plugins/generate-tostring/src/org/jetbrains/java/generate/view/TemplatesPanel.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 org.jetbrains.java.generate.view; import com.intellij.java.JavaBundle; @@ -11,7 +11,6 @@ import com.intellij.openapi.util.Cloner; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.NlsContexts; -import gnu.trove.Equality; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -22,6 +21,7 @@ import org.jetbrains.java.generate.template.toString.ToStringTemplatesManager; import java.util.ArrayList; import java.util.Collections; import java.util.Objects; +import java.util.function.BiPredicate; public class TemplatesPanel extends NamedItemsListEditor { private static final Namer NAMER = new Namer<>() { @@ -59,7 +59,7 @@ public class TemplatesPanel extends NamedItemsListEditor { } }; - private static final Equality COMPARER = + private static final BiPredicate COMPARER = (o1, o2) -> Objects.equals(o1.getTemplate(), o2.getTemplate()) && Objects.equals(o1.getFileName(), o2.getFileName()); private final Project myProject; private final TemplatesManager myTemplatesManager;