code: public int countTokens() 
    {
      int savedPosition = position;
      int count=0;
      while (hasMoreTokens())
      {
        nextToken();
        count++;
      }
      position = savedPosition;
      return count;
    }
docs: Calculates the number of times that this tokenizer's
  <code>nextToken</code> method can be called before it generates an
  exception. The current position is not advanced.
  
  @return  the number of tokens remaining in the string using the current
  delimiter set.
  @see     uk.org.skeet.util.JlsTokenizer#nextToken()