Skip to content
This repository
Browse code

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...
commit 59ef9f3a245edfe649e3c77f530955ecc7996b52 1 parent d642b4d
tomaz authored
7 Processing/GBProcessor.m
@@ -211,6 +211,7 @@ - (void)processParametersFromComment:(GBComment *)comment matchingMethod:(GBMeth
211 211 #pragma mark Undocumented objects handling
212 212
213 213 - (void)removeUndocumentedObjectsFromStore {
  214 + if (self.settings.keepUndocumentedObjects && self.settings.keepUndocumentedMembers) return;
214 215 GBLogInfo(@"Investigating undocumented objects and members...");
215 216 [self removeUndocumentedObjectsInSet:self.store.classes];
216 217 [self removeUndocumentedObjectsInSet:self.store.categories];
@@ -219,7 +220,6 @@ - (void)removeUndocumentedObjectsFromStore {
219 220
220 221 - (void)removeUndocumentedObjectsInSet:(NSSet *)objects {
221 222 // 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...
222   - if (self.settings.keepUndocumentedObjects && self.settings.keepUndocumentedMembers) return;
223 223 BOOL deleteObjects = !self.settings.keepUndocumentedObjects;
224 224 BOOL deleteMethods = !self.settings.keepUndocumentedMembers;
225 225 NSArray *array = [objects allObjects];
@@ -228,16 +228,15 @@ - (void)removeUndocumentedObjectsInSet:(NSSet *)objects {
228 228 GBMethodsProvider *provider = [(id<GBObjectDataProviding>)object methods];
229 229 NSArray *methods = [provider.methods copy];
230 230
231   - // Count or delete all undocumented methods.
  231 + // Count and delete all undocumented methods.
232 232 NSUInteger uncommentedMethodsCount = 0;
233 233 for (GBMethodData *method in methods) {
234 234 if ([self isCommentValid:method.comment]) continue;
235 235 if (deleteMethods) {
236 236 GBLogVerbose(@"Removing undocumented method %@...", method);
237 237 [provider unregisterMethod:method];
238   - } else {
239   - uncommentedMethodsCount++;
240 238 }
  239 + uncommentedMethodsCount++;
241 240 }
242 241
243 242 // Remove the object if it isn't commented or has only uncommented methods.
24 Testing/GBProcessor-UndocumentedObjectsTesting.m
@@ -111,6 +111,30 @@ - (void)testProcessObjectsFromStore_shouldDeleteUncommentedMethodsIfKeepMembersI
111 111 assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(NO));
112 112 }
113 113
  114 +- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfAllMethodsAreUnregisteredIfKeepObjectIsYes {
  115 + // setup
  116 + GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
  117 + GBClassData *class = [self classWithComment:NO];
  118 + GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
  119 + [self registerMethodsOfCount:1 withComment:NO toObject:class];
  120 + // execute
  121 + [processor processObjectsFromStore:store];
  122 + // verify
  123 + assertThatBool([store.classes containsObject:class], equalToBool(YES));
  124 +}
  125 +
  126 +- (void)testProcessObjectsFromStore_shouldDeleteUncommentedObjectIfAllMethodsAreUnregisteredIfKeepObjectIsNo {
  127 + // setup
  128 + GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
  129 + GBClassData *class = [self classWithComment:NO];
  130 + GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
  131 + [self registerMethodsOfCount:1 withComment:NO toObject:class];
  132 + // execute
  133 + [processor processObjectsFromStore:store];
  134 + // verify
  135 + assertThatBool([store.classes containsObject:class], equalToBool(NO));
  136 +}
  137 +
114 138 #pragma mark Creation methods
115 139
116 140 - (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.