String fullFieldType = kbuilder != null ?
TypeDeclarationUtils.toBuildableType( typeNameKey, kbuilder.getRootClassLoader() ) :
typeNameKey;
FieldDefinition fieldDef = new FieldDefinition( field.getFieldName(),
fullFieldType );
// field is marked as PK
boolean isKey = field.getAnnotation(TypeDeclaration.ATTR_KEY) != null;
fieldDef.setKey( isKey );
fieldDef.setDeclIndex( field.getIndex() );
if (field.getIndex() < 0) {
int freePos = occupiedPositions.nextClearBit(0);
if (freePos < maxDeclaredPos) {
occupiedPositions.set(freePos);
} else {
freePos = maxDeclaredPos + 1;
}
fieldDef.setPriority(freePos * 256 + curr++);
} else {
fieldDef.setPriority(field.getIndex() * 256 + curr++);
}
fieldDef.setInherited( field.isInherited() );
fieldDef.setRecursive( field.isRecursive() );
fieldDef.setInitExpr( TypeDeclarationUtils.rewriteInitExprWithImports( field.getInitExpr(), typeResolver ) );
for (String annotationName : field.getAnnotationNames()) {
Class annotation = TypeDeclarationUtils.resolveAnnotation( annotationName,
typeResolver );
if (annotation != null && annotation.isAnnotation()) {
try {
AnnotationDefinition annotationDefinition = AnnotationDefinition.build( annotation,
field.getAnnotations().get( annotationName ).getValueMap(),
typeResolver );
fieldDef.addAnnotation( annotationDefinition );
} catch ( NoSuchMethodException nsme ) {
kbuilder.addBuilderResult( new TypeDeclarationError( field,
"Annotated field " + field.getFieldName() +
" - undefined property in @annotation " +
annotationName + ": " + nsme.getMessage() + ";" ) );
}
}
if (annotation == null || annotation == Key.class || annotation == Position.class) {
fieldDef.addMetaData(annotationName, field.getAnnotation(annotationName).getSingleValue());
}
}
queue.add(fieldDef);