public class SpecificCompiler extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SpecificCompiler.FieldVisibility |
Modifier and Type | Field and Description |
---|---|
protected static int |
MAX_FIELD_PARAMETER_UNIT_COUNT |
Constructor and Description |
---|
SpecificCompiler(Protocol protocol) |
SpecificCompiler(Schema schema) |
Modifier and Type | Method and Description |
---|---|
void |
addCustomConversion(Class<?> conversionClass) |
protected int |
calcAllArgConstructorParameterUnits(Schema record)
Returns the number of parameter units required by fields for the
AllArgsConstructor.
|
static void |
compileProtocol(File[] srcFiles,
File dest)
Generates Java interface and classes for a number of protocol files.
|
static void |
compileProtocol(File src,
File dest)
Generates Java interface and classes for a protocol.
|
static void |
compileSchema(File[] srcFiles,
File dest)
Generates Java classes for a number of schema files.
|
static void |
compileSchema(File src,
File dest)
Generates Java classes for a schema.
|
void |
compileToDestination(File src,
File dst)
Generate output under dst, unless existing file is newer than src.
|
String |
conversionInstance(Schema schema) |
boolean |
deprecatedFields() |
static String |
escapeForJavadoc(String s)
Utility for template use.
|
static long |
fingerprint64(Schema schema)
Utility for use by templates.
|
static String |
generateClearMethod(Schema schema,
Schema.Field field)
Generates the name of a field "clear" method.
|
static String |
generateGetBuilderMethod(Schema schema,
Schema.Field field)
Generates the name of a field Builder accessor method.
|
static String |
generateGetMethod(Schema schema,
Schema.Field field)
Generates the name of a field accessor method.
|
static String |
generateGetOptionalMethod(Schema schema,
Schema.Field field)
Generates the name of a field accessor method that returns a Java 8 Optional.
|
static String |
generateHasBuilderMethod(Schema schema,
Schema.Field field)
Generates the name of a field Builder "has" method.
|
static String |
generateHasMethod(Schema schema,
Schema.Field field)
Generates the name of a field "has" method.
|
static String |
generateSetBuilderMethod(Schema schema,
Schema.Field field)
Generates the name of a field Builder mutator method.
|
static String |
generateSetMethod(Schema schema,
Schema.Field field)
Generates the name of a field mutator method.
|
String |
generateSetterCode(Schema schema,
String name,
String pname)
Utility for template use.
|
int |
getNonNullIndex(Schema s)
Utility for template use.
|
String |
getStringType(Schema s)
Utility for template use (and also internal use).
|
Collection<String> |
getUsedConversionClasses(Schema schema) |
static boolean |
hasBuilder(Schema schema)
Utility for use by templates.
|
boolean |
hasLogicalTypeField(Schema schema) |
String |
indent(int n)
Utility for template use.
|
boolean |
isCreateAllArgsConstructor() |
boolean |
isCreateOptionalGetters() |
boolean |
isCreateSetters() |
boolean |
isCustomCodable(Schema schema)
Utility for template use.
|
boolean |
isGettersReturnOptional() |
boolean |
isOptionalGettersForNullableFieldsOnly() |
boolean |
isStringable(Schema schema)
Utility for template use.
|
static boolean |
isUnboxedJavaTypeNullable(Schema schema)
Tests whether an unboxed Java type can be set to null
|
String[] |
javaAnnotations(JsonProperties props)
Utility for template use.
|
static String |
javaEscape(String o)
Utility for template use.
|
String |
javaSplit(String s)
Utility for template use.
|
String |
javaType(Schema schema)
Utility for template use.
|
String |
javaUnbox(Schema schema)
Deprecated.
use javaUnbox(Schema, boolean), kept for backward compatibiliby
of custom templates
|
String |
javaUnbox(Schema schema,
boolean unboxNullToVoid)
Utility for template use.
|
static void |
main(String[] args) |
static String |
mangle(String word)
Utility for template use.
|
static String |
mangle(String word,
boolean isError)
Utility for template use.
|
static String |
mangle(String word,
Set<String> reservedWords)
Utility for template use.
|
static String |
mangle(String word,
Set<String> reservedWords,
boolean isMethod)
Utility for template use.
|
static String |
nullToEmpty(String x)
Utility for template use.
|
boolean |
privateFields() |
boolean |
publicFields() |
void |
setAdditionalVelocityTools(List<Object> additionalVelocityTools)
Set additional Velocity tools (simple POJOs) to be injected into the Velocity
template context.
|
void |
setCreateOptionalGetters(boolean createOptionalGetters)
Set to false to not create the getters that return an Optional.
|
void |
setCreateSetters(boolean createSetters)
Set to false to not create setter methods for the fields of the record.
|
void |
setEnableDecimalLogicalType(boolean enableDecimalLogicalType)
Set to true to use
BigDecimal instead of
ByteBuffer for logical type "decimal" |
void |
setFieldVisibility(SpecificCompiler.FieldVisibility fieldVisibility)
Sets the field visibility option.
|
void |
setGettersReturnOptional(boolean gettersReturnOptional)
Set to false to not create the getters that return an Optional.
|
void |
setOptionalGettersForNullableFieldsOnly(boolean optionalGettersForNullableFieldsOnly)
Set to true to create the Optional getters only for nullable fields.
|
void |
setOutputCharacterEncoding(String outputCharacterEncoding)
Sets character encoding for generated java file
|
void |
setStringType(GenericData.StringType t)
Set the Java type to be emitted for string schemas.
|
void |
setSuffix(String suffix)
Set the resource file suffix, .java or .xxx
|
void |
setTemplateDir(String templateDir)
Set the resource directory where templates reside.
|
protected void |
validateRecordForCompilation(Schema record) |
protected static final int MAX_FIELD_PARAMETER_UNIT_COUNT
public SpecificCompiler(Protocol protocol)
public SpecificCompiler(Schema schema)
public boolean isCreateAllArgsConstructor()
public void setAdditionalVelocityTools(List<Object> additionalVelocityTools)
public void setTemplateDir(String templateDir)
public void setSuffix(String suffix)
public boolean deprecatedFields()
public boolean publicFields()
public boolean privateFields()
public void setFieldVisibility(SpecificCompiler.FieldVisibility fieldVisibility)
public boolean isCreateSetters()
public void setCreateSetters(boolean createSetters)
public boolean isCreateOptionalGetters()
public void setCreateOptionalGetters(boolean createOptionalGetters)
public boolean isGettersReturnOptional()
public void setGettersReturnOptional(boolean gettersReturnOptional)
public boolean isOptionalGettersForNullableFieldsOnly()
public void setOptionalGettersForNullableFieldsOnly(boolean optionalGettersForNullableFieldsOnly)
public void setEnableDecimalLogicalType(boolean enableDecimalLogicalType)
BigDecimal
instead of
ByteBuffer
for logical type "decimal"public void addCustomConversion(Class<?> conversionClass)
public Collection<String> getUsedConversionClasses(Schema schema)
public static void compileProtocol(File src, File dest) throws IOException
src
- the source Avro protocol filedest
- the directory to place generated files inIOException
public static void compileProtocol(File[] srcFiles, File dest) throws IOException
srcFiles
- the source Avro protocol filesdest
- the directory to place generated files inIOException
public static void compileSchema(File src, File dest) throws IOException
IOException
public static void compileSchema(File[] srcFiles, File dest) throws IOException
IOException
public void compileToDestination(File src, File dst) throws IOException
IOException
protected int calcAllArgConstructorParameterUnits(Schema record)
record
- a Record schemaprotected void validateRecordForCompilation(Schema record)
public void setStringType(GenericData.StringType t)
public String getStringType(Schema s)
public boolean isStringable(Schema schema)
public String javaType(Schema schema)
public String generateSetterCode(Schema schema, String name, String pname)
@Deprecated public String javaUnbox(Schema schema)
public String javaUnbox(Schema schema, boolean unboxNullToVoid)
public String indent(int n)
public int getNonNullIndex(Schema s)
public boolean isCustomCodable(Schema schema)
public boolean hasLogicalTypeField(Schema schema)
public String[] javaAnnotations(JsonProperties props)
public String javaSplit(String s) throws IOException
s
- The string to splitIOException
public static String javaEscape(String o)
public static String escapeForJavadoc(String s)
public static String nullToEmpty(String x)
public static String mangle(String word)
public static String mangle(String word, boolean isError)
public static String mangle(String word, Set<String> reservedWords)
public static String mangle(String word, Set<String> reservedWords, boolean isMethod)
public static long fingerprint64(Schema schema)
public static String generateGetMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the accessor name.public static String generateGetOptionalMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the accessor name.public static String generateSetMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the mutator name.public static String generateHasMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the "has" method name.public static String generateClearMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the accessor name.public static boolean hasBuilder(Schema schema)
public static String generateGetBuilderMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the Builder accessor name.public static String generateSetBuilderMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the Builder mutator name.public static String generateHasBuilderMethod(Schema schema, Schema.Field field)
schema
- the schema in which the field is defined.field
- the field for which to generate the "has" Builder method name.public static boolean isUnboxedJavaTypeNullable(Schema schema)
public void setOutputCharacterEncoding(String outputCharacterEncoding)
outputCharacterEncoding
- Character encoding for output files (defaults
to system encoding)Copyright © 2009–2020 The Apache Software Foundation. All rights reserved.