@Override public boolean equals(Object o) { if (!(o instanceof TypeQualifierAnnotation)) { return false; } TypeQualifierAnnotation other = (TypeQualifierAnnotation) o; return typeQualifier.equals(other.typeQualifier) && when.equals(other.when); }
@Override public int hashCode() { return typeQualifier.hashCode() * 37 + when.hashCode(); }
private static TypeQualifierAnnotation combineAnnotations(TypeQualifierAnnotation a, TypeQualifierAnnotation b, When[][] mergeMatrix) { assert a.typeQualifier.equals(b.typeQualifier); When aWhen = a.when; When bWhen = b.when; if (aWhen.ordinal() < bWhen.ordinal()) { When tmp = aWhen; aWhen = bWhen; bWhen = tmp; } When combined = mergeMatrix[aWhen.ordinal()][bWhen.ordinal()]; if (combined != null) { return getValue(a.typeQualifier, combined); } else { return null; } }
public class Ideas_2011_10_24 { @Documented @TypeQualifier() @Retention(RetentionPolicy.RUNTIME) public @interface PK {} @NoWarning("TQ") @PK int asPK(int v) { return v; } @ExpectWarning("TQ") @PK int asPK(boolean b, int v) { if (b) System.out.println("true"); return v; } @NoWarning("TQ") boolean isFive(@PK int v) { return v == 5; } @ExpectWarning("TQ") boolean isFive(@PK int v, int x) { return v == x; } }
public class Ideas_2011_09_24 { @Documented @TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface PK {} @TypeQualifier(applicableTo = CharSequence.class) @Retention(RetentionPolicy.RUNTIME) public @interface SlashedClassName { @TypeQualifierNickname @Retention(RetentionPolicy.RUNTIME) public @interface DottedClassName {
private CheckReturnValueAnnotation createJSR305Annotation(AnnotationEntry entry) { for (ElementValuePair pair : entry.getElementValuePairs()) { if (!pair.getNameString().equals("when")) { continue; } return CheckReturnValueAnnotation.createFor(When.valueOf(pair.getValue().stringifyValue())); } // use default value return CheckReturnValueAnnotation.createFor(When.ALWAYS); }
@TypeQualifierDefault(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ReturnValuesAreNonnullByDefault {
@CheckForNull public static CheckReturnValueAnnotation createFor(@NonNull When when) { switch (when.name()) { case "NEVER": case "UNKNOWN": return CheckReturnValueAnnotation.CHECK_RETURN_VALUE_IGNORE; case "MAYBE": return CheckReturnValueAnnotation.CHECK_RETURN_VALUE_MEDIUM_BAD_PRACTICE; case "ALWAYS": return CheckReturnValueAnnotation.CHECK_RETURN_VALUE_HIGH; default: return null; } } }
public class Ideas_2012_12_03 { @Documented @Retention(RetentionPolicy.RUNTIME) @TypeQualifier public @interface PK { } @Documented @TypeQualifier(applicableTo = CharSequence.class) @Retention(RetentionPolicy.RUNTIME) public @interface SlashedClassName { public static final String NOT_AVAILABLE = "./."; When when() default When.ALWAYS; } @NoWarning("TQ") @PK int foo(@PK int x, int y) { return x; } @NoWarning("TQ") @SlashedClassName String foo() { return null; } }
public class Ideas_2013_01_29 { @TypeQualifier @Retention(RetentionPolicy.RUNTIME) public @interface Foo { @TypeQualifierNickname public @interface NotFoo { } @TypeQualifierNickname public @interface MaybeFoo { }
@Override public int hashCode() { int result = 1; result = PRIME * result + ((constantValue == null) ? 0 : constantValue.hashCode()); result = PRIME * result + (interproc ? 1231 : 1237); result = PRIME * result + local; result = PRIME * result + ((location == null) ? 0 : location.hashCode()); result = PRIME * result + parameter; result = PRIME * result + ((type == null) ? 0 : type.hashCode()); result = PRIME * result + ((vn == null) ? 0 : vn.hashCode()); result = PRIME * result + ((when == null) ? 0 : when.hashCode()); return result; }
/** * Resolve a raw AnnotationValue into a TypeQualifierAnnotation. * * @param v * a raw AnnotationValue * @return a constructed TypeQualifierAnnotation */ public static TypeQualifierAnnotation constructTypeQualifierAnnotation(AnnotationValue v) { assert v != null; EnumValue whenValue = (EnumValue) v.getValue("when"); When when = whenValue == null ? When.ALWAYS : When.valueOf(whenValue.value); ClassDescriptor annotationClass = v.getAnnotationClass(); TypeQualifierValue<?> tqv = TypeQualifierValue.getValue(annotationClass, v.getValue("value")); TypeQualifierAnnotation tqa = TypeQualifierAnnotation.getValue(tqv, when); return tqa; }
@Bug2311143b.ReturnValueIsNonnullByDefault public class Bug2311143b { @Documented @Nonnull @TypeQualifierDefault(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ReturnValueIsNonnullByDefault { } @CheckForNull private static List<String> getMagic() { return Collections.emptyList(); } public int complain() { return getMagic().size(); } public static final class InnerClass { public void doMagic() { List<String> contextualTabs = getMagic(); if (contextualTabs != null) { System.out.println("checked for null, but still generated a warning"); } } } }
public class Ideas_2012_02_01 { @TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface Foo { @TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface Bar {
@TypeQualifier(applicableTo = Number.class) @Retention(RetentionPolicy.RUNTIME) static public @interface Even {
public class Ideas_2011_01_17 { @Documented @TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface PK {
public class Ideas_2011_08_31 { @TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface PK {
public class Ideas_2013_05_06 { @TypeQualifier(applicableTo = Long.class) @Retention(RetentionPolicy.RUNTIME) public @interface PK {
@TypeQualifier public @interface PK { @Documented @Retention(RetentionPolicy.RUNTIME) @TypeQualifier public @interface PK2 {
@TypeQualifier(applicableTo = Integer.class) @Retention(RetentionPolicy.RUNTIME) public @interface AnalysisFeature {