IllegalAccessException,
InvocationTargetException,
InstantiationException,
NoSuchFieldException {
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS );
this.buildClassHeader( cw,
classDef );
// Building fields
for ( FieldDefinition fieldDef : classDef.getFieldsDefinitions() ) {
this.buildField( cw,
fieldDef );
}
// Building default constructor
this.buildDefaultConstructor( cw,
classDef );
// Building constructor with all fields
this.buildConstructorWithFields( cw,
classDef,
classDef.getFieldsDefinitions() );
// Building constructor with key fields only
List<FieldDefinition> keys = new LinkedList<FieldDefinition>();
for ( FieldDefinition fieldDef : classDef.getFieldsDefinitions() ) {
if ( fieldDef.isKey() ) {
keys.add( fieldDef );
}
}
if ( !keys.isEmpty() && keys.size() != classDef.getFieldsDefinitions().size() ) {
this.buildConstructorWithFields( cw,
classDef,
keys );
}
// Building methods
for ( FieldDefinition fieldDef : classDef.getFieldsDefinitions() ) {
this.buildGetMethod( cw,
classDef,
fieldDef );
this.buildSetMethod( cw,
classDef,
fieldDef );
}
this.buildEquals( cw,
classDef );
this.buildHashCode( cw,
classDef );
this.buildToString( cw,
classDef );
cw.visitEnd();
return cw.toByteArray();
}