PsiReference[] (final PsiElement element, final List<? extends PsiReference> references) { Map<TextRange, PsiReference> byTextRanges = new LinkedHashMap<>(); for (PsiReference reference : references) { final TextRange textRange = reference.getRangeInElement(); final PsiReference psiReference = byTextRanges.get(textRange); if (psiReference == null) { byTextRanges.put(textRange, reference); } else if (psiReference instanceof PsiDynaReference) { ((PsiDynaReference<?>)psiReference).addReference(reference); } else { byTextRanges.put(textRange, createDynaReference(element, textRange, reference, psiReference)); } } return byTextRanges.values().toArray(PsiReference.EMPTY_ARRAY); }