This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support any nullability annotation. (#42)
- Loading branch information
1 parent
4059653
commit f290611
Showing
14 changed files
with
190 additions
and
50 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
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
22 changes: 22 additions & 0 deletions
22
rave-compiler/src/test/resources/fixtures/jsr305/JSR305Conflict.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,22 @@ | ||
package fixtures.jsr305; | ||
|
||
import fixtures.SampleFactory; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import com.uber.rave.annotation.Validated; | ||
|
||
@Validated(factory = SampleFactory.class) | ||
public class JSR305Conflict { | ||
String canBeNullField; | ||
|
||
public JSR305Conflict (String canBeNullField) { | ||
this.canBeNullField = canBeNullField; | ||
} | ||
|
||
@Nonnull | ||
@Nullable | ||
public String getCanBeNullField() { | ||
return canBeNullField; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
rave-compiler/src/test/resources/fixtures/jsr305/SampleFactory_Generated_Validator.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,47 @@ | ||
package fixtures; | ||
|
||
import com.uber.rave.BaseValidator; | ||
import com.uber.rave.InvalidModelException; | ||
import com.uber.rave.RaveError; | ||
import fixtures.jsr305.UseOfJSR305; | ||
import java.lang.Class; | ||
import java.lang.IllegalArgumentException; | ||
import java.lang.Object; | ||
import java.lang.Override; | ||
import java.util.List; | ||
import javax.annotation.Generated; | ||
|
||
@Generated( | ||
value = "com.uber.rave.compiler.RaveProcessor", | ||
comments = "https://github.com/uber-common/rave" | ||
) | ||
public final class SampleFactory_Generated_Validator extends BaseValidator { | ||
SampleFactory_Generated_Validator() { | ||
addSupportedClass(UseOfJSR305.class); | ||
registerSelf(); | ||
} | ||
|
||
@Override | ||
protected void validateAs(Object object, Class<?> clazz) throws InvalidModelException { | ||
if (!clazz.isInstance(object)) { | ||
throw new IllegalArgumentException(object.getClass().getCanonicalName() + "is not of type" + clazz.getCanonicalName()); | ||
} | ||
if (clazz.equals(UseOfJSR305.class)) { | ||
validateAs((UseOfJSR305) object); | ||
return; | ||
} | ||
throw new IllegalArgumentException(object.getClass().getCanonicalName() + " is not supported by validator " + this.getClass().getCanonicalName()); | ||
} | ||
|
||
private void validateAs(UseOfJSR305 object) throws InvalidModelException { | ||
BaseValidator.ValidationContext context = getValidationContext(UseOfJSR305.class); | ||
List<RaveError> raveErrors = null; | ||
context.setValidatedItemName("getNotNullField()"); | ||
raveErrors = mergeErrors(raveErrors, checkNullable(object.getNotNullField(), false, context)); | ||
context.setValidatedItemName("getCanBeNullField()"); | ||
raveErrors = mergeErrors(raveErrors, checkNullable(object.getCanBeNullField(), true, context)); | ||
if (raveErrors != null && !raveErrors.isEmpty()) { | ||
throw new InvalidModelException(raveErrors); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
rave-compiler/src/test/resources/fixtures/jsr305/UseOfJSR305.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 fixtures.jsr305; | ||
|
||
import fixtures.SampleFactory; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import com.uber.rave.annotation.Validated; | ||
|
||
@Validated(factory = SampleFactory.class) | ||
public class UseOfJSR305 { | ||
String notNullField; | ||
String canBeNullField; | ||
|
||
public UseOfJSR305 ( | ||
String notNullField, | ||
String canBeNullField) { | ||
this.notNullField = notNullField; | ||
this.canBeNullField = canBeNullField; | ||
} | ||
|
||
@Nonnull | ||
public String getNotNullField() { | ||
return notNullField; | ||
} | ||
|
||
@Nullable | ||
public String getCanBeNullField() { | ||
return canBeNullField; | ||
} | ||
} |
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.