private static @Nullable PsiElement getContextElement(@Nullable PsiFile file, int offset) {
    if (file == null) return null;
    if (offset == file.getTextLength()) {
      offset = Math.max(0, offset - 1);
    }
    return file.findElementAt(offset);
  }
private static @Nullable PsiElement getContextElement(@Nullable PsiFile file, int offset)