-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@NotNull as alias for @Required #5161
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -441,13 +459,13 @@ private boolean categorizeIndexField(Element element, VariableElement variableEl | |||
private void categorizeRequiredField(Element element, VariableElement variableElement) { | |||
if (Utils.isPrimitiveType(variableElement)) { | |||
Utils.error(String.format(Locale.US, | |||
"@Required annotation is unnecessary for primitive field \"%s\".", element)); | |||
"@Required and @NotNull annotation is unnecessary for primitive field \"%s\".", element)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// In order to fully support the Kotlin type system we interpret `@NotNull` as an alias | ||
// for `@Required` | ||
for (AnnotationMirror annotation : field.getAnnotationMirrors()) { | ||
if (annotation.getAnnotationType().toString().equals("org.jetbrains.annotations.NotNull")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use field.getAnnotation(Required.class)
? you don't want to pull the dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean @NotNull
, but yes.
return; | ||
} | ||
|
||
if (Utils.isRealmList(variableElement) || Utils.isRealmModel(variableElement)) { | ||
if (Utils.isRealmModel(variableElement)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why removing the isRealmList
check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it conflicted with Kotlin mostly. RealmList is always non-null for managed object. I don't know why we didn't allow this to be set. At worst it would be redundant information.
@NotNull as alias for @required (realm#5161)
This PR adds support for org.jetbrains.annotations.NotNull as an alias for @required. This means that Realm now understands the Kotlin type-system in the Realm schema. Previously we reported an error if you did @required RealmList<MyType> list = new RealmList<>();. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do @required RealmList<MyType> list = new RealmLis<>() as well as val list : RealmList<MyType> = RealmList(); After this change it is no longer possible to do val person : Person either, you have to do val person : Person?. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter.
…sor) (#5168) * @NotNull as alias for @required (#5161) This PR adds support for org.jetbrains.annotations.NotNull as an alias for @required. This means that Realm now understands the Kotlin type-system in the Realm schema. Previously we reported an error if you did @required RealmList<MyType> list = new RealmList<>();. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do @required RealmList<MyType> list = new RealmLis<>() as well as val list : RealmList<MyType> = RealmList(); After this change it is no longer possible to do val person : Person either, you have to do val person : Person?. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter. * implement elemenrt type check of RealmList * fix error message * remove extra line * fix typo * address review comments
* Add Primitive List fields to test classes * removed tests for Primitive List for now * removed tests for Primitive List for now * Primitive List feature(Part5: Element type check in annotation processor) (#5168) * @NotNull as alias for @required (#5161) This PR adds support for org.jetbrains.annotations.NotNull as an alias for @required. This means that Realm now understands the Kotlin type-system in the Realm schema. Previously we reported an error if you did @required RealmList<MyType> list = new RealmList<>();. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do @required RealmList<MyType> list = new RealmLis<>() as well as val list : RealmList<MyType> = RealmList(); After this change it is no longer possible to do val person : Person either, you have to do val person : Person?. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter. * implement elemenrt type check of RealmList * fix error message * remove extra line * fix typo * address review comments
…sts) (#5151) * solve compilation errors related to Primitive List API changes * revert test * fix FB warnings * fix failing tests * Primitive List feature(Part4: Tests) (#5152) * Add Primitive List fields to test classes * removed tests for Primitive List for now * removed tests for Primitive List for now * Primitive List feature(Part5: Element type check in annotation processor) (#5168) * @NotNull as alias for @required (#5161) This PR adds support for org.jetbrains.annotations.NotNull as an alias for @required. This means that Realm now understands the Kotlin type-system in the Realm schema. Previously we reported an error if you did @required RealmList<MyType> list = new RealmList<>();. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do @required RealmList<MyType> list = new RealmLis<>() as well as val list : RealmList<MyType> = RealmList(); After this change it is no longer possible to do val person : Person either, you have to do val person : Person?. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter. * implement elemenrt type check of RealmList * fix error message * remove extra line * fix typo * address review comments
* Nullability changes for Primitive List support * more @nullable annotations * fix annotation order * Primitive List feature(Part3: Temporary fix of implementations and tests) (#5151) * solve compilation errors related to Primitive List API changes * revert test * fix FB warnings * fix failing tests * Primitive List feature(Part4: Tests) (#5152) * Add Primitive List fields to test classes * removed tests for Primitive List for now * removed tests for Primitive List for now * Primitive List feature(Part5: Element type check in annotation processor) (#5168) * @NotNull as alias for @required (#5161) This PR adds support for org.jetbrains.annotations.NotNull as an alias for @required. This means that Realm now understands the Kotlin type-system in the Realm schema. Previously we reported an error if you did @required RealmList<MyType> list = new RealmList<>();. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do @required RealmList<MyType> list = new RealmLis<>() as well as val list : RealmList<MyType> = RealmList(); After this change it is no longer possible to do val person : Person either, you have to do val person : Person?. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter. * implement elemenrt type check of RealmList * fix error message * remove extra line * fix typo * address review comments
This PR adds support for
org.jetbrains.annotations.NotNull
as an alias for@Required
. This means that Realm now understands the Kotlin type-system in the Realm schema.Previously we reported an error if you did
@Required RealmList<MyType> list = new RealmList<>();
. It is a bit unclear why, since a RealmList is always non-null on managed objects. Since it made the interop with Kotlin kinda strange, I made a change so you can now do@Required RealmList<MyType> list = new RealmLis<>()
as well asval list : RealmList<MyType> = RealmList();
After this change it is no longer possible to do
val person : Person
either, you have to doval person : Person?
. This reflects the constraints of Realm, but if people are able to maintain the variant themselves (hint: not possible when using sync), then they can use a custom non-null getter.