Class SpecificCompiler
java.lang.Object
org.apache.avro.compiler.specific.SpecificCompiler
Generate specific Java interfaces and classes for protocols and schemas.
Java reserved keywords are mangled to preserve compilation.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpecificCompiler(Iterable<Schema> schemas) SpecificCompiler(Collection<Schema> schemas) SpecificCompiler(Protocol protocol) SpecificCompiler(Schema schema) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCustomConversion(Class<?> conversionClass) protected intReturns the number of parameter units required by fields for the AllArgsConstructor.static voidcompileProtocol(File[] srcFiles, File dest) Generates Java interface and classes for a number of protocol files.static voidcompileProtocol(File src, File dest) Generates Java interface and classes for a protocol.static voidcompileSchema(File[] srcFiles, File dest) Generates Java classes for a number of schema files.static voidcompileSchema(File src, File dest) Generates Java classes for a schema.voidcompileToDestination(File src, File dst) Generate output under dst, unless existing file is newer than src.conversionInstance(Schema schema) static StringUtility for template use.static longfingerprint64(Schema schema) Utility for use by templates.static StringgenerateClearMethod(Schema schema, Schema.Field field) Generates the name of a field "clear" method.static StringgenerateGetBuilderMethod(Schema schema, Schema.Field field) Generates the name of a field Builder accessor method.static StringgenerateGetMethod(Schema schema, Schema.Field field) Generates the name of a field accessor method.static StringgenerateGetOptionalMethod(Schema schema, Schema.Field field) Generates the name of a field accessor method that returns a Java 8 Optional.static StringgenerateHasBuilderMethod(Schema schema, Schema.Field field) Generates the name of a field Builder "has" method.static StringgenerateHasMethod(Schema schema, Schema.Field field) Generates the name of a field "has" method.static StringgenerateSetBuilderMethod(Schema schema, Schema.Field field) Generates the name of a field Builder mutator method.static StringgenerateSetMethod(Schema schema, Schema.Field field) Generates the name of a field mutator method.generateSetterCode(Schema schema, String name, String pname) Utility for template use.intUtility for template use.getSchemaParentClass(boolean isError) Utility for template use (and also internal use).getUsedConversionClasses(Schema schema) static booleanhasBuilder(Schema schema) Utility for use by templates.booleanhasLogicalTypeField(Schema schema) indent(int n) Utility for template use.booleanbooleanbooleanbooleanbooleanisCustomCodable(Schema schema) Utility for template use.booleanbooleanbooleanisStringable(Schema schema) Utility for template use.static booleanisUnboxedJavaTypeNullable(Schema schema) Tests whether an unboxed Java type can be set to nullString[]javaAnnotations(JsonProperties props) Utility for template use.static StringjavaEscape(String o) Utility for template use.Utility for template use.Utility for template use.Deprecated.use javaUnbox(Schema, boolean), kept for backward compatibility of custom templatesUtility for template use.static voidstatic StringUtility for template use.static StringUtility for template use.static StringUtility for template use.static StringUtility for template use.static StringmangleTypeIdentifier(String word) Utility for template use.static StringmangleTypeIdentifier(String word, boolean isError) Utility for template use.static StringUtility for template use.booleanbooleanvoidsetAdditionalVelocityTools(List<Object> additionalVelocityTools) Set additional Velocity tools (simple POJOs) to be injected into the Velocity template context.voidsetCreateNullSafeAnnotations(boolean createNullSafeAnnotations) Set to true to add jetbrains @Nullable and @NotNull annotationsvoidsetCreateOptionalGetters(boolean createOptionalGetters) Set to false to not create the getters that return an Optional.voidsetCreateSetters(boolean createSetters) Set to false to not create setter methods for the fields of the record.voidsetEnableDecimalLogicalType(boolean enableDecimalLogicalType) Set to true to useBigDecimalinstead ofByteBufferfor logical type "decimal"voidsetErrorSpecificClass(String errorSpecificClass) voidsetFieldVisibility(SpecificCompiler.FieldVisibility fieldVisibility) Sets the field visibility option.voidsetGettersReturnOptional(boolean gettersReturnOptional) Set to false to not create the getters that return an Optional.voidsetOptionalGettersForNullableFieldsOnly(boolean optionalGettersForNullableFieldsOnly) Set to true to create the Optional getters only for nullable fields.voidsetOutputCharacterEncoding(String outputCharacterEncoding) Sets character encoding for generated java filevoidsetRecordSpecificClass(String recordSpecificClass) voidSet the Java type to be emitted for string schemas.voidSet the resource file suffix, .java or .xxxvoidsetTemplateDir(String templateDir) Set the resource directory where templates reside.protected voidvalidateRecordForCompilation(Schema record)
-
Field Details
-
MAX_FIELD_PARAMETER_UNIT_COUNT
protected static final int MAX_FIELD_PARAMETER_UNIT_COUNT- See Also:
-
-
Constructor Details
-
SpecificCompiler
-
SpecificCompiler
-
SpecificCompiler
-
SpecificCompiler
-
-
Method Details
-
isCreateAllArgsConstructor
public boolean isCreateAllArgsConstructor() -
setAdditionalVelocityTools
Set additional Velocity tools (simple POJOs) to be injected into the Velocity template context. -
setTemplateDir
Set the resource directory where templates reside. First, the compiler checks the system path for the specified file, if not it is assumed that it is present on the classpath. -
setSuffix
Set the resource file suffix, .java or .xxx -
publicFields
public boolean publicFields()- Returns:
- true if the record fields should be public
-
privateFields
public boolean privateFields()- Returns:
- true if the record fields should be private
-
setFieldVisibility
Sets the field visibility option. -
isCreateSetters
public boolean isCreateSetters() -
setCreateSetters
public void setCreateSetters(boolean createSetters) Set to false to not create setter methods for the fields of the record. -
isCreateNullSafeAnnotations
public boolean isCreateNullSafeAnnotations() -
setCreateNullSafeAnnotations
public void setCreateNullSafeAnnotations(boolean createNullSafeAnnotations) Set to true to add jetbrains @Nullable and @NotNull annotations -
isCreateOptionalGetters
public boolean isCreateOptionalGetters() -
setCreateOptionalGetters
public void setCreateOptionalGetters(boolean createOptionalGetters) Set to false to not create the getters that return an Optional. -
isGettersReturnOptional
public boolean isGettersReturnOptional() -
setGettersReturnOptional
public void setGettersReturnOptional(boolean gettersReturnOptional) Set to false to not create the getters that return an Optional. -
isOptionalGettersForNullableFieldsOnly
public boolean isOptionalGettersForNullableFieldsOnly() -
setOptionalGettersForNullableFieldsOnly
public void setOptionalGettersForNullableFieldsOnly(boolean optionalGettersForNullableFieldsOnly) Set to true to create the Optional getters only for nullable fields. -
setEnableDecimalLogicalType
public void setEnableDecimalLogicalType(boolean enableDecimalLogicalType) Set to true to useBigDecimalinstead ofByteBufferfor logical type "decimal" -
addCustomConversion
-
getUsedConversionClasses
-
getUsedCustomLogicalTypeFactories
-
compileProtocol
Generates Java interface and classes for a protocol.- Parameters:
src- the source Avro protocol filedest- the directory to place generated files in- Throws:
IOException
-
compileProtocol
Generates Java interface and classes for a number of protocol files.- Parameters:
srcFiles- the source Avro protocol filesdest- the directory to place generated files in- Throws:
IOException
-
compileSchema
Generates Java classes for a schema.- Throws:
IOException
-
compileSchema
Generates Java classes for a number of schema files.- Throws:
IOException
-
compileToDestination
Generate output under dst, unless existing file is newer than src.- Throws:
IOException
-
calcAllArgConstructorParameterUnits
Returns the number of parameter units required by fields for the AllArgsConstructor.- Parameters:
record- a Record schema
-
validateRecordForCompilation
-
setStringType
Set the Java type to be emitted for string schemas. -
getStringType
Utility for template use (and also internal use). Returns a string giving the FQN of the Java type to be used for a string schema or for the key of a map schema. (It's an error to call this on a schema other than a string or map.) -
isStringable
Utility for template use. Returns true iff a STRING-schema or the key of a MAP-schema is what SpecificData defines as "stringable" (which means we need to call toString on it before before writing it). -
javaType
Utility for template use. Returns the java type for a Schema. -
generateSetterCode
Utility for template use. -
javaUnbox
Deprecated.use javaUnbox(Schema, boolean), kept for backward compatibility of custom templatesUtility for template use. Returns the unboxed java type for a Schema. -
javaUnbox
Utility for template use. Returns the unboxed java type for a Schema including the void type. -
indent
Utility for template use. Return a string with a given number of spaces to be used for indentation purposes. -
getNonNullIndex
Utility for template use. For a two-branch union type with one null branch, returns the index of the null branch. It's an error to use on anything other than a two-branch union with on null branch. -
isCustomCodable
Utility for template use. Returns true if the encode/decode logic in record.vm can handle the schema being presented. -
hasLogicalTypeField
-
conversionInstance
-
javaAnnotations
Utility for template use. Returns the java annotations for a schema. -
javaSplit
Utility for template use. Takes a (potentially overly long) string and splits it into a quoted, comma-separted sequence of escaped strings.- Parameters:
s- The string to split- Returns:
- A sequence of quoted, comma-separated, escaped strings
- Throws:
IOException
-
javaEscape
Utility for template use. Escapes quotes and backslashes. -
escapeForJavadoc
Utility for template use. Escapes comment end with HTML entities. -
nullToEmpty
Utility for template use. Returns empty string for null. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangleTypeIdentifier
Utility for template use. Adds a dollar sign to reserved words in type identifiers. -
mangleTypeIdentifier
Utility for template use. Adds a dollar sign to reserved words in type identifiers. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
fingerprint64
Utility for use by templates. Return schema fingerprint as a long. -
generateGetMethod
Generates the name of a field accessor method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the accessor name.- Returns:
- the name of the accessor method for the given field.
-
generateGetOptionalMethod
Generates the name of a field accessor method that returns a Java 8 Optional.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the accessor name.- Returns:
- the name of the accessor method for the given field.
-
generateSetMethod
Generates the name of a field mutator method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the mutator name.- Returns:
- the name of the mutator method for the given field.
-
generateHasMethod
Generates the name of a field "has" method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the "has" method name.- Returns:
- the name of the has method for the given field.
-
generateClearMethod
Generates the name of a field "clear" method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the accessor name.- Returns:
- the name of the has method for the given field.
-
hasBuilder
Utility for use by templates. Does this schema have a Builder method? -
generateGetBuilderMethod
Generates the name of a field Builder accessor method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the Builder accessor name.- Returns:
- the name of the Builder accessor method for the given field.
-
generateSetBuilderMethod
Generates the name of a field Builder mutator method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the Builder mutator name.- Returns:
- the name of the Builder mutator method for the given field.
-
generateHasBuilderMethod
Generates the name of a field Builder "has" method.- Parameters:
schema- the schema in which the field is defined.field- the field for which to generate the "has" Builder method name.- Returns:
- the name of the "has" Builder method for the given field.
-
isUnboxedJavaTypeNullable
Tests whether an unboxed Java type can be set to null -
main
- Throws:
Exception
-
setOutputCharacterEncoding
Sets character encoding for generated java file- Parameters:
outputCharacterEncoding- Character encoding for output files (defaults to system encoding)
-
getSchemaParentClass
-
setRecordSpecificClass
-
setErrorSpecificClass
-