public static void fillAllVariablesInScope(Map<String,VarSymbol> vars,Stack<JCTree> scanningStack,JCTree from,JCTree to){
  if (from == to) {
    return;
  }
  int i=scanningStack.indexOf(from);
  if (i == -1 || i == 0) {
    return;
  }
  JCTree parent=scanningStack.get(i - 1);
  List<JCStatement> statements=null;
switch (parent.getKind()) {
case BLOCK:
    statements=((JCBlock)parent).stats;
  break;
case CASE:
statements=((JCCase)parent).stats;
break;
case CATCH:
putVar(vars,((JCCatch)parent).param.sym);
break;
case FOR_LOOP:
if (((JCForLoop)parent).init != null) {
for (JCStatement s : ((JCForLoop)parent).init) {
if (s instanceof JCVariableDecl) {
putVar(vars,((JCVariableDecl)s).sym);
}
}
}
break;
case ENHANCED_FOR_LOOP:
putVar(vars,((JCEnhancedForLoop)parent).var.sym);
break;
case METHOD:
for (JCVariableDecl var : ((JCMethodDecl)parent).params) {
putVar(vars,var.sym);
}
break;
default :
}
if (statements != null) {
for (JCStatement s : statements) {
if (s == from) {
break;
}
 else if (s instanceof JCVariableDecl) {
putVar(vars,((JCVariableDecl)s).sym);
}
}
}
fillAllVariablesInScope(vars,scanningStack,parent,to);
}

public static void fillAllVariablesInScope ( Map < String , VarSymbol > vars , Stack < JCTree > scanningStack , JCTree from , JCTree to ) { if ( from == to ) { return ; } int i = scanningStack . indexOf ( from ) ; if ( i == - 1 || i == 0 ) { return ; } JCTree parent = scanningStack . get ( i - 1 ) ; List < JCStatement > statements = null ; switch ( parent . getKind ( ) ) { case BLOCK : statements = ( ( JCBlock ) parent ) . stats ; break ; case CASE : statements = ( ( JCCase ) parent ) . stats ; break ; case CATCH : putVar ( vars , ( ( JCCatch ) parent ) . param . sym ) ; break ; case FOR_LOOP : if ( ( ( JCForLoop ) parent ) . init != null ) { for ( JCStatement s : ( ( JCForLoop ) parent ) . init ) { if ( s instanceof JCVariableDecl ) { putVar ( vars , ( ( JCVariableDecl ) s ) . sym ) ; } } } break ; case ENHANCED_FOR_LOOP : putVar ( vars , ( ( JCEnhancedForLoop ) parent ) . var . sym ) ; break ; case METHOD : for ( JCVariableDecl var : ( ( JCMethodDecl ) parent ) . params ) { putVar ( vars , var . sym ) ; } break ; default : } if ( statements != null ) { for ( JCStatement s : statements ) { if ( s == from ) { break ; } else if ( s instanceof JCVariableDecl ) { putVar ( vars , ( ( JCVariableDecl ) s ) . sym ) ; } } } fillAllVariablesInScope ( vars , scanningStack , parent , to ) ; }
finds all the variables accessible within the current scanning scope .
