Skip to content

Commit

Permalink
MF-5140 Adds @nullable & @nonnull annotations to generated data model…
Browse files Browse the repository at this point in the history
… getters
  • Loading branch information
Walter Dziemianczyk committed Mar 9, 2024
1 parent 9d3744c commit e2f4f00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
6.1.0 (202X-XX-XX)
---------------------------------------------
- [#527](https://github.com/dropbox/dropbox-sdk-java/pull/527) Adds nullability annotations to data models for improved interop with Kotlin

6.0.0 (2023-11-30)
---------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sourceSets.main.java.srcDir(versionWriterTask)

dependencies {
api(dropboxJavaSdkLibs.jackson.core)
api(dropboxJavaSdkLibs.jsr305)

compileOnly dropboxJavaSdkLibs.appengine.api
compileOnly dropboxJavaSdkLibs.jakarta.servlet.api
Expand Down
6 changes: 6 additions & 0 deletions core/generator/java/java.stoneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3433,6 +3433,12 @@ def generate_data_type_struct(self, data_type):
returns += ' Defaults to %s.' % w.java_default_value(field)

w.javadoc(field.doc or '', stone_elem=field, returns=returns)

if not field.has_default and field in data_type.all_optional_fields:
w.out('@javax.annotation.Nullable')
elif not j.is_java_primitive(field.data_type):
w.out('@javax.annotation.Nonnull')

with w.block('public %s %s()', j.java_class(field), j.field_getter_method(field)):
w.out('return %s;' % j.param_name(field))

Expand Down
1 change: 1 addition & 0 deletions gradle/dropboxJavaSdkLibs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jackson-databind = 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
jetty-server = "org.eclipse.jetty:jetty-server:11.0.15"
json = "org.json:json:20230618"
jakarta-servlet-api = 'jakarta.servlet:jakarta.servlet-api:5.0.0'
jsr305 = 'com.google.code.findbugs:jsr305:3.0.2'
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
Expand Down

0 comments on commit e2f4f00

Please sign in to comment.