1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
import org.checkerframework.checker.regex.qual.Regex;
import org.checkerframework.framework.qual.EnsuresQualifierIf;
public class RegexUtilTest {
void fullyQualifiedRegexUtil(String s) {
if (org.checkerframework.checker.regex.RegexUtil.isRegex(s, 2)) {
@Regex(2) String s2 = s;
}
@Regex(2) String s2 = org.checkerframework.checker.regex.RegexUtil.asRegex(s, 2);
}
void unqualifiedRegexUtil(String s) {
if (RegexUtil.isRegex(s, 2)) {
@Regex(2) String s2 = s;
}
@Regex(2) String s2 = RegexUtil.asRegex(s, 2);
}
void fullyQualifiedRegexUtilNoParamsArg(String s) {
if (org.checkerframework.checker.regex.RegexUtil.isRegex(s)) {
@Regex String s2 = s;
@Regex(0) String s3 = s;
}
@Regex String s2 = org.checkerframework.checker.regex.RegexUtil.asRegex(s);
@Regex(0) String s3 = org.checkerframework.checker.regex.RegexUtil.asRegex(s);
}
void unqualifiedRegexUtilNoParamsArg(String s) {
if (RegexUtil.isRegex(s)) {
@Regex String s2 = s;
@Regex(0) String s3 = s;
}
@Regex String s2 = RegexUtil.asRegex(s, 2);
@Regex(0) String s3 = RegexUtil.asRegex(s, 2);
}
void illegalName(String s) {
if (IllegalName.isRegex(s, 2)) {
// :: error: (assignment.type.incompatible)
@Regex(2) String s2 = s;
}
// :: error: (assignment.type.incompatible)
@Regex(2) String s2 = IllegalName.asRegex(s, 2);
}
void illegalNameRegexUtil(String s) {
if (IllegalNameRegexUtil.isRegex(s, 2)) {
// :: error: (assignment.type.incompatible)
@Regex(2) String s2 = s;
}
// :: error: (assignment.type.incompatible)
@Regex(2) String s2 = IllegalNameRegexUtil.asRegex(s, 2);
}
}
// A dummy RegexUtil class to make sure RegexUtil in no package works.
class RegexUtil {
@EnsuresQualifierIf(result = true, expression = "#1", qualifier = Regex.class)
public static boolean isRegex(final String s, int n) {
return false;
}
public static @Regex String asRegex(String s, int n) {
return null;
}
@EnsuresQualifierIf(result = true, expression = "#1", qualifier = Regex.class)
public static boolean isRegex(final String s) {
return false;
}
public static @Regex String asRegex(String s) {
return null;
}
}
// These methods shouldn't work.
class IllegalName {
public static boolean isRegex(String s, int n) {
return false;
}
public static @Regex String asRegex(String s, int n) {
return null;
}
}
// These methods shouldn't work.
class IllegalNameRegexUtil {
public static boolean isRegex(String s, int n) {
return false;
}
public static @Regex String asRegex(String s, int n) {
return null;
}
}
|