From e4b529f663017ad4068b2acea588d8a166e905ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Mathe=CC=81?= Date: Fri, 30 Sep 2016 17:32:17 +0200 Subject: [PATCH] Annotated COObject with nullability and lightweight generics --- Core/COObject+Private.h | 24 ++++++++++------- Core/COObject+RelationshipCache.h | 12 ++++++--- Core/COObject.h | 45 ++++++++++++++++++------------- Core/CORelationshipCache.h | 2 +- Core/COSerialization.h | 27 +++++++++++-------- Core/COSerialization.m | 3 ++- 6 files changed, 68 insertions(+), 45 deletions(-) diff --git a/Core/COObject+Private.h b/Core/COObject+Private.h index 0ca5b09f4..5770e55de 100644 --- a/Core/COObject+Private.h +++ b/Core/COObject+Private.h @@ -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); @@ -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. * @@ -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 *additionalStoreItemUUIDs; /** * This method is only exposed to be used internally by CoreObject. */ @@ -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. * @@ -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 diff --git a/Core/COObject+RelationshipCache.h b/Core/COObject+RelationshipCache.h index ec2311815..db1c69d99 100644 --- a/Core/COObject+RelationshipCache.h +++ b/Core/COObject+RelationshipCache.h @@ -8,19 +8,23 @@ #import #import +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 diff --git a/Core/COObject.h b/Core/COObject.h index 091c8afc9..2ac175688 100644 --- a/Core/COObject.h +++ b/Core/COObject.h @@ -8,7 +8,10 @@ #import #import -@class COPersistentRoot, COEditingContext, CORevision, COBranch, CORelationshipCache, COObjectGraphContext, COCrossPersistentRootReferenceCache; +@class COPersistentRoot, COEditingContext, CORevision, COBranch, COObjectGraphContext; +@class CORelationshipCache, COCrossPersistentRootReferenceCache, COTag; + +NS_ASSUME_NONNULL_BEGIN /** * @group Core @@ -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. */ @@ -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. * @@ -551,6 +554,7 @@ */ @property (nonatomic, readonly) BOOL isShared; + /** @taskunit History Attributes */ @@ -560,7 +564,7 @@ * * See also -[COBranch currentRevision]. */ -@property (nonatomic, readonly) CORevision *revision; +@property (nonatomic, readonly, nullable) CORevision *revision; /** @taskunit Basic Properties */ @@ -569,7 +573,7 @@ /** * The object name. */ -@property (nonatomic, readwrite, copy) NSString *name; +@property (nonatomic, readwrite, copy, nullable) NSString *name; /** * * Returns the object identifier. @@ -590,7 +594,7 @@ * * The returned collection contains COTag objects. */ -@property (nonatomic, readonly) NSSet *tags; +@property (nonatomic, readonly) NSSet *tags; /** @taskunit Property-Value Coding */ @@ -602,7 +606,7 @@ * * See also -entityDescription and -persistentPropertyNames. */ -@property (nonatomic, readonly) NSArray *propertyNames; +@property (nonatomic, readonly) NSArray *propertyNames; /** * * Returns the persistent properties declared in the receiver entity description. @@ -612,7 +616,7 @@ * * See also -entityDescription and -propertyNames. */ -@property (nonatomic, readonly) NSArray *persistentPropertyNames; +@property (nonatomic, readonly) NSArray *persistentPropertyNames; /** * * Returns the property value. @@ -622,7 +626,7 @@ * * See also -setValue:forProperty:. */ -- (id)valueForProperty: (NSString *)key; +- (nullable id)valueForProperty: (NSString *)key; /** * * Sets the property value. @@ -632,7 +636,7 @@ * * See also -valueForProperty:. */ -- (BOOL)setValue: (id)value forProperty: (NSString *)key; +- (BOOL)setValue: (nullable id)value forProperty: (NSString *)key; /** @taskunit Validation */ @@ -648,7 +652,7 @@ * * See -validateValue:forProperty: and ETValidationResult. */ -- (NSArray *)validateAllValues; +- (NSArray *)validateAllValues; /** * Validates the proposed value against the property, then returns a validation * result array. @@ -671,7 +675,8 @@ * * See -validateValue:forProperty: and ETValidationResult. */ -- (NSArray *)validateValue: (id)value forProperty: (NSString *)key; +- (NSArray *)validateValue: (nullable id)value + forProperty: (NSString *)key; /** * * Validates the receiver when it belongs to the inserted or updated objects in @@ -714,7 +719,7 @@ * -[COObjectGraphContext updatedObjectUUIDs] and * -[COObjectGraphContext changedObjectUUIDs]. */ -- (NSArray *)validate; +- (NSArray *)validate; /** * Calls -validateValue:forProperty: to validate the value, and returns the * validation result through aValue and anError. @@ -723,7 +728,9 @@ * GNUstep programs.
* 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 */ @@ -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; /** * * Sets a value in the variable storage. @@ -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. * @@ -1018,3 +1025,5 @@ @property (nonatomic, readonly) BOOL isZombie; @end + +NS_ASSUME_NONNULL_END diff --git a/Core/CORelationshipCache.h b/Core/CORelationshipCache.h index b6cd3a596..eb554a1c2 100644 --- a/Core/CORelationshipCache.h +++ b/Core/CORelationshipCache.h @@ -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; diff --git a/Core/COSerialization.h b/Core/COSerialization.h index 568682190..e2689d52c 100644 --- a/Core/COSerialization.h +++ b/Core/COSerialization.h @@ -12,6 +12,8 @@ @class COItem; +NS_ASSUME_NONNULL_BEGIN + /** * @group Core * @abstract Additions to convert inner objects into a "semi-serialized" @@ -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 *)types + values: (NSMutableDictionary *)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; @@ -129,3 +132,5 @@ - (id)roundTripValueForProperty: (NSString *)key; @end + +NS_ASSUME_NONNULL_END diff --git a/Core/COSerialization.m b/Core/COSerialization.m index 1ecc968f0..8e7e8f7f5 100644 --- a/Core/COSerialization.m +++ b/Core/COSerialization.m @@ -432,7 +432,8 @@ - (COType)serializedTypeForUnivaluedPropertyDescription: (ETPropertyDescription } } -- (id)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc value: (id)value +- (NSNumber *)serializedTypeForPropertyDescription: (ETPropertyDescription *)aPropertyDesc + value: (id)value { COType type = 0;