createRecordStructures static method
Create CKRecordStructure
objects from the provided annotated model classes.
Implementation
static void createRecordStructures(List<Type> classTypes)
{
Map<Type,CKRecordStructure> recordStructures = {};
classTypes.forEach((currentType)
{
ClassMirror currentClassMirror = reflector.reflectType(currentType) as ClassMirror;
var ckRecordType = currentType.toString(); // default to local name if none is provided in a CKRecordTypeAnnotation
if (_isTypeInArray<CKRecordTypeAnnotation>(currentClassMirror.metadata)) // if a CKRecordTypeAnnotation is found above the class declaration ...
{
var typeAnnotation = _getTypeFromArray<CKRecordTypeAnnotation>(currentClassMirror.metadata);
ckRecordType = typeAnnotation.type; // ... set the ckRecordType to the name in the annotation
}
var recordStructure = CKRecordStructure(currentType, ckRecordType, currentClassMirror); // create a CKRecordData object to track local and ck field names and types
currentClassMirror.declarations.values.forEach((field) // iterate through member functions, variables, etc
{
if (field is VariableMirror && _isTypeInArray<CKFieldAnnotation>(field.metadata)) // if the field is a variable and tagged with a CKFieldAnnotation ...
{
var fieldAnnotation = _getTypeFromArray<CKFieldAnnotation>(field.metadata); // get the annotation object
recordStructure.fields.add(CKFieldStructure(field.simpleName, fieldAnnotation.name, CKFieldType.fromLocalType(field.reflectedType))); // create a CKFieldData object for the current field
}
else if (field is VariableMirror && _isTypeInArray<CKRecordNameAnnotation>(field.metadata)) // if the field is a variable and tagged with a CKRecordNameAnnotation ...
{
recordStructure.fields.add(CKFieldStructure(field.simpleName, CKConstants.RECORD_NAME_FIELD, CKFieldType.fromLocalType(field.reflectedType))); // create a CKFieldData object for the recordName field
}
});
recordStructures[currentType] = recordStructure;
});
CKRecordParser._recordStructures = recordStructures;
}