Class ASTNodeConverter.TypeToEnumConverter

  extended by
      extended by
Enclosing class:

protected class ASTNodeConverter.TypeToEnumConverter
extends ASTNodeConverter.Converter

Converter of type to enum.

See Also:

Field Summary
protected  org.eclipse.jdt.core.dom.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 Summary
ASTNodeConverter.TypeToEnumConverter(ASTJType type)
Method Summary
 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.
Methods inherited from class
moveChildren, replaceNode
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected ASTJType type
Type that will be converted


protected org.eclipse.jdt.core.dom.AST ast
AST of the source and converted node


protected java.util.List<JNode> typeChildren
List of children of the type


protected java.util.Map<java.lang.String,ASTJField> fieldNamesMap
Map of field names to fields

Constructor Detail


public ASTNodeConverter.TypeToEnumConverter(ASTJType type)
type - to convert to enum
Method Detail


public ASTJEnum convert()
Converts type to the enum.

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.

Specified by:
convert in class ASTNodeConverter.Converter
converted type, or null if conversion not possible


protected ASTJNode<?> convertFieldToEnumConst(ASTJField field)
Converts given field to enum constant if possible.

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 convert
original field if conversion not possible, or converted field otherwise
See Also:
setEnumConstantArgumentsAndBody(ASTJEnumConstant, ASTJField)


protected void setEnumConstantArgumentsAndBody(ASTJEnumConstant enumConstant,
                                               ASTJField field)
Sets arguments and body of the enum constant from the initializer of the given 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 -

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.