コード例 #1
0
 /**
  * requires: condition is a string representation of a conditional
  *
  * @return a list of all possible variable variable names in condition. arrays appear with "[]" at
  *     the end if their elements or accessed in the condition.
  */
 private static List<String> findPossibleClassVariables(String condition) throws ParseException {
   NodeToken[] tokens = TokenExtractor.extractTokens(condition);
   // System.out.println("TokenExtractor.extractTokens(" + condition + ") ==> " +
   // ArraysMDE.toString(tokens));
   List<String> variables = new ArrayList<String>();
   if (tokens.length >= 1) {
     if (tokens[0].kind == IDENTIFIER && (tokens.length <= 1 || tokens[1].kind != LPAREN)) {
       variables.add(tokens[0].tokenImage);
     }
   }
   if (tokens.length >= 2) {
     if (tokens[1].kind == IDENTIFIER
         && (tokens.length <= 2 || tokens[2].kind != LPAREN)
         && (!variables.contains(tokens[1].tokenImage))) {
       variables.add(tokens[1].tokenImage);
     }
   }
   for (int i = 2; i < tokens.length - 1; i++) {
     NodeToken token = tokens[i];
     if (token.kind == IDENTIFIER
         && tokens[i - 1].kind != DOT
         && tokens[i + 1].kind != LPAREN
         && (!variables.contains(token.tokenImage))) {
       variables.add(token.tokenImage);
     }
   }
   if (tokens.length >= 3) {
     int lastIndex = tokens.length - 1;
     if (tokens[lastIndex].kind == IDENTIFIER
         && tokens[lastIndex - 1].kind != DOT
         && (!variables.contains(tokens[lastIndex].tokenImage))) {
       variables.add(tokens[lastIndex].tokenImage);
     }
   }
   // System.out.println("findPossibleClassVariables(" + condition + ") ==> " +
   // variables.toString());
   return variables;
 }
コード例 #2
0
 /** Returns true if the variable represented by varInfo is used in this splitting condition. */
 private static boolean isNeeded(String name, List<String> vars) {
   return vars.contains(name);
 }