diff --git a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java index c0fe923f9e4c..e0ef589cd2ef 100644 --- a/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java +++ b/platform/lang-impl/src/com/intellij/find/replaceInProject/ReplaceInProjectManager.java @@ -58,7 +58,6 @@ import com.intellij.usages.rules.UsageInFile; import com.intellij.util.AdapterProcessor; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.*; @@ -491,8 +490,8 @@ public class ReplaceInProjectManager { return true; } - private void replaceUsagesUnderCommand(@NotNull final ReplaceContext replaceContext, @Nullable final Set usagesSet) { - if (usagesSet == null) { + private void replaceUsagesUnderCommand(@NotNull final ReplaceContext replaceContext, @NotNull final Set usagesSet) { + if (usagesSet.isEmpty()) { return; } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/ui/ReplaceUsageViewContext.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/ui/ReplaceUsageViewContext.java index 2c43042dc847..f71d1b7fc6ef 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/ui/ReplaceUsageViewContext.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/ui/ReplaceUsageViewContext.java @@ -31,6 +31,7 @@ import com.intellij.usages.Usage; import com.intellij.usages.UsageInfo2UsageAdapter; import com.intellij.usages.UsageView; import com.intellij.util.ObjectUtils; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.stream.Collectors; @@ -65,7 +66,7 @@ class ReplaceUsageViewContext extends UsageViewContext { final Runnable previewReplacement = () -> { final Set selection = myUsageView.getSelectedUsages(); - if (selection == null || selection.isEmpty()) { + if (selection.isEmpty()) { return; } for (Usage usage : selection) { @@ -85,10 +86,7 @@ class ReplaceUsageViewContext extends UsageViewContext { myUsageView.addButtonToLowerPane(previewReplacement, SSRBundle.message("preview.replacement.button")); } - private void replace(Collection usages) { - if (usages == null) { - return; - } + private void replace(@NotNull Collection usages) { final Set excluded = myUsageView.getExcludedUsages(); usages = usages.stream().filter(u -> !excluded.contains(u)).filter(u -> isValid((UsageInfo2UsageAdapter)u)).collect(Collectors.toList()); diff --git a/platform/usageView/src/com/intellij/usages/UsageView.java b/platform/usageView/src/com/intellij/usages/UsageView.java index 82fa8851feb7..2e93e9354f3d 100644 --- a/platform/usageView/src/com/intellij/usages/UsageView.java +++ b/platform/usageView/src/com/intellij/usages/UsageView.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -81,8 +81,7 @@ public interface UsageView extends Disposable { @NotNull Set getExcludedUsages(); - @Nullable - Set getSelectedUsages(); + @NotNull Set getSelectedUsages(); @NotNull Set getUsages(); @NotNull List getSortedUsages(); diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 11cd89d8eaa7..e7bf59a5ece3 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -1470,12 +1470,12 @@ public class UsageViewImpl implements UsageView { } @Override - @Nullable + @NotNull public Set getSelectedUsages() { ApplicationManager.getApplication().assertIsDispatchThread(); TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { - return null; + return Collections.emptySet(); } Set usages = new THashSet<>(); @@ -1679,7 +1679,7 @@ public class UsageViewImpl implements UsageView { else if (key == USAGES_KEY) { final Set selectedUsages = getSelectedUsages(); - sink.put(USAGES_KEY, selectedUsages != null ? selectedUsages.toArray(new Usage[selectedUsages.size()]) : null); + sink.put(USAGES_KEY, selectedUsages.toArray(new Usage[selectedUsages.size()])); } else if (key == USAGE_TARGETS_KEY) {