author | jlahoda |
Tue, 13 Dec 2016 10:49:28 +0100 | |
changeset 42815 | 050370edaade |
parent 29427 | 44f4e6905b67 |
permissions | -rw-r--r-- |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
1 |
/* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
4 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
10 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
15 |
* accompanied this code). |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
16 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
20 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
23 |
* questions. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
24 |
*/ |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
25 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.util; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
27 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
28 |
import java.util.regex.Pattern; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
29 |
import javax.lang.model.SourceVersion; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
30 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
31 |
/**Utilities to convert an import-like string to a regexp. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
32 |
* |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
33 |
* <p><b>This is NOT part of any supported API. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
34 |
* If you write code that depends on this, you do so at your own risk. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
35 |
* This code and its internal interfaces are subject to change or |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
36 |
* deletion without notice.</b> |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
37 |
*/ |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
38 |
public class MatchingUtils { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
39 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
40 |
private static final String allMatchesString = ".*"; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
41 |
private static final Pattern allMatches = Pattern.compile(allMatchesString); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
42 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
43 |
/** |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
44 |
* Return true if the argument string is a valid import-style |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
45 |
* string specifying claimed annotations; return false otherwise. |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
46 |
*/ |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
47 |
public static boolean isValidImportString(String s) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
48 |
if (s.equals("*")) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
49 |
return true; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
50 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
51 |
boolean valid = true; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
52 |
String t = s; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
53 |
int index = t.indexOf('*'); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
54 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
55 |
if (index != -1) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
56 |
// '*' must be last character... |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
57 |
if (index == t.length() -1) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
58 |
// ... any and preceding character must be '.' |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
59 |
if ( index-1 >= 0 ) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
60 |
valid = t.charAt(index-1) == '.'; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
61 |
// Strip off ".*$" for identifier checks |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
62 |
t = t.substring(0, t.length()-2); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
63 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
64 |
} else |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
65 |
return false; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
66 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
67 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
68 |
// Verify string is off the form (javaId \.)+ or javaId |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
69 |
if (valid) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
70 |
String[] javaIds = t.split("\\.", t.length()+2); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
71 |
for(String javaId: javaIds) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
72 |
valid &= SourceVersion.isIdentifier(javaId); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
73 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
74 |
return valid; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
75 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
76 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
77 |
public static String validImportStringToPatternString(String s) { |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
78 |
if (s.equals("*")) { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
79 |
return allMatchesString; |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
80 |
} else { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
81 |
String s_prime = s.replace(".", "\\."); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
82 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
83 |
if (s_prime.endsWith("*")) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
84 |
s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+"; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
85 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
86 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
87 |
return s_prime; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
88 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
89 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
90 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
91 |
public static Pattern validImportStringToPattern(String s) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
92 |
String pattern = validImportStringToPatternString(s); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
93 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
94 |
if (pattern == allMatchesString) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
95 |
return allMatches; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
96 |
} else { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
29427
diff
changeset
|
97 |
return Pattern.compile(pattern); |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
98 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
99 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
100 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
diff
changeset
|
101 |
} |