int (@NotNull String text) { int offset = myPsiElement.getTextOffset(); if (offset > text.length()) return -1; String cutText = text.substring(0, offset); String cutTextWithoutBogusWords = cutText.replaceAll(PSI_EXPR_MASK, "").replaceAll(PSI_CONDITIONAL_EXPR_MASK, ""); return offset - (cutText.length() - cutTextWithoutBogusWords.length()); }