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 6, 2024
1 parent 9d3744c commit a8762f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sourceSets.main.java.srcDir(versionWriterTask)
dependencies {
api(dropboxJavaSdkLibs.jackson.core)

compileOnly dropboxJavaSdkLibs.jsr305
compileOnly dropboxJavaSdkLibs.appengine.api
compileOnly dropboxJavaSdkLibs.jakarta.servlet.api
compileOnly dropboxJavaSdkLibs.kotlin.stdlib
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 a8762f3

Please sign in to comment.