PsiElement (@Nullable PsiElement nameIdentifier, @NotNull Collection<? extends PsiReference> refs, @NotNull Collection<? extends Pair<PsiElement, TextRange>> stringUsages, int offset) { //prefer reference in case of self-references for (PsiReference ref : refs) { PsiElement element = ref.getElement(); if (checkRangeContainsOffset(offset, ref.getRangeInElement(), element)) return element; } if (nameIdentifier != null) { TextRange range = nameIdentifier.getTextRange(); if (range != null && checkRangeContainsOffset(offset, range, nameIdentifier, 0)) return nameIdentifier; } for (Pair<PsiElement, TextRange> stringUsage : stringUsages) { if (checkRangeContainsOffset(offset, stringUsage.second, stringUsage.first)) return stringUsage.first; } LOG.error(nameIdentifier + " by " + this.getClass().getName()); return null; }