int (@Nullable PsiFile file, @NotNull Document document, final int offset) { CharSequence text = document.getCharsSequence(); int correctedOffset = offset; int textLength = text.length(); if (offset >= textLength) { correctedOffset = textLength - 1; } else if (!isIdentifierPart(file, text, offset)) { correctedOffset--; } if (correctedOffset >= 0) { char charAt = text.charAt(correctedOffset); if (charAt == '\'' || charAt == '"' || charAt == ')' || charAt == ']' || isIdentifierPart(file, text, correctedOffset)) { return correctedOffset; } } return offset; }