-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding com.google.code.findbugs:jsr305
- Loading branch information
earcam
authored and
earcam
committed
Jul 17, 2018
1 parent
37d4ba7
commit d07243b
Showing
31 changed files
with
839 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* The annotated element might be null, and uses of the element should check for null. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@TypeQualifierNickname | ||
@Nonnull(when = When.MAYBE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CheckForNull { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* Used to annotate a value that may be either negative or nonnegative, and | ||
* indicates that uses of it should check for | ||
* negative values before using it in a way that requires the value to be | ||
* nonnegative, and check for it being nonnegative before using it in a way that | ||
* requires it to be negative. | ||
*/ | ||
@Documented | ||
@TypeQualifierNickname | ||
@Nonnegative(when = When.MAYBE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CheckForSigned { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* This annotation is used to denote a method whose return value should always | ||
* be checked after invoking the method. | ||
*/ | ||
@Documented | ||
@Target( { ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, | ||
ElementType.PACKAGE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CheckReturnValue { | ||
When when() default When.ALWAYS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
@Documented | ||
@TypeQualifierNickname | ||
@Untainted(when = When.ALWAYS) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Detainted { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.annotation.meta.TypeQualifier; | ||
import javax.annotation.meta.TypeQualifierValidator; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* This annotation is used to denote String values that should always match given pattern. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@TypeQualifier(applicableTo = String.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MatchesPattern { | ||
@RegEx | ||
String value(); | ||
|
||
int flags() default 0; | ||
|
||
static class Checker implements TypeQualifierValidator<MatchesPattern> { | ||
public When forConstantValue(MatchesPattern annotation, Object value) { | ||
Pattern p = Pattern.compile(annotation.value(), annotation.flags()); | ||
if (p.matcher(((String) value)).matches()) | ||
return When.ALWAYS; | ||
return When.NEVER; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package javax.annotation; | ||
|
||
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; | ||
|
||
/** | ||
* This annotation is used to annotate a value that should only contain nonnegative values. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@TypeQualifier(applicableTo = Number.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Nonnegative { | ||
When when() default When.ALWAYS; | ||
|
||
class Checker implements TypeQualifierValidator<Nonnegative> { | ||
|
||
public When forConstantValue(Nonnegative annotation, Object v) { | ||
if (!(v instanceof Number)) | ||
return When.NEVER; | ||
boolean isNegative; | ||
Number value = (Number) v; | ||
if (value instanceof Long) | ||
isNegative = value.longValue() < 0; | ||
else if (value instanceof Double) | ||
isNegative = value.doubleValue() < 0; | ||
else if (value instanceof Float) | ||
isNegative = value.floatValue() < 0; | ||
else | ||
isNegative = value.intValue() < 0; | ||
|
||
if (isNegative) | ||
return When.NEVER; | ||
else | ||
return When.ALWAYS; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package javax.annotation; | ||
|
||
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; | ||
|
||
/** | ||
* The annotated element must not be null. | ||
* <p> | ||
* Annotated fields must not be null after construction has completed. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@TypeQualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Nonnull { | ||
When when() default When.ALWAYS; | ||
|
||
class Checker implements TypeQualifierValidator<Nonnull> { | ||
|
||
public When forConstantValue(Nonnull qualifierArgument, Object value) { | ||
if (value == null) | ||
return When.NEVER; | ||
return When.ALWAYS; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* The annotated element could be null under some circumstances. | ||
* <p> | ||
* In general, this means developers will have to read the documentation to | ||
* determine when a null value is acceptable and whether it is necessary to | ||
* check for a null value. | ||
* <p> | ||
* This annotation is useful mostly for overriding a {@link Nonnull} annotation. | ||
* Static analysis tools should generally treat the annotated items as though they | ||
* had no annotation, unless they are configured to minimize false negatives. | ||
* Use {@link CheckForNull} to indicate that the element value should always be checked | ||
* for a null value. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@TypeQualifierNickname | ||
@Nonnull(when = When.UNKNOWN) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Nullable { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/javax/annotation/OverridingMethodsMustInvokeSuper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* When this annotation is applied to a method, it indicates that if this method | ||
* is overridden in a subclass, the overriding method should invoke this method | ||
* (through method invocation on super). | ||
* <p> | ||
* An example of such method is {@link Object#finalize()}. | ||
*/ | ||
@Documented | ||
@Target( { ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface OverridingMethodsMustInvokeSuper { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/javax/annotation/ParametersAreNonnullByDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierDefault; | ||
|
||
/** | ||
* This annotation can be applied to a package, class or method to indicate that | ||
* the method parameters in that element are nonnull by default unless there is: | ||
* <ul> | ||
* <li>An explicit nullness annotation | ||
* <li>The method overrides a method in a superclass (in which case the | ||
* annotation of the corresponding parameter in the superclass applies) | ||
* <li>There is a default parameter annotation (like {@link ParametersAreNullableByDefault}) | ||
* applied to a more tightly nested element. | ||
* </ul> | ||
* | ||
* @see Nonnull | ||
*/ | ||
@Documented | ||
@Nonnull | ||
@TypeQualifierDefault(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ParametersAreNonnullByDefault { | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/javax/annotation/ParametersAreNullableByDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierDefault; | ||
|
||
/** | ||
* This annotation can be applied to a package, class or method to indicate that | ||
* the method parameters in that element are nullable by default unless there is: | ||
* <ul> | ||
* <li>An explicit nullness annotation | ||
* <li>The method overrides a method in a superclass (in which case the | ||
* annotation of the corresponding parameter in the superclass applies) | ||
* <li>There is a default parameter annotation applied to a more tightly nested element. | ||
* </ul> | ||
* <p>This annotation implies the same "nullness" as no annotation. However, it is different | ||
* than having no annotation, as it is inherited and it can override a {@link ParametersAreNonnullByDefault} | ||
* annotation at an outer scope. | ||
* | ||
* @see Nullable | ||
*/ | ||
@Documented | ||
@Nullable | ||
@TypeQualifierDefault(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ParametersAreNullableByDefault { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifier; | ||
import javax.annotation.meta.When; | ||
|
||
@Documented | ||
@TypeQualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface PropertyKey { | ||
When when() default When.ALWAYS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.util.regex.Pattern; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.TypeQualifierValidator; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* This qualifier is used to denote String values that should be a Regular | ||
* expression. | ||
* <p> | ||
* When this annotation is applied to a method it applies to the method return value. | ||
*/ | ||
@Documented | ||
@Syntax("RegEx") | ||
@TypeQualifierNickname | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface RegEx { | ||
When when() default When.ALWAYS; | ||
|
||
static class Checker implements TypeQualifierValidator<RegEx> { | ||
|
||
public When forConstantValue(RegEx annotation, Object value) { | ||
if (!(value instanceof String)) | ||
return When.NEVER; | ||
|
||
try { | ||
Pattern.compile((String) value); | ||
} catch (PatternSyntaxException e) { | ||
return When.NEVER; | ||
} | ||
return When.ALWAYS; | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* Used to annotate a value of unknown sign. | ||
*/ | ||
@Documented | ||
@TypeQualifierNickname | ||
@Nonnegative(when = When.UNKNOWN) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Signed { | ||
|
||
} |
Oops, something went wrong.