From a8762f3252793b969e7563f289f503af5fe6d266 Mon Sep 17 00:00:00 2001 From: Walter Dziemianczyk Date: Wed, 6 Mar 2024 08:11:15 -0500 Subject: [PATCH] MF-5140 Adds @Nullable & @Nonnull annotations to generated data model getters --- core/build.gradle | 1 + core/generator/java/java.stoneg.py | 6 ++++++ gradle/dropboxJavaSdkLibs.versions.toml | 1 + 3 files changed, 8 insertions(+) diff --git a/core/build.gradle b/core/build.gradle index 0ec477091..61b2fb263 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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 diff --git a/core/generator/java/java.stoneg.py b/core/generator/java/java.stoneg.py index bd575d255..6fecd6e66 100644 --- a/core/generator/java/java.stoneg.py +++ b/core/generator/java/java.stoneg.py @@ -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)) diff --git a/gradle/dropboxJavaSdkLibs.versions.toml b/gradle/dropboxJavaSdkLibs.versions.toml index da08792f2..f5e8adfda 100644 --- a/gradle/dropboxJavaSdkLibs.versions.toml +++ b/gradle/dropboxJavaSdkLibs.versions.toml @@ -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" }