boolean (int caretOffset, PsiElement leaf, PsiReference ref, String expectedVariant) { if (expectedVariant == null) return false; int expectedEnd = ref != null ? ref.getRangeInElement().getEndOffset() + ref.getElement().getTextRange().getStartOffset() : leaf != null ? leaf.getTextRange().getEndOffset() : 0; return expectedEnd == caretOffset && getFile().getText().substring(0, caretOffset).endsWith(expectedVariant); }