1 /*
2 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1741
1742 public static final Pattern noMatches = Pattern.compile("(\\P{all})+");
1743
1744 /**
1745 * Convert import-style string for supported annotations into a
1746 * regex matching that string. If the string is not a valid
1747 * import-style string, return a regex that won't match anything.
1748 */
1749 private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log, boolean lint) {
1750 String module;
1751 String pkg;
1752 int slash = s.indexOf('/');
1753 if (slash == (-1)) {
1754 if (s.equals("*")) {
1755 return MatchingUtils.validImportStringToPattern(s);
1756 }
1757 module = allowModules ? ".*/" : "";
1758 pkg = s;
1759 } else {
1760 String moduleName = s.substring(0, slash);
1761 if (!SourceVersion.isIdentifier(moduleName)) {
1762 return warnAndNoMatches(s, p, log, lint);
1763 }
1764 module = Pattern.quote(moduleName + "/");
1765 // And warn if module is specified if modules aren't supported, conditional on -Xlint:proc?
1766 pkg = s.substring(slash + 1);
1767 }
1768 if (MatchingUtils.isValidImportString(pkg)) {
1769 return Pattern.compile(module + MatchingUtils.validImportStringToPatternString(pkg));
1770 } else {
1771 return warnAndNoMatches(s, p, log, lint);
1772 }
1773 }
1774
1775 private static Pattern warnAndNoMatches(String s, Processor p, Log log, boolean lint) {
1776 if (lint) {
1777 log.warning(Warnings.ProcMalformedSupportedString(s, p.getClass().getName()));
1778 }
1779 return noMatches; // won't match any valid identifier
1780 }
1781
|
1 /*
2 * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1741
1742 public static final Pattern noMatches = Pattern.compile("(\\P{all})+");
1743
1744 /**
1745 * Convert import-style string for supported annotations into a
1746 * regex matching that string. If the string is not a valid
1747 * import-style string, return a regex that won't match anything.
1748 */
1749 private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log, boolean lint) {
1750 String module;
1751 String pkg;
1752 int slash = s.indexOf('/');
1753 if (slash == (-1)) {
1754 if (s.equals("*")) {
1755 return MatchingUtils.validImportStringToPattern(s);
1756 }
1757 module = allowModules ? ".*/" : "";
1758 pkg = s;
1759 } else {
1760 String moduleName = s.substring(0, slash);
1761 if (!SourceVersion.isName(moduleName)) {
1762 return warnAndNoMatches(s, p, log, lint);
1763 }
1764 module = Pattern.quote(moduleName + "/");
1765 // And warn if module is specified if modules aren't supported, conditional on -Xlint:proc?
1766 pkg = s.substring(slash + 1);
1767 }
1768 if (MatchingUtils.isValidImportString(pkg)) {
1769 return Pattern.compile(module + MatchingUtils.validImportStringToPatternString(pkg));
1770 } else {
1771 return warnAndNoMatches(s, p, log, lint);
1772 }
1773 }
1774
1775 private static Pattern warnAndNoMatches(String s, Processor p, Log log, boolean lint) {
1776 if (lint) {
1777 log.warning(Warnings.ProcMalformedSupportedString(s, p.getClass().getName()));
1778 }
1779 return noMatches; // won't match any valid identifier
1780 }
1781
|