protected class ASTNodeConverter.EnumToTypeConverter extends ASTNodeConverter.Converter
convert()
Modifier and Type | Field and Description |
---|---|
protected AST |
ast
AST of the source and converted node
|
protected ASTJEnum |
astjEnum
Enum to convert to type
|
protected java.util.List<JNode> |
enumChildren
List of children of the enum
|
protected java.util.Map<ASTJField,java.lang.Integer> |
fieldIndexesMap
Map of fields to their index in the children list
|
protected java.util.Map<java.lang.String,ASTJField> |
fieldInitializersMap
Map of initializer values of the fields to fields
|
protected ASTJNode<?> |
lastFinalFieldUsed
Last field used in the initializer string of the fields converted from enum constants.
|
Constructor and Description |
---|
ASTNodeConverter.EnumToTypeConverter(ASTJEnum astjEnum) |
Modifier and Type | Method and Description |
---|---|
ASTJType |
convert()
Converts enum to the class declaration.
|
protected ASTJNode<?> |
convertEnumConstToField(ASTJEnumConstant enumConstant)
Converts enum constant to field.
|
protected void |
setFieldInitializer(ASTJField field,
ASTJEnumConstant enumConstant)
Sets field initializer based on arguments and body of enum constant.
|
moveChildren, replaceNode
protected ASTJEnum astjEnum
protected AST ast
protected java.util.List<JNode> enumChildren
protected java.util.Map<java.lang.String,ASTJField> fieldInitializersMap
protected java.util.Map<ASTJField,java.lang.Integer> fieldIndexesMap
protected ASTJNode<?> lastFinalFieldUsed
public ASTNodeConverter.EnumToTypeConverter(ASTJEnum astjEnum)
astjEnum
- to convertpublic ASTJType convert()
Name, flags, comment, super interfaces of the class declaration are set from the enum.
All children of the enum are added to the class declaration. Enum constants are converted to public static final fields with initializer value created from arguments and body of enum constant.
convert
in class ASTNodeConverter.Converter
null
if conversion not possiblesetFieldInitializer(ASTJField, ASTJEnumConstant)
protected ASTJNode<?> convertEnumConstToField(ASTJEnumConstant enumConstant)
Resulting field is public static final
. The type of the field is the name of the
enum. Comment of the field is copied from the enum constant.
Initializer value is a call to the constructor of the enum (or converted type) with arguments
taken from enum constant.
enumConstant
- to convertsetFieldInitializer(ASTJField, ASTJEnumConstant)
protected void setFieldInitializer(ASTJField field, ASTJEnumConstant enumConstant)
Initializer string is in the form
new Type ( ArgumentsList ) AnonymousClassDeclaration
where
Type
is the the type of the class
ArgumentsList
is the arguments of the enum constant with some arguments replaced by the names of static final fields.
Arguments that match the initializer value of any public static final field are replaced by the name of that field.
AnonymousClassDeclaration is the body of enum constant
field
- enumConstant
-