1 package javax.annotation; 2 3 import java.lang.annotation.Documented; 4 import java.lang.annotation.Retention; 5 import java.lang.annotation.RetentionPolicy; 6 import java.util.regex.Pattern; 7 8 import javax.annotation.meta.TypeQualifier; 9 import javax.annotation.meta.TypeQualifierValidator; 10 import javax.annotation.meta.When; 11 12 @Documented 13 @TypeQualifier(applicableTo = String.class) 14 @Retention(RetentionPolicy.RUNTIME) 15 public @interface MatchesPattern { 16 @RegEx 17 String value(); 18 19 int flags() default 0; 20 21 static class Checker implements TypeQualifierValidator<MatchesPattern> { 22 public When forConstantValue(MatchesPattern annotation, Object value) { 23 Pattern p = Pattern.compile(annotation.value(), annotation.flags()); 24 if (p.matcher(((String) value)).matches()) 25 return When.ALWAYS; 26 return When.NEVER; 27 } 28 29 } 30 } 31