--- old/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2010-02-17 14:30:09.000000000 -0800 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2010-02-17 14:30:09.000000000 -0800 @@ -25,7 +25,6 @@ package com.sun.tools.javac.processing; - import java.lang.reflect.*; import java.util.*; import java.util.regex.*; @@ -1355,115 +1354,62 @@ return specifiedPackages; } - // Borrowed from DocletInvoker and apt - // TODO: remove from apt's Main + private static final Pattern allMatches = Pattern.compile(".*"); + public static final Pattern noMatches = Pattern.compile("(\\P{all})+"); + /** - * Utility method for converting a search path string to an array - * of directory and JAR file URLs. - * - * @param path the search path string - * @return the resulting array of directory and JAR file URLs - */ - public static URL[] pathToURLs(String path) { - StringTokenizer st = new StringTokenizer(path, File.pathSeparator); - URL[] urls = new URL[st.countTokens()]; - int count = 0; - while (st.hasMoreTokens()) { - URL url = fileToURL(new File(st.nextToken())); - if (url != null) { - urls[count++] = url; - } - } - if (urls.length != count) { - URL[] tmp = new URL[count]; - System.arraycopy(urls, 0, tmp, 0, count); - urls = tmp; + * Convert import-style string for supported annotations into a + * regex matching that string. If the string is a valid + * import-style string, return a regex that won't match anything. + */ + private static Pattern importStringToPattern(String s, Processor p, Log log) { + if (isValidImportString(s)) { + return validImportStringToPattern(s); + } else { + log.warning("proc.malformed.supported.string", s, p.getClass().getName()); + return noMatches; // won't match any valid identifier } - return urls; } /** - * Returns the directory or JAR file URL corresponding to the specified - * local file name. - * - * @param file the File object - * @return the resulting directory or JAR file URL, or null if unknown + * Return true if the argument string is a valid import-style + * string specifying claimed annotations; return false otherwise. */ - private static URL fileToURL(File file) { - String name; - try { - name = file.getCanonicalPath(); - } catch (IOException e) { - name = file.getAbsolutePath(); - } - name = name.replace(File.separatorChar, '/'); - if (!name.startsWith("/")) { - name = "/" + name; - } - // If the file does not exist, then assume that it's a directory - if (!file.isFile()) { - name = name + "/"; + public static boolean isValidImportString(String s) { + if (s.equals("*")) + return true; + + boolean valid = true; + String t = s; + int index = t.indexOf('*'); + + if (index != -1) { + // '*' must be last character... + if (index == t.length() -1) { + // ... any and preceding character must be '.' + if ( index-1 >= 0 ) { + valid = t.charAt(index-1) == '.'; + // Strip off ".*$" for identifier checks + t = t.substring(0, t.length()-2); + } + } else + return false; } - try { - return new URL("file", "", name); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("file"); + + // Verify string is off the form (javaId \.)+ or javaId + if (valid) { + String[] javaIds = t.split("\\.", t.length()+2); + for(String javaId: javaIds) + valid &= SourceVersion.isIdentifier(javaId); } + return valid; } - - - private static final Pattern allMatches = Pattern.compile(".*"); - - private static final Pattern noMatches = Pattern.compile("(\\P{all})+"); - /** - * Convert import-style string to regex matching that string. If - * the string is a valid import-style string, return a regex that - * won't match anything. - */ - // TODO: remove version in Apt.java - public static Pattern importStringToPattern(String s, Processor p, Log log) { + public static Pattern validImportStringToPattern(String s) { if (s.equals("*")) { return allMatches; } else { - String t = s; - boolean star = false; - - /* - * Validate string from factory is legal. If the string - * has more than one asterisks or the asterisks does not - * appear as the last character (preceded by a period), - * the string is not legal. - */ - - boolean valid = true; - int index = t.indexOf('*'); - if (index != -1) { - // '*' must be last character... - if (index == t.length() -1) { - // ... and preceeding character must be '.' - if ( index-1 >= 0 ) { - valid = t.charAt(index-1) == '.'; - // Strip off ".*$" for identifier checks - t = t.substring(0, t.length()-2); - } - } else - valid = false; - } - - // Verify string is off the form (javaId \.)+ or javaId - if (valid) { - String[] javaIds = t.split("\\.", t.length()+2); - for(String javaId: javaIds) - valid &= SourceVersion.isIdentifier(javaId); - } - - if (!valid) { - log.warning("proc.malformed.supported.string", s, p.getClass().getName()); - return noMatches; // won't match any valid identifier - } - - String s_prime = s.replaceAll("\\.", "\\\\."); + String s_prime = s.replace(".", "\\."); if (s_prime.endsWith("*")) { s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+";