From f5b602a059380ee02bb1b16acfe1ce229f532631 Mon Sep 17 00:00:00 2001 From: Tomaz Kragelj Date: Fri, 6 May 2011 13:38:56 +0200 Subject: [PATCH] Fixed handling instance/static methods with same selector. Closes #90. 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... --- Model/GBMethodData.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Model/GBMethodData.m b/Model/GBMethodData.m index 94fe6317..c7ad7d4b 100644 --- a/Model/GBMethodData.m +++ b/Model/GBMethodData.m @@ -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; @@ -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; @@ -247,18 +247,21 @@ - (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 @@ -266,7 +269,7 @@ - (void)validateMergeWith:(GBMethodData *)source { - (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]) {