interfaceList.add( TraitableBean.class.getName() );
}
String[] interfaces = interfaceList.toArray( new String[interfaceList.size()] );
// prepares a class definition
ClassDefinition def;
switch ( type.getKind() ) {
case TRAIT :
def = new ClassDefinition( fullName,
"java.lang.Object",
fullSuperTypes );
break;
case ENUM :
def = new EnumClassDefinition( fullName,
fullSuperTypes[0],
null );
break;
case CLASS :
default :
def = new ClassDefinition( fullName,
fullSuperTypes[0],
interfaces );
def.setTraitable( traitable, traitableAnn != null &&
traitableAnn.getValue( "logical" ) != null &&
Boolean.valueOf( traitableAnn.getValue( "logical" ) ) );
}
for (String annotationName : typeDescr.getAnnotationNames()) {
Class annotation = resolveAnnotation( annotationName,
pkgRegistry.getTypeResolver() );
if (annotation != null) {
try {
AnnotationDefinition annotationDefinition = AnnotationDefinition.build( annotation,
typeDescr.getAnnotations().get( annotationName ).getValueMap(),
pkgRegistry.getTypeResolver() );
def.addAnnotation( annotationDefinition );
} catch (NoSuchMethodException nsme) {
this.results.add( new TypeDeclarationError( typeDescr,
"Annotated type " + fullName +
" - undefined property in @annotation " +
annotationName + ": " +
nsme.getMessage() + ";" ) );
}
} else {
def.addMetaData( annotationName, typeDescr.getAnnotation( annotationName ).getSingleValue() );
}
}
// add enum literals, if appropriate
if ( type.getKind() == TypeDeclaration.Kind.ENUM ) {
for ( EnumLiteralDescr lit : ((EnumDeclarationDescr) typeDescr).getLiterals() ) {
((EnumClassDefinition) def).addLiteral(
new EnumLiteralDefinition( lit.getName(), lit.getConstructorArgs() )
);
}
}
// fields definitions are created. will be used by subclasses, if any.
// Fields are SORTED in the process
if (!typeDescr.getFields().isEmpty()) {
PriorityQueue<FieldDefinition> fieldDefs = sortFields( typeDescr.getFields(),
pkgRegistry );
int n = fieldDefs.size();
for ( int k = 0; k < n; k++ ) {
FieldDefinition fld = fieldDefs.poll();
if (unresolvedTypeDefinitions != null) {
for (TypeDefinition typeDef : unresolvedTypeDefinitions) {
if (fld.getTypeName().equals(typeDef.getTypeClassName())) {
fld.setRecursive(true);
break;
}
}
}
fld.setIndex( k );
def.addField( fld );
}
}
// check whether it is necessary to build the class or not
type.setNovel( isNovelClass( typeDescr ) );