DupInfo () { Object2IntMap<PsiFragment[]> duplicateList = new Object2IntOpenHashMap<>(); for (Int2ObjectMap.Entry<List<List<PsiFragment>>> entry : myDuplicates.int2ObjectEntrySet()) { for (List<PsiFragment> list : entry.getValue()) { int len = list.size(); if (len > 1) { PsiFragment[] filtered = new PsiFragment[len]; int idx = 0; for (PsiFragment fragment : list) { fragment.markDuplicate(); filtered[idx++] = fragment; } duplicateList.put(filtered, entry.getIntKey()); } } } myDuplicates = null; for (ObjectIterator<Object2IntMap.Entry<PsiFragment[]>> iterator = duplicateList.object2IntEntrySet().iterator(); iterator.hasNext(); ) { Object2IntMap.Entry<PsiFragment[]> entry = iterator.next(); PsiFragment[] fragments = entry.getKey(); LOG.assertTrue(fragments.length > 1); boolean nested = false; for (PsiFragment fragment : fragments) { if (fragment.isNested()) { nested = true; break; } } if (nested) { iterator.remove(); } } PsiFragment[][] duplicates = duplicateList.keySet().toArray(new PsiFragment[][]{}); Arrays.sort(duplicates, (x, y) -> y[0].getCost() - x[0].getCost()); return new DupInfo() { private final Int2ObjectMap<GroupNodeDescription> myPattern2Description = new Int2ObjectOpenHashMap<>(); @Override public int getPatterns() { return duplicates.length; } @Override public int getPatternCost(int number) { return ((PsiFragment[])duplicates[number])[0].getCost(); } @Override public int getPatternDensity(int number) { return duplicates[number].length; } @Override public PsiFragment[] getFragmentOccurences(int pattern) { return duplicates[pattern]; } @Override public UsageInfo[] getUsageOccurences(int pattern) { PsiFragment[] occurrences = getFragmentOccurences(pattern); UsageInfo[] infos = new UsageInfo[occurrences.length]; for (int i = 0; i < infos.length; i++) { infos[i] = occurrences[i].getUsageInfo(); } return infos; } @Override public int getFileCount(final int pattern) { if (myPattern2Description.containsKey(pattern)) { return myPattern2Description.get(pattern).getFilesCount(); } return cacheGroupNodeDescription(pattern).getFilesCount(); } private GroupNodeDescription cacheGroupNodeDescription(final int pattern) { final Set<PsiFile> files = new HashSet<>(); final PsiFragment[] occurrences = getFragmentOccurences(pattern); for (PsiFragment occurrence : occurrences) { final PsiFile file = occurrence.getFile(); if (file != null) { files.add(file); } } final int fileCount = files.size(); final PsiFile psiFile = occurrences[0].getFile(); DuplicatesProfile profile = DuplicatesProfile.findProfileForDuplicate(this, pattern); String comment = profile != null ? profile.getComment(this, pattern) : ""; String filename = psiFile != null ? psiFile.getName() : DupLocatorBundle.message("duplicates.unknown.file.node.title"); final GroupNodeDescription description = new GroupNodeDescription(fileCount, filename, comment); myPattern2Description.put(pattern, description); return description; } @Override public @Nullable @Nls String getTitle(int pattern) { if (getFileCount(pattern) == 1) { if (myPattern2Description.containsKey(pattern)) { return myPattern2Description.get(pattern).getTitle(); } return cacheGroupNodeDescription(pattern).getTitle(); } return null; } @Override public @Nullable @Nls String getComment(int pattern) { if (getFileCount(pattern) == 1) { if (myPattern2Description.containsKey(pattern)) { return myPattern2Description.get(pattern).getComment(); } return cacheGroupNodeDescription(pattern).getComment(); } return null; } @Override public int getHash(final int i) { return duplicateList.getInt(duplicates[i]); } }; }