Skip to content

Commit

Permalink
Adding com.google.code.findbugs:jsr305
Browse files Browse the repository at this point in the history
Signed-off-by: Caspar MacRae <[email protected]>
  • Loading branch information
earcam authored and earcam committed Jul 18, 2018
1 parent 37d4ba7 commit 96cb22d
Show file tree
Hide file tree
Showing 31 changed files with 839 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/javax/annotation/CheckForNull.java
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 {

}
23 changes: 23 additions & 0 deletions src/main/java/javax/annotation/CheckForSigned.java
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 {

}
21 changes: 21 additions & 0 deletions src/main/java/javax/annotation/CheckReturnValue.java
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;
}
16 changes: 16 additions & 0 deletions src/main/java/javax/annotation/Detainted.java
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 {

}
35 changes: 35 additions & 0 deletions src/main/java/javax/annotation/MatchesPattern.java
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;
}

}
}
45 changes: 45 additions & 0 deletions src/main/java/javax/annotation/Nonnegative.java
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;

}
}
}
32 changes: 32 additions & 0 deletions src/main/java/javax/annotation/Nonnull.java
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;
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/javax/annotation/Nullable.java
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 {

}
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 src/main/java/javax/annotation/ParametersAreNonnullByDefault.java
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 src/main/java/javax/annotation/ParametersAreNullableByDefault.java
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 {
}
15 changes: 15 additions & 0 deletions src/main/java/javax/annotation/PropertyKey.java
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;
}
43 changes: 43 additions & 0 deletions src/main/java/javax/annotation/RegEx.java
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;

}

}

}
19 changes: 19 additions & 0 deletions src/main/java/javax/annotation/Signed.java
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 {

}
Loading

0 comments on commit 96cb22d

Please sign in to comment.