protected class ASTNodeConverter.TypeToEnumConverter extends ASTNodeConverter.Converter
convert()
Modifier and Type | Field and Description |
---|---|
protected AST |
ast
AST of the source and converted node
|
protected java.util.Map<java.lang.String,ASTJField> |
fieldNamesMap
Map of field names to fields
|
protected ASTJType |
type
Type that will be converted
|
protected java.util.List<JNode> |
typeChildren
List of children of the type
|
Constructor and Description |
---|
ASTNodeConverter.TypeToEnumConverter(ASTJType type) |
Modifier and Type | Method and Description |
---|---|
ASTJEnum |
convert()
Converts type to the enum.
|
protected ASTJNode<?> |
convertFieldToEnumConst(ASTJField field)
Converts given field to enum constant if possible.
|
protected void |
setEnumConstantArgumentsAndBody(ASTJEnumConstant enumConstant,
ASTJField field)
Sets arguments and body of the enum constant from the initializer of the given field.
|
moveChildren, replaceNode
protected ASTJType type
protected AST ast
protected java.util.List<JNode> typeChildren
protected java.util.Map<java.lang.String,ASTJField> fieldNamesMap
public ASTNodeConverter.TypeToEnumConverter(ASTJType type)
type
- to convert to enumpublic ASTJEnum convert()
Name, flags, comment, super interfaces of the enum are set from the type.
All children of the type is added to the enum.
Fields that are public static final
and have the same type are converted to
enum constants. Arguments of the enum constants are set from arguments of the initializer.
Arguments that match the name of any other field are replaced by initializer value of that field.
Conversion must be done only once for the same type.
convert
in class ASTNodeConverter.Converter
null
if conversion not possibleprotected ASTJNode<?> convertFieldToEnumConst(ASTJField field)
Field must be declared as public static final
field, and field must be of the same type
as its parent (e.g. type).
Enum constant arguments and body is set from the original initializer of the field.
field
- to convertsetEnumConstantArgumentsAndBody(ASTJEnumConstant, ASTJField)
protected void setEnumConstantArgumentsAndBody(ASTJEnumConstant enumConstant, ASTJField field)
Note that the original field's initializer node structure is used (e.g. if ASTJField.setInitializer(String)
has been called, this method will use the original initializer of the field).
enumConstant
- field
-