forked from apache/avro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AVRO-3641: Adds support for nullSafeAnnotations to java SpecificCompi…
…ler (apache#2142) * AVRO-3641: Adds support for nullSafeAnnotations to java SpecificCompiler * AVRO-3641: Removes maven dependency to org.jetbrains:annotations since it is only used in the produced jar * AVRO-3641: Removes the unused property for jetbrains-annotations version * AVRO-3641: Removes empty lines from expected output file * Revert "AVRO-3641: Removes empty lines from expected output file" This reverts commit f99cf16. * AVRO-3641: Use full class name for null safe annotations instead of imports * AVRO-3641: Adds avro-maven-plugin config parameter for createNullSafeAnnotations * AVRO-3641: Clarifies the source of the nullability annotations * AVRO-3641: Minor javadoc formatting. * AVRO-3641: Fixes spotless formatting * AVRO-3641: Adds license exclude for NullSafeAnnotationsFieldsTest.java --------- Co-authored-by: pknu <[email protected]>
- Loading branch information
1 parent
2a1f3af
commit b255b43
Showing
8 changed files
with
663 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS | |
#end | ||
#end | ||
*/ | ||
public ${this.mangleTypeIdentifier($schema.getName())}(#foreach($field in $schema.getFields())${this.javaType($field.schema())} ${this.mangle($field.name())}#if($foreach.count < $schema.getFields().size()), #end#end) { | ||
public ${this.mangleTypeIdentifier($schema.getName())}(#foreach($field in $schema.getFields())#if(${this.createNullSafeAnnotations})#if(${field.schema().isNullable()})@org.jetbrains.annotations.Nullable#[email protected]#end #end${this.javaType($field.schema())} ${this.mangle($field.name())}#if($foreach.count < $schema.getFields().size()), #end#end) { | ||
#foreach ($field in $schema.getFields()) | ||
${this.generateSetterCode($field.schema(), ${this.mangle($field.name())}, ${this.mangle($field.name())})} | ||
#end | ||
|
@@ -243,6 +243,13 @@ public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS | |
#else * @return The value of the '${this.mangle($field.name(), $schema.isError())}' field. | ||
#end | ||
*/ | ||
#if(${this.createNullSafeAnnotations}) | ||
#if (${field.schema().isNullable()}) | ||
@org.jetbrains.annotations.Nullable | ||
#else | ||
@org.jetbrains.annotations.NotNull | ||
#end | ||
#end | ||
public ${this.javaUnbox($field.schema(), false)} ${this.generateGetMethod($schema, $field)}() { | ||
return ${this.mangle($field.name(), $schema.isError())}; | ||
} | ||
|
@@ -267,7 +274,7 @@ public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS | |
#end | ||
* @param value the value to set. | ||
*/ | ||
public void ${this.generateSetMethod($schema, $field)}(${this.javaUnbox($field.schema(), false)} value) { | ||
public void ${this.generateSetMethod($schema, $field)}(#if(${this.createNullSafeAnnotations})#if(${field.schema().isNullable()})@org.jetbrains.annotations.Nullable#[email protected]#end #end${this.javaUnbox($field.schema(), false)} value) { | ||
${this.generateSetterCode($field.schema(), ${this.mangle($field.name(), $schema.isError())}, "value")} | ||
} | ||
#end | ||
|
@@ -423,7 +430,7 @@ public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS | |
* @param value The value of '${this.mangle($field.name(), $schema.isError())}'. | ||
* @return This builder. | ||
*/ | ||
public #if ($schema.getNamespace())$this.mangle($schema.getNamespace()).#end${this.mangleTypeIdentifier($schema.getName())}.Builder ${this.generateSetMethod($schema, $field)}(${this.javaUnbox($field.schema(), false)} value) { | ||
public #if ($schema.getNamespace())$this.mangle($schema.getNamespace()).#end${this.mangleTypeIdentifier($schema.getName())}.Builder ${this.generateSetMethod($schema, $field)}(#if(${this.createNullSafeAnnotations})#if(${field.schema().isNullable()})@org.jetbrains.annotations.Nullable#[email protected]#end #end${this.javaUnbox($field.schema(), false)} value) { | ||
validate(fields()[$field.pos()], value); | ||
#if (${this.hasBuilder($field.schema())}) | ||
this.${this.mangle($field.name(), $schema.isError())}Builder = null; | ||
|
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
8 changes: 8 additions & 0 deletions
8
lang/java/tools/src/test/compiler/input/nullsafeannotationsfieldstest.avsc
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,8 @@ | ||
{"type":"record", "name":"NullSafeAnnotationsFieldsTest", "namespace": "avro.examples.baseball", "doc":"Test that @org.jetbrains.annotations.Nullable and @org.jetbrains.annotations.NotNull annotations are created for all fields", | ||
"fields": [ | ||
{"name": "name", "type": "string"}, | ||
{"name": "nullable_name", "type": ["string", "null"]}, | ||
{"name": "favorite_number", "type": "int"}, | ||
{"name": "nullable_favorite_number", "type": ["int", "null"]} | ||
] | ||
} |
Oops, something went wrong.