Skip to content

Commit

Permalink
Add better debugging message for FLEXProperty and FLEXIvar
Browse files Browse the repository at this point in the history
  • Loading branch information
matrush committed Jul 11, 2020
1 parent 9b05601 commit e1835fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Classes/Utility/Runtime/Objc/Reflection/FLEXIvar.m
Expand Up @@ -37,7 +37,8 @@ + (instancetype)ivar:(Ivar)ivar {
}

+ (instancetype)named:(NSString *)name onClass:(Class)cls {
Ivar ivar = class_getInstanceVariable(cls, name.UTF8String);
Ivar _Nullable ivar = class_getInstanceVariable(cls, name.UTF8String);
NSAssert(ivar, @"Cannot find ivar with name %@ on class %@", name, cls);
return [self ivar:ivar];
}

Expand Down
25 changes: 13 additions & 12 deletions Classes/Utility/Runtime/Objc/Reflection/FLEXProperty.m
Expand Up @@ -45,8 +45,9 @@ + (instancetype)property:(objc_property_t)property onClass:(Class)cls {
}

+ (instancetype)named:(NSString *)name onClass:(Class)cls {
NSParameterAssert(class_getProperty(cls, name.UTF8String));
return [self property:class_getProperty(cls, name.UTF8String) onClass:cls];
objc_property_t _Nullable property = class_getProperty(cls, name.UTF8String);
NSAssert(property, @"Cannot find property with name %@ on class %@", name, cls);
return [self property:property onClass:cls];
}

+ (instancetype)propertyWithName:(NSString *)name attributes:(FLEXPropertyAttributes *)attributes {
Expand All @@ -55,34 +56,34 @@ + (instancetype)propertyWithName:(NSString *)name attributes:(FLEXPropertyAttrib

- (id)initWithProperty:(objc_property_t)property onClass:(Class)cls {
NSParameterAssert(property);

self = [super init];
if (self) {
_objc_property = property;
_attributes = [FLEXPropertyAttributes attributesForProperty:property];
_name = @(property_getName(property) ?: "(nil)");
_cls = cls;

if (!_attributes) [NSException raise:NSInternalInconsistencyException format:@"Error retrieving property attributes"];
if (!_name) [NSException raise:NSInternalInconsistencyException format:@"Error retrieving property name"];

[self examine];
}

return self;
}

- (id)initWithName:(NSString *)name attributes:(FLEXPropertyAttributes *)attributes {
NSParameterAssert(name); NSParameterAssert(attributes);

self = [super init];
if (self) {
_attributes = attributes;
_name = name;

[self examine];
}

return self;
}

Expand Down Expand Up @@ -160,7 +161,7 @@ - (void)computeSymbolInfo:(BOOL)forceBundle {
if (dladdr(_objc_property, &exeInfo)) {
_imagePath = exeInfo.dli_fname ? @(exeInfo.dli_fname) : nil;
}

if ((!_multiple || !_uniqueCheckFlag) && _cls) {
_multiple = _objc_property != class_getProperty(_cls, self.name.UTF8String);

Expand Down Expand Up @@ -214,7 +215,7 @@ - (NSString *)fullDescription {
} else {
[attributesStrings addObject:@"readwrite"];
}

// Class or not
if (self.isClassProperty) {
[attributesStrings addObject:@"class"];
Expand All @@ -236,7 +237,7 @@ - (NSString *)fullDescription {

- (id)getValue:(id)target {
if (!target) return nil;

// We don't care about checking dynamically whether the getter
// _now_ exists on this object. If the getter doesn't exist
// when this property is initialized, it will never call it.
Expand Down

0 comments on commit e1835fe

Please sign in to comment.