Skip to content

Commit

Permalink
IDEA-157786 File matching pattern results showed twice for some files
Browse files Browse the repository at this point in the history
  • Loading branch information
donnerpeter committed Jul 28, 2016
1 parent d7563b0 commit cf93ba7
Showing 1 changed file with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ public void actionPerformed(@NotNull final AnActionEvent e) {
presentation.setTargetsNodeText("Unsorted " + StringUtil.toLowerCase(patternToLowerCase(prefixPattern)));
final Object[][] elements = getElements();
final List<PsiElement> targets = new ArrayList<PsiElement>();
final List<Usage> usages = new ArrayList<Usage>();
final Set<Usage> usages = new LinkedHashSet<>();
fillUsages(Arrays.asList(elements[0]), usages, targets, false);
fillUsages(Arrays.asList(elements[1]), usages, targets, true);
if (myListModel.contains(EXTRA_ELEM)) { //start searching for the rest
Expand Down Expand Up @@ -1747,19 +1747,14 @@ public void onError(@NotNull Exception error) {
}

private void fillUsages(Collection<Object> matchElementsArray,
List<Usage> usages,
Collection<Usage> usages,
List<PsiElement> targets,
final boolean separateGroup) {
for (Object o : matchElementsArray) {
if (o instanceof PsiElement) {
PsiElement element = (PsiElement)o;
if (element.getTextRange() != null) {
usages.add(new UsageInfo2UsageAdapter(new UsageInfo(element) {
@Override
public boolean isDynamicUsage() {
return separateGroup || super.isDynamicUsage();
}
}));
usages.add(new MyUsageInfo2UsageAdapter(element, separateGroup));
}
else {
targets.add(element);
Expand All @@ -1769,7 +1764,7 @@ public boolean isDynamicUsage() {
}

private void showUsageView(@NotNull List<PsiElement> targets,
@NotNull List<Usage> usages,
@NotNull Collection<Usage> usages,
@NotNull UsageViewPresentation presentation) {
UsageTarget[] usageTargets = targets.isEmpty() ? UsageTarget.EMPTY_ARRAY :
PsiElement2UsageTargetAdapter.convert(PsiUtilCore.toPsiElementArray(targets));
Expand All @@ -1789,6 +1784,42 @@ public void update(@NotNull AnActionEvent e) {
public abstract Object[][] getElements();
}

private static class MyUsageInfo2UsageAdapter extends UsageInfo2UsageAdapter {
private final PsiElement myElement;
private final boolean mySeparateGroup;

MyUsageInfo2UsageAdapter(@NotNull PsiElement element, boolean separateGroup) {
super(new UsageInfo(element) {
@Override
public boolean isDynamicUsage() {
return separateGroup || super.isDynamicUsage();
}
});
myElement = element;
mySeparateGroup = separateGroup;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MyUsageInfo2UsageAdapter)) return false;

MyUsageInfo2UsageAdapter adapter = (MyUsageInfo2UsageAdapter)o;

if (mySeparateGroup != adapter.mySeparateGroup) return false;
if (!myElement.equals(adapter.myElement)) return false;

return true;
}

@Override
public int hashCode() {
int result = myElement.hashCode();
result = 31 * result + (mySeparateGroup ? 1 : 0);
return result;
}
}

public JTextField getTextField() {
return myTextField;
}
Expand Down

0 comments on commit cf93ba7

Please sign in to comment.