Skip to content

Commit

Permalink
Moved -willVisitProtocol:/-didVisitProtocol: from CDClssDumpVisitor t…
Browse files Browse the repository at this point in the history
…o CDTextClassDumpVisitor.

Implement in CDMultiFileVisitor to generate header files for these protocols, as requested by
Gregor Riepl.
  • Loading branch information
nygard committed Sep 3, 2007
1 parent 3037d15 commit 5d149a5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
3 changes: 0 additions & 3 deletions CDClassDumpVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@

- (void)visitObjectiveCSegment:(CDObjCSegmentProcessor *)anObjCSegment;

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;

@end
20 changes: 0 additions & 20 deletions CDClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,4 @@ - (void)visitObjectiveCSegment:(CDObjCSegmentProcessor *)anObjCSegment;
[resultString appendString:@" */\n\n"];
}

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
{
NSArray *protocols;

[resultString appendFormat:@"@protocol %@", [aProtocol name]];

protocols = [aProtocol protocols];
if ([protocols count] > 0) {
[resultString appendFormat:@" <%@>", [[protocols arrayByMappingSelector:@selector(name)] componentsJoinedByString:@", "]];
[symbolReferences addProtocolNamesFromArray:[protocols arrayByMappingSelector:@selector(name)]];
}

[resultString appendString:@"\n"];
}

- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;
{
[resultString appendString:@"@end\n\n"];
}

@end
3 changes: 3 additions & 0 deletions CDMultiFileVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
- (void)willVisitCategory:(CDOCCategory *)aCategory;
- (void)didVisitCategory:(CDOCCategory *)aCategory;

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;

@end
40 changes: 40 additions & 0 deletions CDMultiFileVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,44 @@ - (void)didVisitCategory:(CDOCCategory *)aCategory;
symbolReferences = nil;
}

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
{
[resultString setString:@""];
[classDump appendHeaderToString:resultString];

NSParameterAssert(symbolReferences == nil);
symbolReferences = [[CDSymbolReferences alloc] init];

//[self appendImportForClassName:[aClass superClassName]];
referenceIndex = [resultString length];

// And then generate the regular output
[super willVisitProtocol:aProtocol];
}

- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;
{
NSString *referenceString;
NSString *filename;

// Generate the regular output
[super didVisitProtocol:aProtocol];

// Then insert the imports and write the file.
//[symbolReferences removeClassName:[aClass name]];
//[symbolReferences removeClassName:[aClass superClassName]];
referenceString = [symbolReferences referenceString];
if (referenceString != nil)
[resultString insertString:referenceString atIndex:referenceIndex];

filename = [NSString stringWithFormat:@"%@-Protocol.h", [aProtocol name]];
if (outputPath != nil)
filename = [outputPath stringByAppendingPathComponent:filename];

[[resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];

[symbolReferences release];
symbolReferences = nil;
}

@end
3 changes: 3 additions & 0 deletions CDTextClassDumpVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
- (void)willVisitCategory:(CDOCCategory *)aCategory;
- (void)didVisitCategory:(CDOCCategory *)aCategory;

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;

- (void)visitClassMethod:(CDOCMethod *)aMethod;
- (void)visitInstanceMethod:(CDOCMethod *)aMethod;
- (void)visitIvar:(CDOCIvar *)anIvar;
Expand Down
20 changes: 20 additions & 0 deletions CDTextClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ - (void)didVisitCategory:(CDOCCategory *)aCategory;
[resultString appendString:@"@end\n\n"];
}

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
{
NSArray *protocols;

[resultString appendFormat:@"@protocol %@", [aProtocol name]];

protocols = [aProtocol protocols];
if ([protocols count] > 0) {
[resultString appendFormat:@" <%@>", [[protocols arrayByMappingSelector:@selector(name)] componentsJoinedByString:@", "]];
[symbolReferences addProtocolNamesFromArray:[protocols arrayByMappingSelector:@selector(name)]];
}

[resultString appendString:@"\n"];
}

- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;
{
[resultString appendString:@"@end\n\n"];
}

- (void)visitClassMethod:(CDOCMethod *)aMethod;
{
[resultString appendString:@"+ "];
Expand Down

0 comments on commit 5d149a5

Please sign in to comment.