Permalink
Browse files

Fixed property name detection. Closes #153.

The problem was with recent support for termination macros: originally appledoc always took the last component for property name, but that's obviously not working for termination macros. So the new code took the second component which broke cases like `IBOutlet UIView *name`. To compensate, the code now tries to handle the stuff more intelligently.

**Note:** Just a side note: recent pull requests broke several unit tests, including method/property handling ones, so there might be additional incompatibilities! Will need to check those too!
  • Loading branch information...
1 parent c1eb57f commit debb1aac3436c4470bea9f83fef5e67e9c75279b @tomaz committed Dec 8, 2011
Showing with 41 additions and 4 deletions.
  1. +17 −4 Model/GBMethodData.m
  2. +24 −0 Testing/GBMethodDataTesting.m
View
@@ -47,6 +47,7 @@ + (id)propertyDataWithAttributes:(NSArray *)attributes components:(NSArray *)com
NSMutableArray *results = [NSMutableArray array];
BOOL nextComponentIsBlockPropertyName = NO;
BOOL nextComponentIsBlockReturnComponent = NO;
+ BOOL nextComponentIsPropertyName = NO;
BOOL inProtocolsList = NO;
NSUInteger parenthesisLevel = 0;
for (NSString *component in components) {
@@ -67,23 +68,35 @@ + (id)propertyDataWithAttributes:(NSArray *)attributes components:(NSArray *)com
} else if ([component isEqualToString:@">"]) {
inProtocolsList = NO;
[results addObject:component];
- } else if ([component isMatchedByRegex:@"^[_a-zA-Z][_a-zA-Z0-9]*$"]) {
- if (results.count == 0 || inProtocolsList) {
+ } else if ([component isEqualToString:@"*"]) {
+ [results addObject:component];
+ nextComponentIsPropertyName = YES;
+ } else if ([component isMatchedByRegex:@"^[_a-zA-Z][_a-zA-Z0-9]$"]) {
+ if (results.count == 0 || inProtocolsList) {
[results addObject:component];
- } else if (propertyName == nil) {
+ } else if (propertyName == nil || nextComponentIsPropertyName) {
propertyName = component;
+ nextComponentIsPropertyName = NO;
} else {
// ignore termination macro
}
} else if (propertyName == nil) {
- [results addObject:component];
+ if (nextComponentIsPropertyName) {
+ propertyName = propertyName;
+ nextComponentIsPropertyName = NO;
+ } else {
+ [results addObject:component];
+ }
}
if ([component isEqualToString:@"("]) {
++parenthesisLevel;
} else if ([component isEqualToString:@")"]) {
--parenthesisLevel;
}
}
+
+ // In case we end up with no property name, just take the last component...
+ if (!propertyName) propertyName = [components lastObject];
GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:propertyName];
return [[[self alloc] initWithType:GBMethodTypeProperty attributes:attributes result:results arguments:[NSArray arrayWithObject:argument]] autorelease];
@@ -72,6 +72,30 @@ - (void)testMethodData_shouldInitializePropertySelector {
assertThat(data.methodSelector, is(@"isSelected"));
}
+#pragma mark - Property initializations
+
+- (void)testMethodData_shouldInitializePropertyWithSingleComponent {
+ // setup & execute
+ NSArray *attributes = [NSArray arrayWithObjects:@"readonly", nil];
+ NSArray *components = [NSArray arrayWithObjects:@"UIView", @"*", @"value", nil];
+ GBMethodData *data = [GBMethodData propertyDataWithAttributes:attributes components:components];
+ // verify
+ assertThat(data.methodAttributes, onlyContains(@"readonly", nil));
+ assertThat(data.methodResultTypes, onlyContains(@"UIView", @"*", nil));
+ assertThat(data.methodSelector, is(@"value"));
+}
+
+- (void)testMethodData_shouldInitializePropertyWithMultipleComponents {
+ // setup & execute
+ NSArray *attributes = [NSArray arrayWithObjects:@"nonatomic", @"assign", nil];
+ NSArray *components = [NSArray arrayWithObjects:@"IBOutlet", @"UIView", @"*", @"value", nil];
+ GBMethodData *data = [GBMethodData propertyDataWithAttributes:attributes components:components];
+ // verify
+ assertThat(data.methodAttributes, onlyContains(@"nonatomic", @"assign", nil));
+ assertThat(data.methodResultTypes, onlyContains(@"IBOutlet", @"UIView", @"*", nil));
+ assertThat(data.methodSelector, is(@"value"));
+}
+
#pragma mark Merging testing
- (void)testMergeDataFromObject_shouldMergeImplementationDetails {

0 comments on commit debb1aa

Please sign in to comment.