public byte[] buildClass( ClassDefinition classDef ) {
init( classDef );
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
try {
String cName = BuildUtils.getInternalType(classDef.getClassName());
String genericTypes = BuildUtils.getGenericTypes( classDef.getInterfaces() );
String superType = Type.getInternalName( Object.class );
String[] intfaces = null;
if ( Object.class.getName().equals( classDef.getSuperClass() ) ) {
String[] tmp = BuildUtils.getInternalTypes( classDef.getInterfaces() );
intfaces = new String[ tmp.length + 2 ];
System.arraycopy( tmp, 0, intfaces, 0, tmp.length );
intfaces[ tmp.length ] = Type.getInternalName( Serializable.class );
intfaces[ tmp.length + 1 ] = Type.getInternalName( GeneratedFact.class );
} else {
String[] tmp = BuildUtils.getInternalTypes( classDef.getInterfaces() );
intfaces = new String[ tmp.length + 3 ];
System.arraycopy( tmp, 0, intfaces, 0, tmp.length );
intfaces[ tmp.length ] = BuildUtils.getInternalType( classDef.getSuperClass() );
intfaces[ tmp.length + 1 ] = Type.getInternalName( Serializable.class );
intfaces[ tmp.length + 2 ] = Type.getInternalName( GeneratedFact.class );
}
cw.visit( V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
cName,
genericTypes,
superType,
intfaces );
{
if ( classDef.getDefinedClass() == null || classDef.getDefinedClass().getAnnotation( Trait.class ) == null ) {
AnnotationVisitor av0 = cw.visitAnnotation( Type.getDescriptor( Trait.class ), true);
av0.visitEnd();
}
}
for ( FieldDefinition field : classDef.getFieldsDefinitions() ) {
buildField( cw, field );
}
finalizeCreation( classDef );
cw.visitEnd();
} catch ( Exception e ) {
e.printStackTrace();
}
return cw.toByteArray();
}