From 2ea2d801eb66b4148aaad7de612807d83ce7a878 Mon Sep 17 00:00:00 2001 From: Li Jiantang Date: Fri, 17 Jun 2016 13:15:16 +0100 Subject: [PATCH 1/4] Add comment support for Swift Class --- VVDocumenter-Xcode.xcodeproj/project.pbxproj | 8 + VVDocumenter-Xcode/Commenter/VVCommenter.h | 1 + .../Commenter/VVSwiftClassCommenter.h | 13 ++ .../Commenter/VVSwiftClassCommenter.m | 59 ++++++ .../NSString+PDRegex/NSString+PDRegex.m | 11 +- .../NSString+VVSyntax/NSString+VVSyntax.h | 1 + .../NSString+VVSyntax/NSString+VVSyntax.m | 9 +- VVDocumenter-Xcode/VVDocumenter.m | 2 + .../DocumenterTests/VVMethodTestsCode.plist | 195 +++++++++++------- VVDocumenterTests/VVDocumenterTests.m | 1 + VVDocumenterTests/VVTestHelper.m | 3 +- 11 files changed, 217 insertions(+), 86 deletions(-) create mode 100644 VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.h create mode 100644 VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m diff --git a/VVDocumenter-Xcode.xcodeproj/project.pbxproj b/VVDocumenter-Xcode.xcodeproj/project.pbxproj index c79f721..81c9d03 100644 --- a/VVDocumenter-Xcode.xcodeproj/project.pbxproj +++ b/VVDocumenter-Xcode.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1082F0001D13ECF800DDAC35 /* VVSwiftClassCommenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1082EFFF1D13ECF800DDAC35 /* VVSwiftClassCommenter.m */; }; + 10E70BFA1D13FFD000C85E27 /* VVSwiftClassCommenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1082EFFF1D13ECF800DDAC35 /* VVSwiftClassCommenter.m */; }; 4B06DF741B315E9D007D69BE /* VVSwiftExtensionCommenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B50A26F1B315CF3008A4400 /* VVSwiftExtensionCommenter.m */; }; 4B50A2701B315CF3008A4400 /* VVSwiftExtensionCommenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B50A26F1B315CF3008A4400 /* VVSwiftExtensionCommenter.m */; }; 53C67935184501030030C553 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 893D8F7F18262EF500E8A00C /* Carbon.framework */; }; @@ -73,6 +75,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1082EFFE1D13ECF800DDAC35 /* VVSwiftClassCommenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VVSwiftClassCommenter.h; sourceTree = ""; }; + 1082EFFF1D13ECF800DDAC35 /* VVSwiftClassCommenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VVSwiftClassCommenter.m; sourceTree = ""; }; 4B50A26E1B315CF3008A4400 /* VVSwiftExtensionCommenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VVSwiftExtensionCommenter.h; sourceTree = ""; }; 4B50A26F1B315CF3008A4400 /* VVSwiftExtensionCommenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VVSwiftExtensionCommenter.m; sourceTree = ""; }; 893D8F7F18262EF500E8A00C /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; @@ -309,6 +313,8 @@ D16AFCE81796E0D6006719AA /* VVVariableCommenter.m */, 4B50A26E1B315CF3008A4400 /* VVSwiftExtensionCommenter.h */, 4B50A26F1B315CF3008A4400 /* VVSwiftExtensionCommenter.m */, + 1082EFFE1D13ECF800DDAC35 /* VVSwiftClassCommenter.h */, + 1082EFFF1D13ECF800DDAC35 /* VVSwiftClassCommenter.m */, ); path = Commenter; sourceTree = ""; @@ -517,6 +523,7 @@ D124614717AC16820095F9D6 /* VVDocumenterSetting.m in Sources */, C4052CFB1B3BB10700ED0CF0 /* VVWorkspaceManager.m in Sources */, D124614817AC16820095F9D6 /* VVDSettingPanelWindowController.m in Sources */, + 1082F0001D13ECF800DDAC35 /* VVSwiftClassCommenter.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -537,6 +544,7 @@ D1A6B1D1198A0D8600BCED83 /* VVSwiftPropertyCommenter.m in Sources */, D14110B51988C12F00A7083F /* NSTextView+VVTextGetter.m in Sources */, D14110B61988C12F00A7083F /* VVDocumenterManager.m in Sources */, + 10E70BFA1D13FFD000C85E27 /* VVSwiftClassCommenter.m in Sources */, D14110B71988C12F00A7083F /* VVDocumenter.m in Sources */, D14110A81988C12000A7083F /* VVArgument.m in Sources */, D1C6124919891B3700FDB554 /* VVSwiftEnumCommenter.m in Sources */, diff --git a/VVDocumenter-Xcode/Commenter/VVCommenter.h b/VVDocumenter-Xcode/Commenter/VVCommenter.h index 319a130..ff716cc 100755 --- a/VVDocumenter-Xcode/Commenter/VVCommenter.h +++ b/VVDocumenter-Xcode/Commenter/VVCommenter.h @@ -40,5 +40,6 @@ #import "VVSwiftEnumCommenter.h" #import "VVSwiftPropertyCommenter.h" #import "VVSwiftExtensionCommenter.h" +#import "VVSwiftClassCommenter.h" #endif diff --git a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.h b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.h new file mode 100644 index 0000000..6d3c418 --- /dev/null +++ b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.h @@ -0,0 +1,13 @@ +// +// VVSwiftClassCommenter.h +// VVDocumenter-Xcode +// +// Created by Li Jiantang on 16/06/2016. +// Copyright © 2016 OneV's Den. All rights reserved. +// + +#import "VVCommenter.h" + +@interface VVSwiftClassCommenter : VVBaseCommenter + +@end diff --git a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m new file mode 100644 index 0000000..27b38bf --- /dev/null +++ b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m @@ -0,0 +1,59 @@ +// +// VVSwiftClassCommenter.m +// VVDocumenter-Xcode +// +// Created by Li Jiantang on 16/06/2016. +// Copyright © 2016 OneV's Den. All rights reserved. +// + +#import "VVSwiftClassCommenter.h" +#import "NSString+VVTextGetter.h" +#import "VVTextResult.h" +#import "VVArgument.h" + +@interface VVSwiftClassCommenter() + +@property (nonatomic, strong) NSString *className; +@property (nonatomic, strong) NSArray *inheritances; + +@end + +@implementation VVSwiftClassCommenter + +-(void) captureClassName +{ + NSArray *groups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"^\\s*((.*\\s)?class\\s+)([^:]+):?(.*)\\{"]; + + self.className = [groups objectAtIndex:1]; + if ([groups count] > 3) { + self.className = [groups objectAtIndex:2]; + } + + self.inheritances = [[[groups lastObject] componentsSeparatedByString:@","] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *evaluatedString, NSDictionary * _Nullable bindings) { + + NSString *strippedString = [evaluatedString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + return strippedString.length > 0; + }]]; +} + +-(NSString *) document +{ + [self captureClassName]; + + NSMutableString *finalString = [NSMutableString new]; + [finalString appendFormat:@"/**\n%@class %@\n\n<#Description#>\n\n", self.indent, self.className]; + + if ([self.inheritances count] > 0) { + [finalString appendString:@"inherit from or conform to:\n"]; + for (NSString *inheritance in self.inheritances) { + [finalString appendFormat:@"%@: <#Description#>\n", [inheritance stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; + } + } + + [finalString appendFormat:@"\n %@*/", self.indent]; + + return finalString; +} + +@end diff --git a/VVDocumenter-Xcode/OCCategory/NSString+PDRegex/NSString+PDRegex.m b/VVDocumenter-Xcode/OCCategory/NSString+PDRegex/NSString+PDRegex.m index 1c67f72..60318c2 100755 --- a/VVDocumenter-Xcode/OCCategory/NSString+PDRegex/NSString+PDRegex.m +++ b/VVDocumenter-Xcode/OCCategory/NSString+PDRegex/NSString+PDRegex.m @@ -58,9 +58,14 @@ -(NSArray *) vv_stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex cas __block NSMutableArray *retVal = [NSMutableArray array]; [pattern enumerateMatchesInString:self options:0 range:NSMakeRange(0, [self length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { //Note, we only want to return the things in parens, so we're skipping index 0 intentionally - for (int i=1; i<[result numberOfRanges]; i++) { - NSString *matchedString=[self substringWithRange:[result rangeAtIndex:i]]; - [retVal addObject:matchedString]; + if ([result numberOfRanges] > 1) { + for (int i=1; i<[result numberOfRanges]; i++) { + NSRange range = [result rangeAtIndex:i]; + if (range.location != NSNotFound) { + NSString *matchedString=[self substringWithRange:range]; + [retVal addObject:matchedString]; + } + } } }]; return retVal; diff --git a/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.h b/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.h index b86d460..5bdd13b 100755 --- a/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.h +++ b/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.h @@ -38,6 +38,7 @@ -(BOOL) vv_isStruct; -(BOOL) vv_isUnion; -(BOOL) vv_isComplieKeyword; +-(BOOL) vv_isSwiftClass; -(BOOL) vv_isSwiftFunction; -(BOOL) vv_isSwiftEnum; -(BOOL) vv_isSwiftProperty; diff --git a/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m b/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m index d3d1abc..e04270f 100755 --- a/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m +++ b/VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m @@ -92,6 +92,11 @@ -(BOOL) vv_isSwiftFunction return ![self vv_isObjCMethod] && ![self vv_isSwiftProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?(func\\s+)|(init|deinit|subscript)"]; } +-(BOOL) vv_isSwiftClass +{ + return ![self vv_isSwiftFunction] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?(class\\s+).*\\{"]; +} + -(BOOL) vv_isSwiftEnum { return ![self vv_isSwiftProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?enum\\s+"]; @@ -99,8 +104,8 @@ -(BOOL) vv_isSwiftEnum -(BOOL) vv_isSwiftProperty { - // Opt out the situation of `class func` - if ([self vv_matchesPatternRegexPattern:@"class func"]) { + // Opt out the situation of `class func` and `class` + if ([self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?(class\\s+).*\\{"]) { return NO; } diff --git a/VVDocumenter-Xcode/VVDocumenter.m b/VVDocumenter-Xcode/VVDocumenter.m index e54c834..ab8f605 100755 --- a/VVDocumenter-Xcode/VVDocumenter.m +++ b/VVDocumenter-Xcode/VVDocumenter.m @@ -90,6 +90,8 @@ -(NSString *) document commenter = [[VVStructCommenter alloc] initWithIndentString:baseIndent codeString:trimCode]; } else if ([trimCode vv_isObjCMethod]) { commenter = [[VVMethodCommenter alloc] initWithIndentString:baseIndent codeString:trimCode]; + } else if ([trimCode vv_isSwiftClass]) { + commenter = [[VVSwiftClassCommenter alloc] initWithIndentString:baseIndent codeString:trimCode]; } else if ([trimCode vv_isSwiftFunction]) { commenter = [[VVSwiftFunctionCommenter alloc] initWithIndentString:baseIndent codeString:trimCode]; } else if ([trimCode vv_isSwiftProperty]) { diff --git a/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist b/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist index f45dbba..cec42a9 100644 --- a/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist +++ b/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist @@ -71,19 +71,19 @@ * @param uploadCompletionBlock <#uploadCompletionBlock description#> */ - - source - -(void) createNewMediaset:(NSString *) collectionName withCompletionBlock: (void (^)(void)) completionBlock; - uniform - -(void)createNewMediaset:(NSString *)collectionName withCompletionBlock:(void(^)(void))completionBlock; - result - /** + + source + -(void) createNewMediaset:(NSString *) collectionName withCompletionBlock: (void (^)(void)) completionBlock; + uniform + -(void)createNewMediaset:(NSString *)collectionName withCompletionBlock:(void(^)(void))completionBlock; + result + /** * <#Description#> * * @param collectionName <#collectionName description#> * @param completionBlock <#completionBlock description#> */ - + vv_isCFunction @@ -429,13 +429,13 @@ SIAlertViewBackgroundStyleSolid, vv_isSwiftFunction - - source - func testParasType(var a: Int, let b: Int, inout c: Int, d: Int) { - uniform - func testParasType(var a: Int, let b: Int, inout c: Int, d: Int){ - result - /** + + source + func testParasType(var a: Int, let b: Int, inout c: Int, d: Int) { + uniform + func testParasType(var a: Int, let b: Int, inout c: Int, d: Int){ + result + /** <#Description#> - parameter a: <#a description#> @@ -443,7 +443,7 @@ SIAlertViewBackgroundStyleSolid, - parameter c: <#c description#> - parameter d: <#d description#> */ - + source func sayHello(personName: String) -> String { @@ -548,41 +548,41 @@ SIAlertViewBackgroundStyleSolid, - returns: <#return value description#> */ - - source - public subscript (key: KeyType) -> ValueType? { - uniform - public subscript(key: KeyType)-> ValueType? { - result - /** + + source + public subscript (key: KeyType) -> ValueType? { + uniform + public subscript(key: KeyType)-> ValueType? { + result + /** <#Description#> - parameter key: <#key description#> - returns: <#return value description#> */ - - - source - func getSomething(input:String?, success: (Int) -> Void, failure: (NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) { - uniform - func getSomething(input:String?, success:(Int)-> Void, failure:(NSHTTPURLResponse?, AnyObject?, NSError?)-> Void){ - result - /** + + + source + func getSomething(input:String?, success: (Int) -> Void, failure: (NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) { + uniform + func getSomething(input:String?, success:(Int)-> Void, failure:(NSHTTPURLResponse?, AnyObject?, NSError?)-> Void){ + result + /** <#Description#> - parameter input: <#input description#> - parameter success: <#success description#> - parameter failure: <#failure description#> */ - - - source - func methodCouldThrows(count: Int) throws -> Int { - uniform - func methodCouldThrows(count: Int)throws -> Int { - result - /** + + + source + func methodCouldThrows(count: Int) throws -> Int { + uniform + func methodCouldThrows(count: Int)throws -> Int { + result + /** <#Description#> - parameter count: <#count description#> @@ -591,26 +591,26 @@ SIAlertViewBackgroundStyleSolid, - returns: <#return value description#> */ - - - source - func methodCouldThrows() throws { - uniform - func methodCouldThrows()throws { - result - /** + + + source + func methodCouldThrows() throws { + uniform + func methodCouldThrows()throws { + result + /** <#Description#> - throws: <#throws value description#> */ - - - source - func methodCouldThrows(count: Int, name: String, f: (Int, String) throws -> Void) rethrows -> Int { - uniform - func methodCouldThrows(count: Int, name: String, f:(Int, String)throws -> Void)rethrows -> Int { - result - /** + + + source + func methodCouldThrows(count: Int, name: String, f: (Int, String) throws -> Void) rethrows -> Int { + uniform + func methodCouldThrows(count: Int, name: String, f:(Int, String)throws -> Void)rethrows -> Int { + result + /** <#Description#> - parameter count: <#count description#> @@ -621,35 +621,35 @@ SIAlertViewBackgroundStyleSolid, - returns: <#return value description#> */ - - - source - public class func amethod(count: Int) -> Int? { - uniform - public class func amethod(count: Int)-> Int? { - result - /** + + + source + public class func amethod(count: Int) -> Int? { + uniform + public class func amethod(count: Int)-> Int? { + result + /** <#Description#> - parameter count: <#count description#> - returns: <#return value description#> */ - - - source - func testTuple(aTuple: (first: String, second: String, third: String)) -> (first: String, second: String, third: String)? { - uniform - func testTuple(aTuple:(first: String, second: String, third: String))->(first: String, second: String, third: String)? { - result - /** + + + source + func testTuple(aTuple: (first: String, second: String, third: String)) -> (first: String, second: String, third: String)? { + uniform + func testTuple(aTuple:(first: String, second: String, third: String))->(first: String, second: String, third: String)? { + result + /** <#Description#> - parameter aTuple: <#aTuple description#> - returns: <#return value description#> */ - + vv_isSwiftEnum @@ -763,14 +763,49 @@ SIAlertViewBackgroundStyleSolid, result // MARK: - <#SomeDelegate#> - - source - private extension MyClass\n { - uniform - private extension MyClass\n { - result - // MARK: - <#Description#> - + + source + private extension MyClass\n { + uniform + private extension MyClass\n { + result + // MARK: - <#Description#> + + + vv_isSwiftClass + + + source + class MyClass: SomeDelegate { + uniform + class MyClass: SomeDelegate { + result + /** +class MyClass + +<#Description#> + +inherit from or conform to: +SomeDelegate: <#Description#> + + */ + + + source + public class MyClass: SomeDelegate { + uniform + public class MyClass: SomeDelegate { + result + /** +class MyClass + +<#Description#> + +inherit from or conform to: +SomeDelegate: <#Description#> + + */ + diff --git a/VVDocumenterTests/VVDocumenterTests.m b/VVDocumenterTests/VVDocumenterTests.m index 5019b0c..7af50a6 100755 --- a/VVDocumenterTests/VVDocumenterTests.m +++ b/VVDocumenterTests/VVDocumenterTests.m @@ -54,6 +54,7 @@ - (void)tearDown -(void) testDocument { + [self.testCaseDic enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSArray *cases, BOOL *stop) { [cases enumerateObjectsUsingBlock:^(NSDictionary *testDic, NSUInteger idx, BOOL *stop) { NSString *source = testDic[@"source"]; diff --git a/VVDocumenterTests/VVTestHelper.m b/VVDocumenterTests/VVTestHelper.m index 5212ee6..889aa44 100755 --- a/VVDocumenterTests/VVTestHelper.m +++ b/VVDocumenterTests/VVTestHelper.m @@ -207,7 +207,8 @@ +(NSArray *) arrayOfExceptCodeType:(NSString *)type @"vv_isSwiftFunction", @"vv_isSwiftEnum", @"vv_isSwiftProperty", - @"vv_isSwiftExtension"]; + @"vv_isSwiftExtension", + @"vv_isSwiftClass"]; } return [_typeStrings arrayByRemovingObject:type]; From 8d72ac8a15d9771b703d0084496b16f4828e3eb6 Mon Sep 17 00:00:00 2001 From: Li Jiantang Date: Fri, 17 Jun 2016 14:50:33 +0100 Subject: [PATCH 2/4] Disable inheritance info for swift class, add comments --- .../Commenter/VVSwiftClassCommenter.m | 50 +++++++++++++------ .../DocumenterTests/VVMethodTestsCode.plist | 25 ++++++---- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m index 27b38bf..98bf187 100644 --- a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m +++ b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m @@ -20,15 +20,26 @@ @interface VVSwiftClassCommenter() @implementation VVSwiftClassCommenter --(void) captureClassName +/** + * Capture class name from extracted regex groups + * + * @param groups regex groups + */ +-(void) captureClassNameFrom:(NSArray *)groups { - NSArray *groups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"^\\s*((.*\\s)?class\\s+)([^:]+):?(.*)\\{"]; - self.className = [groups objectAtIndex:1]; + // if there are additional annotations like `public`, `private`, `final` if ([groups count] > 3) { self.className = [groups objectAtIndex:2]; } - +} + +/** + * Capture inheritances from extracted regex groups + * + * @param groups regex groups + */ +-(void) captureInheritancesFrom:(NSArray *)groups { self.inheritances = [[[groups lastObject] componentsSeparatedByString:@","] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *evaluatedString, NSDictionary * _Nullable bindings) { NSString *strippedString = [evaluatedString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; @@ -37,23 +48,32 @@ -(void) captureClassName }]]; } --(NSString *) document -{ - [self captureClassName]; - - NSMutableString *finalString = [NSMutableString new]; - [finalString appendFormat:@"/**\n%@class %@\n\n<#Description#>\n\n", self.indent, self.className]; - +/** + * Append inheritance info string to comment string + * + * @param string comment string want to append to + */ +-(void) appendInheritanceStringTo:(NSMutableString *)string { if ([self.inheritances count] > 0) { - [finalString appendString:@"inherit from or conform to:\n"]; + [string appendString:@"inherits from or conforms to:\n"]; for (NSString *inheritance in self.inheritances) { - [finalString appendFormat:@"%@: <#Description#>\n", [inheritance stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; + [string appendFormat:@"%@: <#Description#>\n", [inheritance stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; } } +} + +// override super document function to change default comment behavior +-(NSString *) document +{ + NSArray *groups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"^\\s*((.*\\s)?class\\s+)([^:]+):?(.*)\\{"]; + + [self captureClassNameFrom:groups]; - [finalString appendFormat:@"\n %@*/", self.indent]; + NSMutableString *commentString = [NSMutableString new]; + [commentString appendFormat:@"/**\n%@@class %@\n\n@abstract <#Description#>\n", self.indent, self.className]; + [commentString appendFormat:@"\n %@*/", self.indent]; - return finalString; + return commentString; } @end diff --git a/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist b/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist index cec42a9..6989a69 100644 --- a/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist +++ b/VVDocumenterTests/DocumenterTests/VVMethodTestsCode.plist @@ -781,12 +781,9 @@ SIAlertViewBackgroundStyleSolid, class MyClass: SomeDelegate { result /** -class MyClass +@class MyClass -<#Description#> - -inherit from or conform to: -SomeDelegate: <#Description#> +@abstract <#Description#> */ @@ -797,12 +794,22 @@ SomeDelegate: <#Description#> public class MyClass: SomeDelegate { result /** -class MyClass +@class MyClass + +@abstract <#Description#> -<#Description#> + */ + + + source + public final class MyClass: SomeDelegate { + uniform + public final class MyClass: SomeDelegate { + result + /** +@class MyClass -inherit from or conform to: -SomeDelegate: <#Description#> +@abstract <#Description#> */ From 3e905b16ee936a80f39e9369ee24b0c95d32605a Mon Sep 17 00:00:00 2001 From: Li Jiantang Date: Fri, 17 Jun 2016 15:14:09 +0100 Subject: [PATCH 3/4] Change back NSPredicate predicateWithBlock default parameter --- VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m index 98bf187..5acf878 100644 --- a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m +++ b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m @@ -40,9 +40,9 @@ -(void) captureClassNameFrom:(NSArray *)groups * @param groups regex groups */ -(void) captureInheritancesFrom:(NSArray *)groups { - self.inheritances = [[[groups lastObject] componentsSeparatedByString:@","] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *evaluatedString, NSDictionary * _Nullable bindings) { + self.inheritances = [[[groups lastObject] componentsSeparatedByString:@","] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary * _Nullable bindings) { - NSString *strippedString = [evaluatedString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *strippedString = [[NSString stringWithFormat:@"%@", evaluatedObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; return strippedString.length > 0; }]]; From 6696b8435a46e84f32b02bd092cc5d57c08780ba Mon Sep 17 00:00:00 2001 From: Li Jiantang Date: Fri, 17 Jun 2016 15:31:42 +0100 Subject: [PATCH 4/4] Remove NSPredicate from VVSwiftClassCommenter --- .../Commenter/VVSwiftClassCommenter.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m index 5acf878..ecdacd0 100644 --- a/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m +++ b/VVDocumenter-Xcode/Commenter/VVSwiftClassCommenter.m @@ -40,12 +40,18 @@ -(void) captureClassNameFrom:(NSArray *)groups * @param groups regex groups */ -(void) captureInheritancesFrom:(NSArray *)groups { - self.inheritances = [[[groups lastObject] componentsSeparatedByString:@","] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary * _Nullable bindings) { - - NSString *strippedString = [[NSString stringWithFormat:@"%@", evaluatedObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - return strippedString.length > 0; - }]]; + + NSMutableArray *nonEmptyStrings = [NSMutableArray new]; + NSArray *potentialInheritances = [[groups lastObject] componentsSeparatedByString:@","]; + + for(NSString *string in potentialInheritances) { + NSString *strippedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (strippedString.length > 0) { + [nonEmptyStrings addObject:strippedString]; + } + } + + self.inheritances = [NSArray arrayWithArray:nonEmptyStrings]; } /**