-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose @EnsuresNonNull and @RequiresNonNull in annotations package (#999
- Loading branch information
Showing
7 changed files
with
80 additions
and
47 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
annotations/src/main/java/com/uber/nullaway/annotations/EnsuresNonNull.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,34 @@ | ||
package com.uber.nullaway.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* An annotation describing a nullability post-condition for an instance method. Each parameter to | ||
* the annotation should be a field of the enclosing class. The method must ensure that whenever the | ||
* method exits normally, the fields listed in the annotation are non-null. NullAway verifies that | ||
* this property holds, and the property is used when checking call sites of the method. Here is an | ||
* example: | ||
* | ||
* <pre> | ||
* class Foo { | ||
* {@literal @}Nullable Object theField; | ||
* {@literal @}EnsuresNonNull("theField") // @EnsuresNonNull("this.theField") is also valid | ||
* void foo() { | ||
* theField = new Object(); | ||
* } | ||
* void bar() { | ||
* foo(); | ||
* // No error, NullAway knows theField is non-null after call to foo() | ||
* theField.toString(); | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
@Retention(RetentionPolicy.CLASS) | ||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) | ||
public @interface EnsuresNonNull { | ||
String[] value(); | ||
} |
37 changes: 37 additions & 0 deletions
37
annotations/src/main/java/com/uber/nullaway/annotations/RequiresNonNull.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,37 @@ | ||
package com.uber.nullaway.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* An annotation describing a nullability pre-condition for an instance method. Each parameter to | ||
* the annotation should be a field of the enclosing class. Each call site of the method must ensure | ||
* that the fields listed in the annotation are non-null before the call. NullAway verifies that | ||
* this property holds, and uses the property when checking the body of the method. Here is an | ||
* example: | ||
* | ||
* <pre> | ||
* class Foo { | ||
* {@literal @}Nullable Object theField; | ||
* {@literal @}RequiresNonNull("theField") // @RequiresNonNull("this.theField") is also valid | ||
* void foo() { | ||
* // No error, NullAway knows theField is non-null after foo() | ||
* theField.toString(); | ||
* } | ||
* void bar() { | ||
* // Error, theField may be null before the call to foo() | ||
* foo(); | ||
* this.theField = new Object(); | ||
* // No error | ||
* foo(); | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
@Retention(RetentionPolicy.CLASS) | ||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) | ||
public @interface RequiresNonNull { | ||
String[] value(); | ||
} |
19 changes: 0 additions & 19 deletions
19
nullaway/src/main/java/com/uber/nullaway/annotations/EnsuresNonNull.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
nullaway/src/main/java/com/uber/nullaway/annotations/RequiresNonNull.java
This file was deleted.
Oops, something went wrong.
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
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
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