Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > c9dd5d0762274eef039ae33dd2a479f2 > files > 13

jsr-305-0-0.6.20090319svn.fc15.noarch.rpm

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.annotation.meta.TypeQualifier;
import javax.annotation.meta.TypeQualifierValidator;
import javax.annotation.meta.When;

@Documented
@TypeQualifier(applicableTo=String.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface FixedLengthString {
	int value();

	class Checker implements TypeQualifierValidator<FixedLengthString> {

		public When forConstantValue(FixedLengthString annotation, Object v) {
			if (!(v instanceof String))
				return When.NEVER;
			String s = (String) v;
			if (s.length() == annotation.value())
				return When.ALWAYS;
			return When.NEVER;
		}
	}
}