Permalink
Browse files

Implemented better support for declared in info.

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...
1 parent ec00a81 commit 1efedb6f9a575de74833677044f4c5361c26553b @tomaz committed Dec 9, 2010
Showing with 72 additions and 2 deletions.
  1. +12 −0 Model/GBModelBase.h
  2. +12 −0 Model/GBModelBase.m
  3. +2 −2 Templates/html/object-template.html
  4. +46 −0 Testing/GBModelBaseTesting.m
View
12 Model/GBModelBase.h
@@ -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;
View
12 Model/GBModelBase.m
@@ -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:)];
}
View
4 Templates/html/object-template.html
@@ -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
View
46 Testing/GBModelBaseTesting.m
@@ -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.