Skip to content

Commit

Permalink
Fixed handling instance/static methods with same selector. Closes #90.
Browse files Browse the repository at this point in the history
Note that although this should work, proper solution would require properly handling cross references to these methods too. Currently instance method will be used whenever cross reference is given, regardless of +/- sign. On the other hand, this might not be very common (guessing!?) and would only affect cross references, so will leave this simple solution for now...
  • Loading branch information
tomaz committed May 6, 2011
1 parent 89d29d7 commit f5b602a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Model/GBMethodData.m
Expand Up @@ -20,7 +20,7 @@ - (BOOL)formatTypesFromArray:(NSArray *)types toArray:(NSMutableArray *)array pr
- (NSDictionary *)formattedComponentWithValue:(NSString *)value;
- (NSDictionary *)formattedComponentWithValue:(NSString *)value style:(NSUInteger)style href:(NSString *)href;
- (NSString *)attributeValueForKey:(NSString *)key;
- (void)validateMergeWith:(GBMethodData *)source;
- (BOOL)validateMergeWith:(GBMethodData *)source;
@property (readonly) NSString *methodSelectorDelimiter;
@property (readonly) NSString *methodPrefix;

Expand Down Expand Up @@ -236,8 +236,8 @@ - (NSString *)attributeValueForKey:(NSString *)key {
return result;
}

- (void)validateMergeWith:(GBMethodData *)source {
// Validates merging with the given method. This method raises exception if merging is not allowed based on method types. It takes into account manual propery accessors and mutators!
- (BOOL)validateMergeWith:(GBMethodData *)source {
// Validates merging with the given method. This method raises exception if merging is not allowed based on method types. It takes into account manual propery accessors and mutators! Note that in case class method is being matched with instance, we prevent merging - this is to allow same selectors (due to how we currently handle class/instance methods (i.e. don't distinguish between them when matching by selectors) we simply need to prevent merging taking place in such case).
if (source.methodType != self.methodType) {
GBMethodData *propertyData = nil;
GBMethodData *manualData = nil;
Expand All @@ -247,26 +247,29 @@ - (void)validateMergeWith:(GBMethodData *)source {
} else if (self.methodType == GBMethodTypeInstance && source.methodType == GBMethodTypeProperty) {
propertyData = source;
manualData = self;
} else if (self.methodType == GBMethodTypeInstance && source.methodType == GBMethodTypeClass) {
return NO;
} else {
[NSException raise:@"Failed merging %@ to %@; method type doesn't match!", source, self];
}

// We should allow if the getter or setter matches.
if ([propertyData.propertyGetterSelector isEqualToString:manualData.methodSelector]) return;
if ([propertyData.propertySetterSelector isEqualToString:manualData.methodSelector]) return;
if ([propertyData.propertyGetterSelector isEqualToString:manualData.methodSelector]) return YES;
if ([propertyData.propertySetterSelector isEqualToString:manualData.methodSelector]) return YES;
[NSException raise:@"Failed merging %@ to %@; getter or setter doesn't match", source, self];
} else {
NSParameterAssert([source.methodSelector isEqualToString:self.methodSelector]);
NSParameterAssert([source.methodResultTypes isEqualToArray:self.methodResultTypes]);
}
return YES;
}

#pragma mark Overidden methods

- (void)mergeDataFromObject:(id)source {
if (!source || source == self) return;
GBLogDebug(@"%@: Merging data from %@...", self, source);
[self validateMergeWith:source];
if (![self validateMergeWith:source]) return;

// Use argument var names from the method that has comment. If no method has comment, just keep deafult.
if ([source comment] && ![self comment]) {
Expand Down

0 comments on commit f5b602a

Please sign in to comment.