Skip to content

Commit

Permalink
Implemented better support for declared in info.
Browse files Browse the repository at this point in the history
Instead of displaying all entries (.h and .m files for example), first the file from comment is tried. If no comment, or missing source file information, the first header file from the object's sourceInfos list is returned. If no header file is found, the first file from the list is returned. Finally if no source information is found, nil is returned.
  • Loading branch information
tomaz committed Dec 9, 2010
1 parent ec00a81 commit 1efedb6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Model/GBModelBase.h
Expand Up @@ -35,13 +35,25 @@
@see sourceInfos
@see registerSourceInfo:
@see prefferedSourceInfo:
*/
- (NSArray *)sourceInfosSortedByName;

/** Returns the preffered source info that should be rendered to output.
This investigates `sourceInfos` list and `comment` and returns the most likely used one. If comment is given and has source information attached, that one is used. If comment is not given, source information list from the receiver is used. If header file is found in the list, that one is preffered. If header file is not found, the first file is returned.
@return Returns preffered source information object to be used for output.
@see sourceInfos
@see sourceInfosSortedByName
*/
@property (readonly) GBSourceInfo *prefferedSourceInfo;

/** The list of all declared file data as `GBSourceInfo` objects.
@see registerSourceInfo:
@see sourceInfosSortedByName
@see prefferedSourceInfo
*/
@property (readonly) NSSet *sourceInfos;

Expand Down
12 changes: 12 additions & 0 deletions Model/GBModelBase.m
Expand Up @@ -70,6 +70,18 @@ - (void)registerSourceInfo:(GBSourceInfo *)data {
[_sourceInfos addObject:data];
}

- (GBSourceInfo *)prefferedSourceInfo {
if (self.comment && self.comment.sourceInfo) return self.comment.sourceInfo;
if ([self.sourceInfos count] > 0) {
NSArray *infos = [self sourceInfosSortedByName];
for (GBSourceInfo *info in infos) {
if ([[info.filename pathExtension] isEqualToString:@"h"]) return info;
}
return [infos objectAtIndex:0];
}
return nil;
}

- (NSArray *)sourceInfosSortedByName {
return [[self.sourceInfos allObjects] sortedArrayUsingSelector:@selector(compare:)];
}
Expand Down
4 changes: 2 additions & 2 deletions Templates/html/object-template.html
Expand Up @@ -147,12 +147,12 @@ <h4 class="method-subtitle">{{strings/objectMethods/seeAlsoTitle}}</h4>
</div>
{{/hasCrossrefs}}

{{#prefferedSourceInfo}}
<div class="method-subsection declared-in-section">
<h4 class="method-subtitle">{{strings/objectMethods/declaredInTitle}}</h4>
{{#sourceInfosSortedByName}}
<code class="declared-in-ref">{{filename}}</code><br />
{{/sourceInfosSortedByName}}
</div>
{{/prefferedSourceInfo}}
{{/comment}}
</div>
EndSection
Expand Down
46 changes: 46 additions & 0 deletions Testing/GBModelBaseTesting.m
Expand Up @@ -94,4 +94,50 @@ - (void)testMergeDataFromObject_shouldKeepOriginalCommentIfBothObjectsHaveCommen
assertThat(source.comment.stringValue, is(@"Comment2"));
}

#pragma mark Source information testing

- (void)testPrefferedSourceInfo_shouldReturnSourceInfoFromComment {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
object.comment = [GBComment commentWithStringValue:@"comment"];
object.comment.sourceInfo = [GBSourceInfo infoWithFilename:@"file1" lineNumber:1];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"file.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo, is(object.comment.sourceInfo));
}

- (void)testPrefferedSourceInfo_shouldReturnHeaderFileSourceInfoIfCommentNotGiven {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"b.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"b.h"));
}

- (void)testPrefferedSourceInfo_shouldReturnHeaderFileSourceInfoIfCommentDoesntHaveSourceInfo {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
object.comment = [GBComment commentWithStringValue:@"comment"];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"b.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"b.h"));
}

- (void)testPrefferedSourceInfo_shouldReturnSingleSourceInfo {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"a.m"));
}

- (void)testPrefferedSourceInfo_shouldReturnNilIfNoSourceInfoAvailable {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
// execute & verify
assertThat(object.prefferedSourceInfo, is(nil));
}

@end

0 comments on commit 1efedb6

Please sign in to comment.