Skip to content

Commit

Permalink
Annotated COObject with nullability and lightweight generics
Browse files Browse the repository at this point in the history
  • Loading branch information
qmathe committed Sep 30, 2016
1 parent 8918fdc commit e4b529f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 45 deletions.
24 changes: 14 additions & 10 deletions Core/COObject+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@class CORelationshipCache, COObjectGraphContext;

NS_ASSUME_NONNULL_BEGIN

void SetterToProperty(const char *setter, size_t setterlen, char *prop);
BOOL IsSetter(const char *selname, size_t sellen);

Expand All @@ -24,7 +26,7 @@ ETEntityDescription *entityDescriptionForObjectInRepository();
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (Class)coreObjectCollectionClassForPropertyDescription: (ETPropertyDescription *)propDesc;
- (nullable Class)coreObjectCollectionClassForPropertyDescription: (ETPropertyDescription *)propDesc;
/**
* This method is only exposed to be used internally by CoreObject.
*
Expand Down Expand Up @@ -57,7 +59,7 @@ ETEntityDescription *entityDescriptionForObjectInRepository();
/**
* This method is only exposed to be used internally by CoreObject.
*/
@property (nonatomic, readonly) NSDictionary *additionalStoreItemUUIDs;
@property (nonatomic, readonly) NSDictionary<NSString *, ETUUID *> *additionalStoreItemUUIDs;
/**
* This method is only exposed to be used internally by CoreObject.
*/
Expand All @@ -72,23 +74,23 @@ ETEntityDescription *entityDescriptionForObjectInRepository();
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (id)valueForStorageKey: (NSString *)key;
- (nullable id)valueForStorageKey: (NSString *)key;
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (id)valueForStorageKey: (NSString *)key shouldLoad: (BOOL)shouldLoad;
- (nullable id)valueForStorageKey: (NSString *)key shouldLoad: (BOOL)shouldLoad;
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (id)serializableValueForStorageKey: (NSString *)key;
- (nullable id)serializableValueForStorageKey: (NSString *)key;
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (void)setValue: (id)value forStorageKey: (NSString *)key;
- (void)setValue: (nullable id)value forStorageKey: (NSString *)key;
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (id)valueForProperty: (NSString *)key shouldLoad: (BOOL)shouldLoad;
- (nullable id)valueForProperty: (NSString *)key shouldLoad: (BOOL)shouldLoad;
/**
* This method is only exposed to be used internally by CoreObject.
*
Expand Down Expand Up @@ -135,11 +137,13 @@ ETEntityDescription *entityDescriptionForObjectInRepository();
/**
* This method is only exposed to be used in the CoreObject tests.
*/
@property (nonatomic, readonly) NSSet *referringObjects;
@property (nonatomic, readonly) NSSet<__kindof COObject *> *referringObjects;
/**
* This method is only exposed to be used internally by CoreObject.
*/
- (void)replaceReferencesToObjectIdenticalTo: (COObject *)anObject
withObject: (COObject *)aReplacement;
- (void)replaceReferencesToObjectIdenticalTo: (nullable COObject *)anObject
withObject: (nullable COObject *)aReplacement;

@end

NS_ASSUME_NONNULL_END
12 changes: 8 additions & 4 deletions Core/COObject+RelationshipCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
#import <Foundation/Foundation.h>
#import <CoreObject/COObject.h>

NS_ASSUME_NONNULL_BEGIN

@interface COObject (RelationshipCache)

- (void)updateCachedOutgoingRelationshipsForOldValue: (id)oldVal
newValue: (id)newVal
- (void)updateCachedOutgoingRelationshipsForOldValue: (nullable id)oldVal
newValue: (nullable id)newVal
ofPropertyWithDescription: (ETPropertyDescription *)aProperty;
- (void)removeCachedOutgoingRelationships;
- (void)removeCachedOutgoingRelationshipsForCollectionValue: (id)obj
ofPropertyWithDescription: (ETPropertyDescription *)aProperty;
- (void)addCachedOutgoingRelationshipsForCollectionValue: (id)obj
ofPropertyWithDescription: (ETPropertyDescription *)aProperty;
- (void)removeCachedOutgoingRelationshipsForValue: (id)aValue
- (void)removeCachedOutgoingRelationshipsForValue: (nullable id)aValue
ofPropertyWithDescription: (ETPropertyDescription *)aProperty;
- (void)addCachedOutgoingRelationshipsForValue: (id)aValue
- (void)addCachedOutgoingRelationshipsForValue: (nullable id)aValue
ofPropertyWithDescription: (ETPropertyDescription *)aProperty;

@end

NS_ASSUME_NONNULL_END
45 changes: 27 additions & 18 deletions Core/COObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#import <Foundation/Foundation.h>
#import <EtoileFoundation/EtoileFoundation.h>

@class COPersistentRoot, COEditingContext, CORevision, COBranch, CORelationshipCache, COObjectGraphContext, COCrossPersistentRootReferenceCache;
@class COPersistentRoot, COEditingContext, CORevision, COBranch, COObjectGraphContext;
@class CORelationshipCache, COCrossPersistentRootReferenceCache, COTag;

NS_ASSUME_NONNULL_BEGIN

/**
* @group Core
Expand Down Expand Up @@ -500,17 +503,17 @@
* Returns the branch when the receiver is persistent, otherwise
* returns nil.
*/
@property (nonatomic, readonly, weak) COBranch *branch;
@property (nonatomic, readonly, weak, nullable) COBranch *branch;
/**
* Returns the persistent root when the receiver is persistent, otherwise
* returns nil.
*/
@property (nonatomic, readonly, weak) COPersistentRoot *persistentRoot;
@property (nonatomic, readonly, weak, nullable) COPersistentRoot *persistentRoot;
/**
* Returns the editing context when the receiver is persistent, otherwise
* returns nil.
*/
@property (nonatomic, readonly, weak) COEditingContext *editingContext;
@property (nonatomic, readonly, weak, nullable) COEditingContext *editingContext;
/**
* Returns the object graph context owning the receiver.
*/
Expand All @@ -523,7 +526,7 @@
*
* See also -isRoot.
*/
@property (nonatomic, readonly) id rootObject;
@property (nonatomic, readonly, nullable) __kindof COObject *rootObject;
/**
* Returns whether the receiver is owned by a persistent root.
*
Expand Down Expand Up @@ -551,6 +554,7 @@
*/
@property (nonatomic, readonly) BOOL isShared;


/** @taskunit History Attributes */


Expand All @@ -560,7 +564,7 @@
*
* See also -[COBranch currentRevision].
*/
@property (nonatomic, readonly) CORevision *revision;
@property (nonatomic, readonly, nullable) CORevision *revision;


/** @taskunit Basic Properties */
Expand All @@ -569,7 +573,7 @@
/**
* The object name.
*/
@property (nonatomic, readwrite, copy) NSString *name;
@property (nonatomic, readwrite, copy, nullable) NSString *name;
/**
* <override-dummy />
* Returns the object identifier.
Expand All @@ -590,7 +594,7 @@
*
* The returned collection contains COTag objects.
*/
@property (nonatomic, readonly) NSSet *tags;
@property (nonatomic, readonly) NSSet<COTag *> *tags;


/** @taskunit Property-Value Coding */
Expand All @@ -602,7 +606,7 @@
*
* See also -entityDescription and -persistentPropertyNames.
*/
@property (nonatomic, readonly) NSArray *propertyNames;
@property (nonatomic, readonly) NSArray<NSString *> *propertyNames;
/**
* <override-never />
* Returns the persistent properties declared in the receiver entity description.
Expand All @@ -612,7 +616,7 @@
*
* See also -entityDescription and -propertyNames.
*/
@property (nonatomic, readonly) NSArray *persistentPropertyNames;
@property (nonatomic, readonly) NSArray<NSString *> *persistentPropertyNames;
/**
* <override-never />
* Returns the property value.
Expand All @@ -622,7 +626,7 @@
*
* See also -setValue:forProperty:.
*/
- (id)valueForProperty: (NSString *)key;
- (nullable id)valueForProperty: (NSString *)key;
/**
* <override-never />
* Sets the property value.
Expand All @@ -632,7 +636,7 @@
*
* See also -valueForProperty:.
*/
- (BOOL)setValue: (id)value forProperty: (NSString *)key;
- (BOOL)setValue: (nullable id)value forProperty: (NSString *)key;


/** @taskunit Validation */
Expand All @@ -648,7 +652,7 @@
*
* See -validateValue:forProperty: and ETValidationResult.
*/
- (NSArray *)validateAllValues;
- (NSArray<ETValidationResult *> *)validateAllValues;
/**
* Validates the proposed value against the property, then returns a validation
* result array.
Expand All @@ -671,7 +675,8 @@
*
* See -validateValue:forProperty: and ETValidationResult.
*/
- (NSArray *)validateValue: (id)value forProperty: (NSString *)key;
- (NSArray<ETValidationResult *> *)validateValue: (nullable id)value
forProperty: (NSString *)key;
/**
* <override-dummy />
* Validates the receiver when it belongs to the inserted or updated objects in
Expand Down Expand Up @@ -714,7 +719,7 @@
* -[COObjectGraphContext updatedObjectUUIDs] and
* -[COObjectGraphContext changedObjectUUIDs].
*/
- (NSArray *)validate;
- (NSArray<ETValidationResult *> *)validate;
/**
* Calls -validateValue:forProperty: to validate the value, and returns the
* validation result through aValue and anError.
Expand All @@ -723,7 +728,9 @@
* GNUstep programs.<br />
* For Etoile programs or new projects, you should use -validateValue:forProperty:.
*/
- (BOOL)validateValue: (id *)aValue forKey: (NSString *)key error: (NSError **)anError;
- (BOOL)validateValue: (id _Nullable *_Nonnull)aValue
forKey: (NSString *)key
error: (NSError **)anError;


/** @taskunit Direct Access to the Variable Storage */
Expand All @@ -738,7 +745,7 @@
* This is a low-level method whose use should be restricted to serialization
* code and accessors that expose properties with no related instance variable.
*/
- (id)valueForVariableStorageKey: (NSString *)key;
- (nullable id)valueForVariableStorageKey: (NSString *)key;
/**
* <override-never />
* Sets a value in the variable storage.
Expand Down Expand Up @@ -992,7 +999,7 @@
*
* This is used to present the revision to the user in the UI.
*/
@property (nonatomic, readonly) NSString *revisionDescription;
@property (nonatomic, readonly, nullable) NSString *revisionDescription;
/**
* Returns the receiver tags in a coma separated list.
*
Expand All @@ -1018,3 +1025,5 @@
@property (nonatomic, readonly) BOOL isZombie;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion Core/CORelationshipCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@property (nonatomic, readonly) NSDictionary *descriptionDictionary;

@property (readwrite, nonatomic, weak) COObject *sourceObject;
@property (readwrite, nonatomic, weak) __kindof COObject *sourceObject;
@property (readwrite, nonatomic, copy) NSString *sourceProperty;
@property (readwrite, nonatomic, copy) NSString *targetProperty;

Expand Down
27 changes: 16 additions & 11 deletions Core/COSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@class COItem;

NS_ASSUME_NONNULL_BEGIN

/**
* @group Core
* @abstract Additions to convert inner objects into a "semi-serialized"
Expand Down Expand Up @@ -93,25 +95,26 @@

/** @taskunit Serialization */

- (id)serializedValueForValue: (id)aValue
- (id)serializedValueForValue: (nullable id)aValue
propertyDescription: (ETPropertyDescription *)aPropertyDesc;
- (id)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc value: (id)value;
- (NSNumber *)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc
value: (nullable id)value;
- (SEL)serializationGetterForProperty: (NSString *)property;
- (COItem *)storeItemWithUUID: (ETUUID *)aUUID
types: (NSMutableDictionary *)types
values: (NSMutableDictionary *)values
types: (NSMutableDictionary<NSString *, NSNumber *> *)types
values: (NSMutableDictionary<NSString *, id> *)values
entityName: (NSString *)anEntityName
packageDescription: (ETPackageDescription *)package;
- (COItem *)additionalStoreItemForUUID: (ETUUID *)anItemUUID;
- (nullable COItem *)additionalStoreItemForUUID: (ETUUID *)anItemUUID;

/** @taskunit Deserialization */

- (COObject *)objectForSerializedReference: (id)value
ofType: (COType)type
propertyDescription: (ETPropertyDescription *)aPropertyDesc;
- (id)valueForSerializedValue: (id)value
ofType: (COType)type
propertyDescription: (ETPropertyDescription *)aPropertyDesc;
- (nullable __kindof COObject *)objectForSerializedReference: (id)value
ofType: (COType)type
propertyDescription: (ETPropertyDescription *)aPropertyDesc;
- (nullable id)valueForSerializedValue: (id)value
ofType: (COType)type
propertyDescription: (ETPropertyDescription *)aPropertyDesc;
- (SEL)serializationSetterForProperty: (NSString *)property;
- (void)validateStoreItem: (COItem *)aStoreItem;

Expand All @@ -129,3 +132,5 @@
- (id)roundTripValueForProperty: (NSString *)key;

@end

NS_ASSUME_NONNULL_END
3 changes: 2 additions & 1 deletion Core/COSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ - (COType)serializedTypeForUnivaluedPropertyDescription: (ETPropertyDescription
}
}

- (id)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc value: (id)value
- (NSNumber *)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc
value: (id)value
{
COType type = 0;

Expand Down

0 comments on commit e4b529f

Please sign in to comment.