This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 23a9cc0ed AVRO-3788: escape 'code extracts' in Javadoc
23a9cc0ed is described below
commit 23a9cc0ed9f1ebf169ac0897d2456e8f769e0f54
Author: Christophe Le Saec <[email protected]>
AuthorDate: Tue Jul 11 16:49:13 2023 +0200
AVRO-3788: escape 'code extracts' in Javadoc
---
.../avro/compiler/specific/SpecificCompiler.java | 2 +-
.../specific/templates/java/classic/record.vm | 12 ++--
.../input/optionalgettersnullablefieldstest.avsc | 3 +-
.../output/OptionalGettersNullableFieldsTest.java | 80 +++++++++++++++++++++-
4 files changed, 86 insertions(+), 11 deletions(-)
diff --git
a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 56b854c55..1f248ed6d 100644
---
a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++
b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -1061,7 +1061,7 @@ public class SpecificCompiler {
* Utility for template use. Escapes comment end with HTML entities.
*/
public static String escapeForJavadoc(String s) {
- return s.replace("*/", "*/");
+ return s.replace("*/", "*/").replace("<", "<").replace(">", ">");
}
/**
diff --git
a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
index c98c02eb9..5e7f2550b 100755
---
a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
+++
b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
@@ -228,10 +228,10 @@ public class
${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS
#foreach ($field in $schema.getFields())
#if (${this.gettersReturnOptional} &&
(!${this.optionalGettersForNullableFieldsOnly} ||
${field.schema().isNullable()}))
/**
- * Gets the value of the '${this.mangle($field.name(), $schema.isError())}'
field as an Optional<${this.javaType($field.schema())}>.
+ * Gets the value of the '${this.mangle($field.name(), $schema.isError())}'
field as an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
#if ($field.doc()) * $field.doc()
#end
- * @return The value wrapped in an
Optional<${this.javaType($field.schema())}>.
+ * @return The value wrapped in an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
*/
public Optional<${this.javaType($field.schema())}>
${this.generateGetMethod($schema, $field)}() {
return
Optional.<${this.javaType($field.schema())}>ofNullable(${this.mangle($field.name(),
$schema.isError())});
@@ -250,10 +250,10 @@ public class
${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS
#if (${this.createOptionalGetters})
/**
- * Gets the value of the '${this.mangle($field.name(), $schema.isError())}'
field as an Optional<${this.javaType($field.schema())}>.
+ * Gets the value of the '${this.mangle($field.name(), $schema.isError())}'
field as an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
#if ($field.doc()) * $field.doc()
#end
- * @return The value wrapped in an
Optional<${this.javaType($field.schema())}>.
+ * @return The value wrapped in an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
*/
public Optional<${this.javaType($field.schema())}>
${this.generateGetOptionalMethod($schema, $field)}() {
return
Optional.<${this.javaType($field.schema())}>ofNullable(${this.mangle($field.name(),
$schema.isError())});
@@ -406,10 +406,10 @@ public class
${this.mangleTypeIdentifier($schema.getName())} extends ${this.getS
#if (${this.createOptionalGetters})
/**
- * Gets the value of the '${this.mangle($field.name(),
$schema.isError())}' field as an
Optional<${this.javaType($field.schema())}>.
+ * Gets the value of the '${this.mangle($field.name(),
$schema.isError())}' field as an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
#if ($field.doc()) * $field.doc()
#end
- * @return The value wrapped in an
Optional<${this.javaType($field.schema())}>.
+ * @return The value wrapped in an
Optional<${this.escapeForJavadoc(${this.javaType($field.schema())})}>.
*/
public Optional<${this.javaType($field.schema())}>
${this.generateGetOptionalMethod($schema, $field)}() {
return
Optional.<${this.javaType($field.schema())}>ofNullable(${this.mangle($field.name(),
$schema.isError())});
diff --git
a/lang/java/tools/src/test/compiler/input/optionalgettersnullablefieldstest.avsc
b/lang/java/tools/src/test/compiler/input/optionalgettersnullablefieldstest.avsc
index 80ab1c67f..65e21fe80 100644
---
a/lang/java/tools/src/test/compiler/input/optionalgettersnullablefieldstest.avsc
+++
b/lang/java/tools/src/test/compiler/input/optionalgettersnullablefieldstest.avsc
@@ -3,6 +3,7 @@
{"name": "name", "type": "string"},
{"name": "nullable_name", "type": ["string", "null"]},
{"name": "favorite_number", "type": ["int"]},
- {"name": "nullable_favorite_number", "type": ["int", "null"]}
+ {"name": "nullable_favorite_number", "type": ["int", "null"]},
+ {"name": "nullable_array", "type": [{ "type": "array", "items": "string"
}, "null"]}
]
}
diff --git
a/lang/java/tools/src/test/compiler/output/OptionalGettersNullableFieldsTest.java
b/lang/java/tools/src/test/compiler/output/OptionalGettersNullableFieldsTest.java
index a09d1080c..9bf446abc 100644
---
a/lang/java/tools/src/test/compiler/output/OptionalGettersNullableFieldsTest.java
+++
b/lang/java/tools/src/test/compiler/output/OptionalGettersNullableFieldsTest.java
@@ -15,8 +15,10 @@ import java.util.Optional;
/** Test that optional getters are created only for nullable fields */
@org.apache.avro.specific.AvroGenerated
public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.SpecificRecordBase implements
org.apache.avro.specific.SpecificRecord {
- private static final long serialVersionUID = 7830366875847294825L;
- public static final org.apache.avro.Schema SCHEMA$ = new
org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OptionalGettersNullableFieldsTest\",\"namespace\":\"avro.examples.baseball\",\"doc\":\"Test
that optional getters are created only for nullable
fields\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"nullable_name\",\"type\":[\"string\",\"null\"]},{\"name\":\"favorite_number\",\"type\":[\"int\"]},{\"name\":\"nullable_favorite_number\",\"type\"
[...]
+ private static final long serialVersionUID = -6919829133416680993L;
+
+
+ public static final org.apache.avro.Schema SCHEMA$ = new
org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OptionalGettersNullableFieldsTest\",\"namespace\":\"avro.examples.baseball\",\"doc\":\"Test
that optional getters are created only for nullable
fields\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"nullable_name\",\"type\":[\"string\",\"null\"]},{\"name\":\"favorite_number\",\"type\":[\"int\"]},{\"name\":\"nullable_favorite_number\",\"type\"
[...]
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
private static final SpecificData MODEL$ = new SpecificData();
@@ -76,6 +78,7 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
private java.lang.CharSequence nullable_name;
private java.lang.Object favorite_number;
private java.lang.Integer nullable_favorite_number;
+ private java.util.List<java.lang.CharSequence> nullable_array;
/**
* Default constructor. Note that this does not initialize fields
@@ -90,12 +93,14 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
* @param nullable_name The new value for nullable_name
* @param favorite_number The new value for favorite_number
* @param nullable_favorite_number The new value for nullable_favorite_number
+ * @param nullable_array The new value for nullable_array
*/
- public OptionalGettersNullableFieldsTest(java.lang.CharSequence name,
java.lang.CharSequence nullable_name, java.lang.Object favorite_number,
java.lang.Integer nullable_favorite_number) {
+ public OptionalGettersNullableFieldsTest(java.lang.CharSequence name,
java.lang.CharSequence nullable_name, java.lang.Object favorite_number,
java.lang.Integer nullable_favorite_number,
java.util.List<java.lang.CharSequence> nullable_array) {
this.name = name;
this.nullable_name = nullable_name;
this.favorite_number = favorite_number;
this.nullable_favorite_number = nullable_favorite_number;
+ this.nullable_array = nullable_array;
}
@Override
@@ -112,6 +117,7 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
case 1: return nullable_name;
case 2: return favorite_number;
case 3: return nullable_favorite_number;
+ case 4: return nullable_array;
default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
}
}
@@ -125,6 +131,7 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
case 1: nullable_name = (java.lang.CharSequence)value$; break;
case 2: favorite_number = value$; break;
case 3: nullable_favorite_number = (java.lang.Integer)value$; break;
+ case 4: nullable_array = (java.util.List<java.lang.CharSequence>)value$;
break;
default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
}
}
@@ -197,6 +204,23 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
this.nullable_favorite_number = value;
}
+ /**
+ * Gets the value of the 'nullable_array' field as an
Optional<java.util.List<java.lang.CharSequence>>.
+ * @return The value wrapped in an
Optional<java.util.List<java.lang.CharSequence>>.
+ */
+ public Optional<java.util.List<java.lang.CharSequence>> getNullableArray() {
+ return
Optional.<java.util.List<java.lang.CharSequence>>ofNullable(nullable_array);
+ }
+
+
+ /**
+ * Sets the value of the 'nullable_array' field.
+ * @param value the value to set.
+ */
+ public void setNullableArray(java.util.List<java.lang.CharSequence> value) {
+ this.nullable_array = value;
+ }
+
/**
* Creates a new OptionalGettersNullableFieldsTest RecordBuilder.
* @return A new OptionalGettersNullableFieldsTest RecordBuilder
@@ -242,6 +266,7 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
private java.lang.CharSequence nullable_name;
private java.lang.Object favorite_number;
private java.lang.Integer nullable_favorite_number;
+ private java.util.List<java.lang.CharSequence> nullable_array;
/** Creates a new Builder */
private Builder() {
@@ -270,6 +295,10 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
this.nullable_favorite_number = data().deepCopy(fields()[3].schema(),
other.nullable_favorite_number);
fieldSetFlags()[3] = other.fieldSetFlags()[3];
}
+ if (isValidValue(fields()[4], other.nullable_array)) {
+ this.nullable_array = data().deepCopy(fields()[4].schema(),
other.nullable_array);
+ fieldSetFlags()[4] = other.fieldSetFlags()[4];
+ }
}
/**
@@ -294,6 +323,10 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
this.nullable_favorite_number = data().deepCopy(fields()[3].schema(),
other.nullable_favorite_number);
fieldSetFlags()[3] = true;
}
+ if (isValidValue(fields()[4], other.nullable_array)) {
+ this.nullable_array = data().deepCopy(fields()[4].schema(),
other.nullable_array);
+ fieldSetFlags()[4] = true;
+ }
}
/**
@@ -456,6 +489,46 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
return this;
}
+ /**
+ * Gets the value of the 'nullable_array' field.
+ * @return The value.
+ */
+ public java.util.List<java.lang.CharSequence> getNullableArray() {
+ return nullable_array;
+ }
+
+
+ /**
+ * Sets the value of the 'nullable_array' field.
+ * @param value The value of 'nullable_array'.
+ * @return This builder.
+ */
+ public avro.examples.baseball.OptionalGettersNullableFieldsTest.Builder
setNullableArray(java.util.List<java.lang.CharSequence> value) {
+ validate(fields()[4], value);
+ this.nullable_array = value;
+ fieldSetFlags()[4] = true;
+ return this;
+ }
+
+ /**
+ * Checks whether the 'nullable_array' field has been set.
+ * @return True if the 'nullable_array' field has been set, false
otherwise.
+ */
+ public boolean hasNullableArray() {
+ return fieldSetFlags()[4];
+ }
+
+
+ /**
+ * Clears the value of the 'nullable_array' field.
+ * @return This builder.
+ */
+ public avro.examples.baseball.OptionalGettersNullableFieldsTest.Builder
clearNullableArray() {
+ nullable_array = null;
+ fieldSetFlags()[4] = false;
+ return this;
+ }
+
@Override
@SuppressWarnings("unchecked")
public OptionalGettersNullableFieldsTest build() {
@@ -465,6 +538,7 @@ public class OptionalGettersNullableFieldsTest extends
org.apache.avro.specific.
record.nullable_name = fieldSetFlags()[1] ? this.nullable_name :
(java.lang.CharSequence) defaultValue(fields()[1]);
record.favorite_number = fieldSetFlags()[2] ? this.favorite_number :
defaultValue(fields()[2]);
record.nullable_favorite_number = fieldSetFlags()[3] ?
this.nullable_favorite_number : (java.lang.Integer) defaultValue(fields()[3]);
+ record.nullable_array = fieldSetFlags()[4] ? this.nullable_array :
(java.util.List<java.lang.CharSequence>) defaultValue(fields()[4]);
return record;
} catch (org.apache.avro.AvroMissingFieldException e) {
throw e;