/**
  * Replaces instances of Java reserved words that could not appear in a valid Java condition or
  * Java variable name that are being used as variable names in string.
  *
  * @param string the string in which the Java reserved words should be replaced.
  * @return string with the Java reserved words replaced with a substitute names.
  */
 private static String replaceReservedWords(String string) {
   // cheap hack so that pattern never need to look for a key word at
   // the beginning or end of string.  That way one may simplify the pattern
   // to looking for a reserved word that is not prefixed or suffix with a
   // letter or number.
   string = "(" + string + ")";
   for (int i = 0; i < reservedWords.length; i++) {
     String reservedWord = reservedWords[i];
     Pattern p = Pattern.compile("([\\W])(" + reservedWord + ")([\\W])");
     Matcher m = p.matcher(string);
     while (m.find()) {
       string = m.replaceFirst(m.group(1) + "daikon" + reservedWord + m.group(3));
       m = p.matcher(string);
     }
   }
   return string.substring(1, string.length() - 1);
 }
Пример #2
0
 static {
   try {
     non_word_pattern = Pattern.compile("\\W+");
     orig_pattern = Pattern.compile("orig\\s*\\(");
     dot_class_pattern = Pattern.compile("\\.class");
     inequality_pattern = Pattern.compile("[\\!<>]=");
     gteq_pattern = Pattern.compile(">=");
     lteq_pattern = Pattern.compile("<=");
     neq_pattern = Pattern.compile("\\!=");
     contradict_inv_pattern =
         Pattern.compile("(^| && )(.*) == -?[0-9]+ &.*& \\2 == -?[0-9]+($| && )");
     useless_inv_pattern_1 =
         Pattern.compile("(^| && )(.*) > -?[0-9]+ &.*& \\2 > -?[0-9]+($| && )");
     useless_inv_pattern_2 =
         Pattern.compile("(^| && )(.*) < -?[0-9]+ &.*& \\2 < -?[0-9]+($| && )");
   } catch (PatternSyntaxException me) {
     throw new Error("ExtractConsequent: Error while compiling pattern " + me.getMessage());
   }
 }
Пример #3
0
 private static boolean contains_exactly_one(String string, Pattern pattern) {
   Matcher m = pattern.matcher(string);
   // return true if first call returns true and second returns false
   return (m.find() && !m.find());
 }