langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MatchingUtils.java
changeset 42815 050370edaade
parent 29427 44f4e6905b67
equal deleted inserted replaced
42814:058fc03646d9 42815:050370edaade
    34  *  If you write code that depends on this, you do so at your own risk.
    34  *  If you write code that depends on this, you do so at your own risk.
    35  *  This code and its internal interfaces are subject to change or
    35  *  This code and its internal interfaces are subject to change or
    36  *  deletion without notice.</b>
    36  *  deletion without notice.</b>
    37  */
    37  */
    38 public class MatchingUtils {
    38 public class MatchingUtils {
    39     private static final Pattern allMatches = Pattern.compile(".*");
    39 
       
    40     private static final String allMatchesString = ".*";
       
    41     private static final Pattern allMatches = Pattern.compile(allMatchesString);
    40 
    42 
    41     /**
    43     /**
    42      * Return true if the argument string is a valid import-style
    44      * Return true if the argument string is a valid import-style
    43      * string specifying claimed annotations; return false otherwise.
    45      * string specifying claimed annotations; return false otherwise.
    44      */
    46      */
    70                 valid &= SourceVersion.isIdentifier(javaId);
    72                 valid &= SourceVersion.isIdentifier(javaId);
    71         }
    73         }
    72         return valid;
    74         return valid;
    73     }
    75     }
    74 
    76 
    75     public static Pattern validImportStringToPattern(String s) {
    77     public static String validImportStringToPatternString(String s) {
    76         if (s.equals("*")) {
    78         if (s.equals("*")) {
    77             return allMatches;
    79             return allMatchesString;
    78         } else {
    80         } else {
    79             String s_prime = s.replace(".", "\\.");
    81             String s_prime = s.replace(".", "\\.");
    80 
    82 
    81             if (s_prime.endsWith("*")) {
    83             if (s_prime.endsWith("*")) {
    82                 s_prime =  s_prime.substring(0, s_prime.length() - 1) + ".+";
    84                 s_prime =  s_prime.substring(0, s_prime.length() - 1) + ".+";
    83             }
    85             }
    84 
    86 
    85             return Pattern.compile(s_prime);
    87             return s_prime;
       
    88         }
       
    89     }
       
    90 
       
    91     public static Pattern validImportStringToPattern(String s) {
       
    92         String pattern = validImportStringToPatternString(s);
       
    93 
       
    94         if (pattern == allMatchesString) {
       
    95             return allMatches;
       
    96         } else {
       
    97             return Pattern.compile(pattern);
    86         }
    98         }
    87     }
    99     }
    88 
   100 
    89 }
   101 }