@SuppressWarnings("unchecked")
  protected static StatementSequence findEnclosingStatementSequence(
      IFortranAST ast, ITextSelection selection) {
    Token firstToken = findFirstTokenAfter(ast, selection.getOffset());
    Token lastToken = findLastTokenBefore(ast, selection.getOffset() + selection.getLength());
    if (firstToken == null || lastToken == null) return null;

    IASTListNode<? extends IASTNode> listContainingFirstToken =
        firstToken.findNearestAncestor(IASTListNode.class);
    IASTListNode<? extends IASTNode> listContainingLastToken =
        lastToken.findNearestAncestor(IASTListNode.class);
    if (listContainingFirstToken == null
        || listContainingLastToken == null
        || listContainingFirstToken != listContainingLastToken) return null;

    IASTListNode<? extends IASTNode> listContainingStmts = listContainingFirstToken;
    int startIndex = -1;
    int endIndex = -1;
    for (int i = 0; i < listContainingStmts.size(); i++) {
      IASTNode node = listContainingStmts.get(i);
      if (contains(node, firstToken)) startIndex = i;
      if (contains(node, lastToken)) endIndex = i;
    }
    if (startIndex < 0 || endIndex < 0 || endIndex < startIndex)
      throw new Error(
          "INTERNAL ERROR: Unable to locate selected statements in IASTListNode"); //$NON-NLS-1$

    return new StatementSequence(
        listContainingStmts.findNearestAncestor(ScopingNode.class),
        listContainingStmts,
        startIndex,
        endIndex);
  }
 protected static <T extends IASTNode> T getNode(
     Token firstToken, Token lastToken, Class<T> node) {
   assert (firstToken != null);
   assert (lastToken != null);
   T firstTokenNode = firstToken.findNearestAncestor(node);
   T lastTokenNode = lastToken.findNearestAncestor(node);
   if (firstTokenNode == null || lastTokenNode == null || firstTokenNode != lastTokenNode)
     return null;
   return firstTokenNode;
   // return null;
 }
  private Set<ASTCallStmtNode> getCallSites() {
    List<Definition> subroutineDefinitions =
        selectedSubroutine.getSubroutineName().getSubroutineName().resolveBinding();
    HashSet<ASTCallStmtNode> result = new HashSet<ASTCallStmtNode>();

    if (subroutineDefinitions.size() != 1)
      return result; // probably should throw an error of some sort!

    for (PhotranTokenRef tokenRef : subroutineDefinitions.get(0).findAllReferences(true)) {
      Token token = tokenRef.findToken();

      ASTCallStmtNode callStmtNode = token.findNearestAncestor(ASTCallStmtNode.class);

      if (callStmtNode != null) result.add(callStmtNode);
    }

    return result;
  }