title: Antl4 no rule index for labelled rules
body: <p>For the grammar snippet from Java.g4,</p>
  
  <pre><code>statement
      :   block                                             # blockStmt
      |   'if' parExpression statement ('else' statement)?  # ifStmt
      |   'for' '(' forControl ')' statement                # forStmt
      |   'while' parExpression statement                   # whileStmt
      ;
  </code></pre>
  
  <p>All the alternatives are labelled.
  I can get all StatementContext objects using this method</p>
  
  <p>Trees.getAllRuleNodes(root,JavaParser.Rule_statement);</p>
  
  <p>But if I am only interested in getting the IfStmtContext objects, how can I use the above method without using something like this</p>
  
  <pre><code>for(ParseTree tree : statementContextList)
  {
  if(tree instanceof IfStmtContext)
  {
  //add to a list
  }
  </code></pre>
  
  <p>The generated JavaParser doesnt create rule indexes for labelled rules. 
  Do I have to customize the grammar in some way to make them indexed? 
  Or there is another ways do this?</p>
  
  <p>My code should be fast and I need to remove as much as iterations and conditions as possible. Need to get rid of the 'instanceof'  checks as well as possible</p>