/**
   * Return whether a class of the specified type exists between the node argument and the topParent
   * argument.
   *
   * @param node Node
   * @param intermediateParentClass Class
   * @param topParent Node
   * @return boolean
   */
  public static boolean hasAsParentBetween(
      Node node, Class<?> intermediateParentClass, Node topParent) {

    Node currentParent = node.jjtGetParent();

    while (currentParent != topParent) {
      currentParent = currentParent.jjtGetParent();
      if (currentParent.getClass().equals(intermediateParentClass)) return true;
    }
    return false;
  }