Skip to content

Commit 410245a

Browse files
earcamearcam
authored andcommitted
Adding com.google.code.findbugs:jsr305
Signed-off-by: earcam <Caspar MacRae [email protected]>
1 parent 37d4ba7 commit 410245a

31 files changed

+839
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifierNickname;
8+
import javax.annotation.meta.When;
9+
10+
/**
11+
* The annotated element might be null, and uses of the element should check for null.
12+
* <p>
13+
* When this annotation is applied to a method it applies to the method return value.
14+
*/
15+
@Documented
16+
@TypeQualifierNickname
17+
@Nonnull(when = When.MAYBE)
18+
@Retention(RetentionPolicy.RUNTIME)
19+
public @interface CheckForNull {
20+
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifierNickname;
8+
import javax.annotation.meta.When;
9+
10+
/**
11+
* Used to annotate a value that may be either negative or nonnegative, and
12+
* indicates that uses of it should check for
13+
* negative values before using it in a way that requires the value to be
14+
* nonnegative, and check for it being nonnegative before using it in a way that
15+
* requires it to be negative.
16+
*/
17+
@Documented
18+
@TypeQualifierNickname
19+
@Nonnegative(when = When.MAYBE)
20+
@Retention(RetentionPolicy.RUNTIME)
21+
public @interface CheckForSigned {
22+
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
import javax.annotation.meta.When;
10+
11+
/**
12+
* This annotation is used to denote a method whose return value should always
13+
* be checked after invoking the method.
14+
*/
15+
@Documented
16+
@Target( { ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE,
17+
ElementType.PACKAGE })
18+
@Retention(RetentionPolicy.RUNTIME)
19+
public @interface CheckReturnValue {
20+
When when() default When.ALWAYS;
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifierNickname;
8+
import javax.annotation.meta.When;
9+
10+
@Documented
11+
@TypeQualifierNickname
12+
@Untainted(when = When.ALWAYS)
13+
@Retention(RetentionPolicy.RUNTIME)
14+
public @interface Detainted {
15+
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
/**
13+
* This annotation is used to denote String values that should always match given pattern.
14+
* <p>
15+
* When this annotation is applied to a method it applies to the method return value.
16+
*/
17+
@Documented
18+
@TypeQualifier(applicableTo = String.class)
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface MatchesPattern {
21+
@RegEx
22+
String value();
23+
24+
int flags() default 0;
25+
26+
static class Checker implements TypeQualifierValidator<MatchesPattern> {
27+
public When forConstantValue(MatchesPattern annotation, Object value) {
28+
Pattern p = Pattern.compile(annotation.value(), annotation.flags());
29+
if (p.matcher(((String) value)).matches())
30+
return When.ALWAYS;
31+
return When.NEVER;
32+
}
33+
34+
}
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifier;
8+
import javax.annotation.meta.TypeQualifierValidator;
9+
import javax.annotation.meta.When;
10+
11+
/**
12+
* This annotation is used to annotate a value that should only contain nonnegative values.
13+
* <p>
14+
* When this annotation is applied to a method it applies to the method return value.
15+
*/
16+
@Documented
17+
@TypeQualifier(applicableTo = Number.class)
18+
@Retention(RetentionPolicy.RUNTIME)
19+
public @interface Nonnegative {
20+
When when() default When.ALWAYS;
21+
22+
class Checker implements TypeQualifierValidator<Nonnegative> {
23+
24+
public When forConstantValue(Nonnegative annotation, Object v) {
25+
if (!(v instanceof Number))
26+
return When.NEVER;
27+
boolean isNegative;
28+
Number value = (Number) v;
29+
if (value instanceof Long)
30+
isNegative = value.longValue() < 0;
31+
else if (value instanceof Double)
32+
isNegative = value.doubleValue() < 0;
33+
else if (value instanceof Float)
34+
isNegative = value.floatValue() < 0;
35+
else
36+
isNegative = value.intValue() < 0;
37+
38+
if (isNegative)
39+
return When.NEVER;
40+
else
41+
return When.ALWAYS;
42+
43+
}
44+
}
45+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifier;
8+
import javax.annotation.meta.TypeQualifierValidator;
9+
import javax.annotation.meta.When;
10+
11+
/**
12+
* The annotated element must not be null.
13+
* <p>
14+
* Annotated fields must not be null after construction has completed.
15+
* <p>
16+
* When this annotation is applied to a method it applies to the method return value.
17+
*/
18+
@Documented
19+
@TypeQualifier
20+
@Retention(RetentionPolicy.RUNTIME)
21+
public @interface Nonnull {
22+
When when() default When.ALWAYS;
23+
24+
class Checker implements TypeQualifierValidator<Nonnull> {
25+
26+
public When forConstantValue(Nonnull qualifierArgument, Object value) {
27+
if (value == null)
28+
return When.NEVER;
29+
return When.ALWAYS;
30+
}
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
import javax.annotation.meta.TypeQualifierNickname;
8+
import javax.annotation.meta.When;
9+
10+
/**
11+
* The annotated element could be null under some circumstances.
12+
* <p>
13+
* In general, this means developers will have to read the documentation to
14+
* determine when a null value is acceptable and whether it is necessary to
15+
* check for a null value.
16+
* <p>
17+
* This annotation is useful mostly for overriding a {@link Nonnull} annotation.
18+
* Static analysis tools should generally treat the annotated items as though they
19+
* had no annotation, unless they are configured to minimize false negatives.
20+
* Use {@link CheckForNull} to indicate that the element value should always be checked
21+
* for a null value.
22+
* <p>
23+
* When this annotation is applied to a method it applies to the method return value.
24+
*/
25+
@Documented
26+
@TypeQualifierNickname
27+
@Nonnull(when = When.UNKNOWN)
28+
@Retention(RetentionPolicy.RUNTIME)
29+
public @interface Nullable {
30+
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
/**
10+
* When this annotation is applied to a method, it indicates that if this method
11+
* is overridden in a subclass, the overriding method should invoke this method
12+
* (through method invocation on super).
13+
* <p>
14+
* An example of such method is {@link Object#finalize()}.
15+
*/
16+
@Documented
17+
@Target( { ElementType.METHOD })
18+
@Retention(RetentionPolicy.RUNTIME)
19+
public @interface OverridingMethodsMustInvokeSuper {
20+
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package javax.annotation;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
8+
import javax.annotation.meta.TypeQualifierDefault;
9+
10+
/**
11+
* This annotation can be applied to a package, class or method to indicate that
12+
* the method parameters in that element are nonnull by default unless there is:
13+
* <ul>
14+
* <li>An explicit nullness annotation
15+
* <li>The method overrides a method in a superclass (in which case the
16+
* annotation of the corresponding parameter in the superclass applies)
17+
* <li>There is a default parameter annotation (like {@link ParametersAreNullableByDefault})
18+
* applied to a more tightly nested element.
19+
* </ul>
20+
*
21+
* @see Nonnull
22+
*/
23+
@Documented
24+
@Nonnull
25+
@TypeQualifierDefault(ElementType.PARAMETER)
26+
@Retention(RetentionPolicy.RUNTIME)
27+
public @interface ParametersAreNonnullByDefault {
28+
}

0 commit comments

Comments
 (0)