Skip to content
Browse files

Fixed removal of undocumented objects in case only undocumented metho…

…ds are registered.

The problem was that we didn't count uncommented methods that were unregistered. But then we calculated the number of commented methods by subtracting the sum of uncommented methods from all methods before handling them. So either we would need to use existing methods count or count all undocumented methods. I chose the second approach.
  • Loading branch information...
1 parent d642b4d commit 59ef9f3a245edfe649e3c77f530955ecc7996b52 @tomaz committed Dec 6, 2010
Showing with 27 additions and 4 deletions.
  1. +3 −4 Processing/GBProcessor.m
  2. +24 −0 Testing/GBProcessor-UndocumentedObjectsTesting.m
View
7 Processing/GBProcessor.m
@@ -211,6 +211,7 @@ - (void)processParametersFromComment:(GBComment *)comment matchingMethod:(GBMeth
#pragma mark Undocumented objects handling
- (void)removeUndocumentedObjectsFromStore {
+ if (self.settings.keepUndocumentedObjects && self.settings.keepUndocumentedMembers) return;
GBLogInfo(@"Investigating undocumented objects and members...");
[self removeUndocumentedObjectsInSet:self.store.classes];
[self removeUndocumentedObjectsInSet:self.store.categories];
@@ -219,7 +220,6 @@ - (void)removeUndocumentedObjectsFromStore {
- (void)removeUndocumentedObjectsInSet:(NSSet *)objects {
// Removes all undocumented objects and theri methods and properties as required by current settings. If settings don't allow removal, no object is removed. Note that we need to take care when deleting objects during enumerating: in both loops - top-level objects and members - we do a copy of returned array. Although for top-level objects this wouldn't be needed as the methods themselves return a copy, it's better to do additional shallow copy in case we change the functionality in the future to return cached values for example; this would break this code and present hard to find bug. Also note that we're assuming each object in the set is either a class, category or protocol...
- if (self.settings.keepUndocumentedObjects && self.settings.keepUndocumentedMembers) return;
BOOL deleteObjects = !self.settings.keepUndocumentedObjects;
BOOL deleteMethods = !self.settings.keepUndocumentedMembers;
NSArray *array = [objects allObjects];
@@ -228,16 +228,15 @@ - (void)removeUndocumentedObjectsInSet:(NSSet *)objects {
GBMethodsProvider *provider = [(id<GBObjectDataProviding>)object methods];
NSArray *methods = [provider.methods copy];
- // Count or delete all undocumented methods.
+ // Count and delete all undocumented methods.
NSUInteger uncommentedMethodsCount = 0;
for (GBMethodData *method in methods) {
if ([self isCommentValid:method.comment]) continue;
if (deleteMethods) {
GBLogVerbose(@"Removing undocumented method %@...", method);
[provider unregisterMethod:method];
- } else {
- uncommentedMethodsCount++;
}
+ uncommentedMethodsCount++;
}
// Remove the object if it isn't commented or has only uncommented methods.
View
24 Testing/GBProcessor-UndocumentedObjectsTesting.m
@@ -111,6 +111,30 @@ - (void)testProcessObjectsFromStore_shouldDeleteUncommentedMethodsIfKeepMembersI
assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(NO));
}
+- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfAllMethodsAreUnregisteredIfKeepObjectIsYes {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
+ GBClassData *class = [self classWithComment:NO];
+ GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
+ [self registerMethodsOfCount:1 withComment:NO toObject:class];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThatBool([store.classes containsObject:class], equalToBool(YES));
+}
+
+- (void)testProcessObjectsFromStore_shouldDeleteUncommentedObjectIfAllMethodsAreUnregisteredIfKeepObjectIsNo {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
+ GBClassData *class = [self classWithComment:NO];
+ GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
+ [self registerMethodsOfCount:1 withComment:NO toObject:class];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThatBool([store.classes containsObject:class], equalToBool(NO));
+}
+
#pragma mark Creation methods
- (OCMockObject *)settingsProviderKeepObjects:(BOOL)objects keepMembers:(BOOL)members {

0 comments on commit 59ef9f3

Please sign in to comment.
Something went wrong with that request. Please try again.