## org.eclipse.emf.codegen.merge.java.facade.ast
Class ASTNodeConverter.EnumToTypeConverter

    java.lang.Object
      org.eclipse.emf.codegen.merge.java.facade.ast.ASTNodeConverter.Converter
          org.eclipse.emf.codegen.merge.java.facade.ast.ASTNodeConverter.EnumToTypeConverter

Enclosing class:
  ASTNodeConverter

    protected class ASTNodeConverter.EnumToTypeConverter

extends ASTNodeConverter.Converter

Converter of enum to class.

See Also:
  `convert()`

Field Summary
`protected org.eclipse.jdt.core.dom.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 Summary
`ASTNodeConverter.EnumToTypeConverter(ASTJEnum astjEnum)`

Method Summary
`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.

Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTNodeConverter.Converter
`moveChildren, replaceNode`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### astjEnum

    protected ASTJEnum astjEnum

  Enum to convert to type

### ast

    protected org.eclipse.jdt.core.dom.AST ast

  AST of the source and converted node

### enumChildren

    protected java.util.List<JNode> enumChildren

  List of children of the enum

### fieldInitializersMap

    protected java.util.Map<java.lang.String,ASTJField> fieldInitializersMap

  Map of initializer values of the fields to fields

### fieldIndexesMap

    protected java.util.Map<ASTJField,java.lang.Integer> fieldIndexesMap

  Map of fields to their index in the children list

### lastFinalFieldUsed

    protected ASTJNode<?> lastFinalFieldUsed

  Last field used in the initializer string of the fields converted from enum constants.

Constructor Detail

### ASTNodeConverter.EnumToTypeConverter

    public ASTNodeConverter.EnumToTypeConverter(ASTJEnum astjEnum)

Parameters:
  `astjEnum` - to convert

Method Detail

### convert

    public ASTJType convert()

  Converts enum to the class declaration.

  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.

  Specified by:
    `convert` in class `ASTNodeConverter.Converter`
  Returns:
    converted type, or `null` if conversion not possible
  See Also:
    `setFieldInitializer(ASTJField, ASTJEnumConstant)`

### convertEnumConstToField

    protected ASTJNode<?> convertEnumConstToField(ASTJEnumConstant enumConstant)

  Converts enum constant to field.

  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.

  Parameters:
    `enumConstant` - to convert
  Returns:
    converted field
  See Also:
    `setFieldInitializer(ASTJField, ASTJEnumConstant)`

### setFieldInitializer

    protected void setFieldInitializer(ASTJField field,
                                       ASTJEnumConstant enumConstant)

  Sets field initializer based on arguments and body of enum constant.

  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`

  Parameters:
    `field` -
    `enumConstant` -

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