-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into type-use-location-nested-class
- Loading branch information
Showing
22 changed files
with
1,493 additions
and
94 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
54 changes: 54 additions & 0 deletions
54
annotations/src/main/java/com/uber/nullaway/annotations/EnsuresNonNullIf.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,54 @@ | ||
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 the method | ||
* returns true in case the fields are non-null. The method can also return false in case the fields | ||
* are non-null (inverse logic), and in such case, you must set {@code result} to false. NullAway | ||
* verifies that the property holds. | ||
* | ||
* <p>Here is an example: | ||
* | ||
* <pre> | ||
* class Foo { | ||
* {@literal @}Nullable Object theField; | ||
* | ||
* {@literal @}EnsuresNonNullIf("theField", result=true) // "this.theField" is also valid | ||
* boolean hasTheField() { | ||
* return theField != null; | ||
* } | ||
* | ||
* void bar() { | ||
* if(!hasTheField()) { | ||
* return; | ||
* } | ||
* | ||
* // No error, NullAway knows theField is non-null after call to hasTheField() | ||
* theField.toString(); | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
@Retention(RetentionPolicy.CLASS) | ||
@Target({ElementType.METHOD}) | ||
public @interface EnsuresNonNullIf { | ||
/** | ||
* The list of fields that are non-null after the method returns the given result. | ||
* | ||
* @return The list of field names | ||
*/ | ||
String[] value(); | ||
|
||
/** | ||
* The return value of the method under which the postcondition holds. The default is set to true, | ||
* which means the method should return true in case fields are non-null. | ||
* | ||
* @return true or false | ||
*/ | ||
boolean result() default true; | ||
} |
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
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
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
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
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
Oops, something went wrong.