Skip to content
This repository

Fix for issue #299 #300

Merged
merged 1 commit into from over 1 year ago

2 participants

Rob Siwek tomaz
Rob Siwek

Fixes edge case where you declare a custom getter for a @property but share the property name w/ an instance method which results in a raised exception when validating the getter selector.
see #299

tomaz tomaz merged commit ed85973 into from
tomaz tomaz closed this
tomaz
Owner

Just merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 04, 2013
Rob Siwek nerdsRob should fix issue #299 c89c984
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 23 additions and 2 deletions. Show diff stats Hide diff stats

  1. +11 0 Model/GBMethodData.h
  2. +12 2 Model/GBMethodData.m
11 Model/GBMethodData.h
@@ -107,6 +107,9 @@ typedef NSUInteger GBMethodType;
107 107 */
108 108 @property (readonly) NSString *methodSelector;
109 109
  110 +/** Method return type that can be used for shared property/method names. */
  111 +@property (readonly) NSString *methodReturnType;
  112 +
110 113 /** Method selector including prefix.
111 114
112 115 @see methodSelector
@@ -188,4 +191,12 @@ typedef NSUInteger GBMethodType;
188 191 */
189 192 - (NSArray *)formattedComponents;
190 193
  194 +/** Returns the data type of the property.
  195 +
  196 + This searches the `methodResultTypes` array and returns the property data type. This only applies to properties, returns `nil` otherwise!
  197 +
  198 + @see methodResultTypes
  199 + */
  200 +- (NSString *)propertyType;
  201 +
191 202 @end
14 Model/GBMethodData.m
@@ -116,6 +116,7 @@ - (id)initWithType:(GBMethodType)type attributes:(NSArray *)attributes result:(N
116 116 _methodPrefix = [[self prefixFromAssignedData] retain];
117 117 _methodSelectorDelimiter = [[self selectorDelimiterFromAssignedData] retain];
118 118 _methodSelector = [[self selectorFromAssignedData] retain];
  119 + _methodReturnType = (NSString *)self.methodResultTypes.firstObject;
119 120 _prefixedMethodSelector = [[self prefixedSelectorFromAssignedData] retain];
120 121 }
121 122 return self;
@@ -279,6 +280,13 @@ - (NSString *)propertySetterSelector {
279 280 return result;
280 281 }
281 282
  283 +- (NSString *)propertyType {
  284 + if (self.methodType != GBMethodTypeProperty) return nil;
  285 + NSString *result = (NSString *)self.methodResultTypes.firstObject;
  286 + if (!result) result = self.methodReturnType;
  287 + return result;
  288 +}
  289 +
282 290 - (NSString *)attributeValueForKey:(NSString *)key {
283 291 // Returns the value after equal sign for the given key (i.e. for attributes "getter", "=", "value", this would return "value"). Returns nil if either key isn't found or isn't followed by equal sign and/or a value.
284 292 __block NSString *result = nil;
@@ -317,10 +325,11 @@ - (BOOL)validateMergeWith:(GBMethodData *)source {
317 325 [NSException raise:@"Failed merging %@ to %@; method type doesn't match!", source, self];
318 326 }
319 327
320   - // We should allow if the getter or setter matches.
  328 + // We should allow if the getter or setter matches and if the getter name is shared to an instance method.
321 329 if ([propertyData.propertyGetterSelector isEqualToString:manualData.methodSelector]) return YES;
322 330 if ([propertyData.propertySetterSelector isEqualToString:manualData.methodSelector]) return YES;
323   - [NSException raise:@"Failed merging %@ to %@; getter or setter doesn't match", source, self];
  331 + if (![propertyData.propertyType isEqualToString:manualData.methodReturnType]) return YES;
  332 + [NSException raise:@"Failed merging %@ to %@; getter or setter doesn't match", source, self];
324 333 } else {
325 334 // If assertion from code below is present, it breaks cases where category declares a property which is also getter for a property from class declaration. See #184 https://github.com/tomaz/appledoc/issues/184 for details. I'm leaving the code commented for the moment to see if it also affects some other user (don't think so, but just in case).
326 335 //NSParameterAssert([source.methodSelector isEqualToString:self.methodSelector]);
@@ -386,6 +395,7 @@ - (BOOL)isProperty {
386 395 @synthesize methodResultTypes = _methodResultTypes;
387 396 @synthesize methodArguments = _methodArguments;
388 397 @synthesize methodSelector = _methodSelector;
  398 +@synthesize methodReturnType = _methodReturnType;
389 399 @synthesize methodSelectorDelimiter = _methodSelectorDelimiter;
390 400 @synthesize methodPrefix = _methodPrefix;
391 401 @synthesize prefixedMethodSelector = _prefixedMethodSelector;

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.