protected static IASTNode findEnclosingNode(IFortranAST ast, ITextSelection selection) {
    Token firstToken = findFirstTokenAfter(ast, selection.getOffset());
    Token lastToken =
        findLastTokenBefore(
            ast, OffsetLength.getPositionPastEnd(selection.getOffset(), selection.getLength()));
    if (firstToken == null || lastToken == null) return null;

    for (IASTNode parent = lastToken.getParent(); parent != null; parent = parent.getParent())
      if (contains(parent, firstToken)) return parent;

    return null;
  }
  protected static boolean nodeExactlyEnclosesRegion(
      IASTNode node, IFortranAST ast, ITextSelection selection) {
    Token firstInNode = node.findFirstToken();
    Token lastInNode = node.findLastToken();

    Token firstInSel = findFirstTokenAfter(ast, selection.getOffset());
    Token lastInSel =
        findLastTokenBefore(
            ast, OffsetLength.getPositionPastEnd(selection.getOffset(), selection.getLength()));

    return firstInNode != null
        && lastInNode != null
        && firstInSel != null
        && lastInSel != null
        && firstInNode == firstInSel
        && lastInNode == lastInSel;
  }