private static boolean isAncestor(@NotNull PsiElement ancestor, @Nullable TreePath path) {
    while (path != null) {
      if (isElement(ancestor, path)) return true;
      path = path.getParentPath();
    }
    return false;
  }
private static boolean isAncestor(@NotNull PsiElement ancestor, @Nullable TreePath path)