├── DocumenterXcode.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── xcuserdata
│ │ ├── serhiilondar.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ │ └── serhiy_londar.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
├── xcshareddata
│ └── xcschemes
│ │ ├── DocumenterXcode.xcscheme
│ │ └── DocumenterXcodeSettings.xcscheme
└── xcuserdata
│ ├── serhii-londar.xcuserdatad
│ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ │ └── xcschememanagement.plist
│ ├── serhiilondar.xcuserdatad
│ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ │ ├── DocumenterXcode.xcscheme
│ │ ├── DocumenterXcodeExtension.xcscheme
│ │ ├── DocumenterXcodeRelese.xcscheme
│ │ └── xcschememanagement.plist
│ └── serhiy_londar.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ └── xcschememanagement.plist
├── DocumenterXcode
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── icon_128@1x.png
│ │ ├── icon_128@2x.png
│ │ ├── icon_16@1x.png
│ │ ├── icon_16@2x.png
│ │ ├── icon_256@1x.png
│ │ ├── icon_256@2x.png
│ │ ├── icon_32@1x.png
│ │ ├── icon_32@2x.png
│ │ ├── icon_512@1x.png
│ │ └── icon_512@2x.png
├── Documenter-Prefix.pch
├── DocumenterXcode.entitlements
├── Info.plist
├── Main.storyboard
├── Setting
│ ├── VVDSettingPanelController.h
│ ├── VVDSettingPanelController.m
│ ├── VVDocumenterSetting.h
│ └── VVDocumenterSetting.m
└── main.m
├── README.md
├── Screenshots
├── Documenter.gif
├── DocumenterSettings.png
└── Settings.png
└── VVDocumenter
├── Info.plist
├── SourceEditorCommand.h
├── SourceEditorCommand.m
├── SourceEditorExtension.h
├── SourceEditorExtension.m
├── VVDocumenter-Prefix.pch
├── VVDocumenter.entitlements
└── VVDocumenter
├── Commenter
├── VVArgument.h
├── VVArgument.m
├── VVBaseCommenter.h
├── VVBaseCommenter.m
├── VVCommenter.h
├── VVEnumCommenter.h
├── VVEnumCommenter.m
├── VVFunctionCommenter.h
├── VVFunctionCommenter.m
├── VVMacroCommenter.h
├── VVMacroCommenter.m
├── VVMethodCommenter.h
├── VVMethodCommenter.m
├── VVPropertyCommenter.h
├── VVPropertyCommenter.m
├── VVStructCommenter.h
├── VVStructCommenter.m
├── VVSwiftEnumCommenter.h
├── VVSwiftEnumCommenter.m
├── VVSwiftExtensionCommenter.h
├── VVSwiftExtensionCommenter.m
├── VVSwiftFunctionCommenter.h
├── VVSwiftFunctionCommenter.m
├── VVSwiftPropertyCommenter.h
├── VVSwiftPropertyCommenter.m
├── VVVariableCommenter.h
└── VVVariableCommenter.m
├── KeyboardHelper
├── VVKeyboardEventSender.h
└── VVKeyboardEventSender.m
├── OCCategory
├── NSString+PDRegex
│ ├── NSString+PDRegex.h
│ └── NSString+PDRegex.m
├── NSString+VVSyntax
│ ├── NSString+VVSyntax.h
│ └── NSString+VVSyntax.m
├── NSString+VVTextGetter
│ ├── NSString+VVTextGetter.h
│ └── NSString+VVTextGetter.m
├── NSTextView+VVTextGetter
│ ├── NSTextView+VVTextGetter.h
│ └── NSTextView+VVTextGetter.m
├── VVTextResult.h
└── VVTextResult.m
├── ProjectHelper
├── VVProject.h
├── VVProject.m
├── VVWorkspaceManager.h
└── VVWorkspaceManager.m
├── VVDocumenter.h
├── VVDocumenter.m
├── VVDocumenterManager.h
└── VVDocumenterManager.m
/DocumenterXcode.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/project.xcworkspace/xcuserdata/serhiilondar.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode.xcodeproj/project.xcworkspace/xcuserdata/serhiilondar.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/project.xcworkspace/xcuserdata/serhiy_londar.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode.xcodeproj/project.xcworkspace/xcuserdata/serhiy_londar.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcshareddata/xcschemes/DocumenterXcode.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
16 |
22 |
23 |
24 |
30 |
36 |
37 |
38 |
39 |
40 |
45 |
46 |
47 |
48 |
54 |
55 |
56 |
57 |
58 |
59 |
70 |
72 |
78 |
79 |
80 |
81 |
82 |
83 |
90 |
92 |
98 |
99 |
100 |
101 |
103 |
104 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcshareddata/xcschemes/DocumenterXcodeSettings.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhii-londar.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
20 |
21 |
22 |
24 |
36 |
37 |
38 |
40 |
52 |
53 |
54 |
56 |
68 |
69 |
70 |
72 |
84 |
85 |
86 |
88 |
100 |
101 |
102 |
104 |
116 |
117 |
118 |
120 |
132 |
133 |
134 |
136 |
148 |
149 |
150 |
152 |
164 |
165 |
166 |
168 |
180 |
181 |
182 |
184 |
196 |
197 |
198 |
200 |
212 |
213 |
214 |
216 |
228 |
229 |
230 |
232 |
244 |
245 |
246 |
247 |
248 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhii-londar.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Documenter.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | VVDocumenter.xcscheme
13 |
14 | orderHint
15 | 1
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiilondar.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
14 |
15 |
16 |
18 |
24 |
25 |
26 |
27 |
28 |
30 |
34 |
35 |
36 |
38 |
50 |
51 |
52 |
54 |
66 |
67 |
68 |
70 |
82 |
83 |
84 |
86 |
98 |
99 |
100 |
102 |
114 |
115 |
116 |
118 |
130 |
131 |
132 |
134 |
146 |
147 |
148 |
150 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiilondar.xcuserdatad/xcschemes/DocumenterXcode.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiilondar.xcuserdatad/xcschemes/DocumenterXcodeExtension.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
16 |
22 |
23 |
24 |
30 |
36 |
37 |
38 |
39 |
40 |
45 |
46 |
47 |
48 |
54 |
55 |
56 |
57 |
58 |
59 |
70 |
72 |
78 |
79 |
80 |
81 |
82 |
83 |
90 |
92 |
98 |
99 |
100 |
101 |
103 |
104 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiilondar.xcuserdatad/xcschemes/DocumenterXcodeRelese.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiilondar.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | DocumenterXcode.xcscheme
8 |
9 | orderHint
10 | 1
11 |
12 | DocumenterXcodeExtension.xcscheme
13 |
14 | orderHint
15 | 0
16 |
17 | DocumenterXcodeRelese.xcscheme
18 |
19 | orderHint
20 | 2
21 |
22 |
23 | SuppressBuildableAutocreation
24 |
25 | E8555A3A1FBC8D6C007C0870
26 |
27 | primary
28 |
29 |
30 | E8555AB31FBC8EC6007C0870
31 |
32 | primary
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiy_londar.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
20 |
21 |
22 |
24 |
36 |
37 |
38 |
40 |
52 |
53 |
54 |
56 |
68 |
69 |
70 |
72 |
84 |
85 |
86 |
88 |
100 |
101 |
102 |
104 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/DocumenterXcode.xcodeproj/xcuserdata/serhiy_londar.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | DocumenterXcode.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 1
11 |
12 | DocumenterXcodeSettings.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 0
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | E8555A3A1FBC8D6C007C0870
21 |
22 | primary
23 |
24 |
25 | E8555AB31FBC8EC6007C0870
26 |
27 | primary
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/DocumenterXcode/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Documenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import
10 | ///
11 | @interface AppDelegate : NSObject
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/DocumenterXcode/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Documenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
18 |
19 | }
20 |
21 | - (void)applicationWillTerminate:(NSNotification *)aNotification {
22 |
23 | }
24 |
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {"images":[{"idiom":"mac","size":"16x16","scale":"1x","filename":"icon_16@1x.png"},{"idiom":"mac","size":"16x16","scale":"2x","filename":"icon_16@2x.png"},{"idiom":"mac","size":"32x32","scale":"1x","filename":"icon_32@1x.png"},{"idiom":"mac","size":"32x32","scale":"2x","filename":"icon_32@2x.png"},{"idiom":"mac","size":"128x128","scale":"1x","filename":"icon_128@1x.png"},{"idiom":"mac","size":"128x128","scale":"2x","filename":"icon_128@2x.png"},{"idiom":"mac","size":"256x256","scale":"1x","filename":"icon_256@1x.png"},{"idiom":"mac","size":"256x256","scale":"2x","filename":"icon_256@2x.png"},{"idiom":"mac","size":"512x512","scale":"1x","filename":"icon_512@1x.png"},{"idiom":"mac","size":"512x512","scale":"2x","filename":"icon_512@2x.png"}],"info":{"version":1,"author":"xcode"}}
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_128@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_128@1x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_128@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_128@2x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_16@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_16@1x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_16@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_16@2x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_256@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_256@1x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_256@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_256@2x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_32@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_32@1x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_32@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_32@2x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_512@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_512@1x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_512@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/DocumenterXcode/Assets.xcassets/AppIcon.appiconset/icon_512@2x.png
--------------------------------------------------------------------------------
/DocumenterXcode/Documenter-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'VVDocumenter-Xcode' target in the 'VVDocumenter-Xcode' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #import "NSString+PDRegex.h"
8 | #endif
9 |
10 |
11 | //#define __DEBUG__ 1
12 | #ifdef __DEBUG__
13 | #define VVLog(...) NSLog(__VA_ARGS__)
14 | #else
15 | #define VVLog(...) do{} while(0)
16 | #endif
17 |
--------------------------------------------------------------------------------
/DocumenterXcode/DocumenterXcode.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.application-groups
8 |
9 | $(TeamIdentifierPrefix)
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/DocumenterXcode/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 0.3
21 | CFBundleVersion
22 | 1
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | Copyright © 2017 slon. All rights reserved.
27 | NSMainStoryboardFile
28 | Main
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/DocumenterXcode/Setting/VVDSettingPanelController.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVDSettingPanelWindowController.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-8-3.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVDSettingPanelController : NSViewController
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/DocumenterXcode/Setting/VVDSettingPanelController.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVDSettingPanelWindowController.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-8-3.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVDSettingPanelController.h"
28 | #import "VVDocumenterSetting.h"
29 |
30 | @interface VVDSettingPanelController ()
31 | @property (weak) IBOutlet NSButton *btnUseSpaces;
32 | @property (weak) IBOutlet NSTextField *tfSpaceCount;
33 | @property (weak) IBOutlet NSTextField *tfSpaceLabel;
34 |
35 | @property (weak) IBOutlet NSStepper *stepperCount;
36 |
37 | @property (weak) IBOutlet NSMatrix *mtxSinceOptions;
38 | @property (weak) IBOutlet NSMatrix *mtxPrefixOptions;
39 | @property (weak) IBOutlet NSButtonCell *btnPrefixWithWhitespace;
40 | @property (weak) IBOutlet NSButtonCell *btnPrefixWithStar;
41 | @property (weak) IBOutlet NSButtonCell *btnPrefixWithSlashes;
42 | @property (weak) IBOutlet NSButton *btnAddSinceToComment;
43 | @property (weak) IBOutlet NSButton *btnBriefDescription;
44 | @property (weak) IBOutlet NSButton *btnUseHeaderDoc;
45 | @property (weak) IBOutlet NSButton *btnBlankLinesBetweenSections;
46 | @property (weak) IBOutlet NSButton *btnAlightArgumentComments;
47 | @property (weak) IBOutlet NSButton *btnUseAuthorInformation;
48 | @property (weak) IBOutlet NSButton *btnUseDateInformation;
49 | @property (weak) IBOutlet NSTextField *tfAuthoInformation;
50 | @property (weak) IBOutlet NSTextField *tfDateInformaitonFormat;
51 | @property (weak) IBOutlet NSTextField *tfSinceVersion;
52 |
53 | @end
54 |
55 | @implementation VVDSettingPanelController
56 |
57 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
58 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
59 | if (self) {
60 | //custom initialization
61 | }
62 | return self;
63 | }
64 |
65 |
66 | - (void)viewDidLoad {
67 | [super viewDidLoad];
68 |
69 | // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
70 | self.btnUseSpaces.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] useSpaces];
71 |
72 | self.btnAddSinceToComment.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] addSinceToComments];
73 | self.mtxSinceOptions.enabled = [[VVDocumenterSetting defaultSetting] addSinceToComments];
74 | [self.mtxSinceOptions selectCellAtRow:(NSInteger)[[VVDocumenterSetting defaultSetting] sinceOption] column:0];
75 | self.tfSinceVersion.enabled = [[VVDocumenterSetting defaultSetting] addSinceToComments];
76 | self.tfSinceVersion.stringValue = [[VVDocumenterSetting defaultSetting] sinceVersion];
77 |
78 | self.btnBriefDescription.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] briefDescription];
79 | self.btnUseHeaderDoc.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] useHeaderDoc];
80 | self.btnBlankLinesBetweenSections.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] blankLinesBetweenSections];
81 | self.btnAlightArgumentComments.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] alignArgumentComments];
82 | self.btnUseAuthorInformation.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] useAuthorInformation];
83 | self.tfAuthoInformation.stringValue = [[VVDocumenterSetting defaultSetting] authorInformation];
84 | self.btnUseDateInformation.state = (NSCellStateValue)[[VVDocumenterSetting defaultSetting] useDateInformation];
85 | self.tfDateInformaitonFormat.stringValue = [[VVDocumenterSetting defaultSetting] dateInformationFormat];
86 |
87 | if ([[VVDocumenterSetting defaultSetting] prefixWithStar]) {
88 | [self.mtxPrefixOptions selectCell:self.btnPrefixWithStar];
89 | } else if ([[VVDocumenterSetting defaultSetting] prefixWithSlashes]) {
90 | [self.mtxPrefixOptions selectCell:self.btnPrefixWithSlashes];
91 | } else {
92 | [self.mtxPrefixOptions selectCell:self.btnPrefixWithWhitespace];
93 | }
94 |
95 | // Disable the slashes prefix option for HeaderDoc comments
96 | if (self.btnUseHeaderDoc.state == NSOnState) {
97 | self.btnPrefixWithSlashes.enabled = NO;
98 | }
99 |
100 | [self updateUseSpace:self.btnUseSpaces.state];
101 | [self syncSpaceCount];
102 |
103 | self.tfDateInformaitonFormat.delegate = self;
104 | self.tfAuthoInformation.delegate = self;
105 | self.tfSinceVersion.delegate = self;
106 | }
107 |
108 | - (IBAction)stepperPressed:(id)sender {
109 | [[VVDocumenterSetting defaultSetting] setSpaceCount:self.stepperCount.integerValue];
110 | [self syncSpaceCount];
111 | }
112 |
113 | - (IBAction)btnResetPressed:(id)sender {
114 | [[VVDocumenterSetting defaultSetting] setUseSpaces:YES];
115 | [[VVDocumenterSetting defaultSetting] setTriggerString:VVDDefaultTriggerString];
116 | [[VVDocumenterSetting defaultSetting] setSpaceCount:2];
117 | [[VVDocumenterSetting defaultSetting] setPrefixWithStar:YES];
118 | [[VVDocumenterSetting defaultSetting] setPrefixWithSlashes:NO];
119 | [[VVDocumenterSetting defaultSetting] setAddSinceToComments:NO];
120 | [[VVDocumenterSetting defaultSetting] setSinceVersion:@""];
121 | [[VVDocumenterSetting defaultSetting] setBriefDescription:NO];
122 | [[VVDocumenterSetting defaultSetting] setUseHeaderDoc:NO];
123 | [[VVDocumenterSetting defaultSetting] setBlankLinesBetweenSections:YES];
124 | [[VVDocumenterSetting defaultSetting] setAlignArgumentComments:YES];
125 | [[VVDocumenterSetting defaultSetting] setUseAuthorInformation:NO];
126 | [[VVDocumenterSetting defaultSetting] setAuthorInformation:VVDDefaultAuthorString];
127 | [[VVDocumenterSetting defaultSetting] setUseDateInformation:NO];
128 | [[VVDocumenterSetting defaultSetting] setDateInformationFormat:VVDDefaultDateInfomationFormat];
129 |
130 | self.btnUseSpaces.state = NSOnState;
131 | [self updateUseSpace:self.btnUseSpaces.state];
132 | self.btnPrefixWithWhitespace.state = NSOffState;
133 | self.btnPrefixWithStar.state = NSOnState;
134 | self.btnPrefixWithSlashes.state = NSOffState;
135 | self.btnAddSinceToComment.state = NSOffState;
136 | self.tfSinceVersion.enabled = NO;
137 | self.mtxSinceOptions.enabled = NO;
138 | self.btnBriefDescription.state = NSOffState;
139 | self.btnUseHeaderDoc.state = NSOffState;
140 | self.btnBlankLinesBetweenSections.state = NSOnState;
141 | self.btnAlightArgumentComments.state = NSOnState;
142 | self.btnUseAuthorInformation.state = NSOffState;
143 | self.tfAuthoInformation.stringValue = VVDDefaultAuthorString;
144 | self.btnUseDateInformation.state = NSOffState;
145 | self.tfDateInformaitonFormat.stringValue = VVDDefaultDateInfomationFormat;
146 |
147 | self.btnPrefixWithSlashes.enabled = YES;
148 |
149 | [self syncSpaceCount];
150 |
151 | }
152 |
153 | - (IBAction)mtxSinceOptionPressed:(id)sender {
154 | VVDSinceOption option = self.mtxSinceOptions.selectedRow;
155 | [[VVDocumenterSetting defaultSetting] setSinceOption:option];
156 | }
157 |
158 | - (IBAction)btnUseSpacesPressed:(id)sender {
159 | [[VVDocumenterSetting defaultSetting] setUseSpaces:self.btnUseSpaces.state];
160 | [self updateUseSpace:self.btnUseSpaces.state];
161 | }
162 |
163 | - (IBAction)mtxPrefixSettingPressed:(id)sender {
164 | id selectedCell = self.mtxPrefixOptions.selectedCell;
165 |
166 | [[VVDocumenterSetting defaultSetting] setPrefixWithStar:[selectedCell isEqual:self.btnPrefixWithStar]];
167 | [[VVDocumenterSetting defaultSetting] setPrefixWithSlashes:[selectedCell isEqual:self.btnPrefixWithSlashes]];
168 | }
169 |
170 | - (IBAction)btnAddSinceToCommentsPressed:(id)sender {
171 | BOOL enableSince = self.btnAddSinceToComment.state;
172 | [[VVDocumenterSetting defaultSetting] setAddSinceToComments:enableSince];
173 | self.tfSinceVersion.enabled = enableSince;
174 | self.mtxSinceOptions.enabled = enableSince;
175 | }
176 |
177 | - (IBAction)btnBriefDescriptionPressed:(id)sender {
178 | [[VVDocumenterSetting defaultSetting] setBriefDescription:self.btnBriefDescription.state];
179 | }
180 |
181 | - (IBAction)btnUseAuthorInformationPressed:(id)sender {
182 | [[VVDocumenterSetting defaultSetting] setUseAuthorInformation:self.btnUseAuthorInformation.state];
183 | }
184 |
185 | - (IBAction)btnUseDateInformationPressed:(id)sender {
186 | [[VVDocumenterSetting defaultSetting] setUseDateInformation:self.btnUseDateInformation.state];
187 | }
188 |
189 | -(void) syncSpaceCount
190 | {
191 | NSInteger spaceCount = [[VVDocumenterSetting defaultSetting] spaceCount];
192 | [self.tfSpaceCount setIntegerValue:spaceCount];
193 | [self.stepperCount setIntegerValue:spaceCount];
194 | }
195 |
196 | -(void) updateUseSpace:(BOOL)useSpace
197 | {
198 | [self.tfSpaceCount setEnabled:useSpace];
199 | [self.stepperCount setEnabled:useSpace];
200 | self.tfSpaceLabel.textColor = useSpace ? [NSColor blackColor] : [NSColor grayColor];
201 | }
202 |
203 | - (void)controlTextDidChange:(NSNotification *)notification {
204 | if([notification object] == self.tfAuthoInformation) {
205 | [[VVDocumenterSetting defaultSetting] setAuthorInformation:self.tfAuthoInformation.stringValue];
206 | }
207 | if([notification object] == self.tfDateInformaitonFormat) {
208 | [[VVDocumenterSetting defaultSetting] setDateInformationFormat:self.tfDateInformaitonFormat.stringValue];
209 | }
210 | if ([notification object] == self.tfSinceVersion) {
211 | [[VVDocumenterSetting defaultSetting] setSinceVersion:self.tfSinceVersion.stringValue];
212 | }
213 | }
214 |
215 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor {
216 | return YES;
217 | }
218 |
219 | - (IBAction)useHeaderDoc:(id)sender {
220 | [[VVDocumenterSetting defaultSetting] setUseHeaderDoc:self.btnUseHeaderDoc.state];
221 |
222 | if (self.btnUseHeaderDoc.state == NSOnState) {
223 | self.btnPrefixWithSlashes.enabled = NO;
224 |
225 | // If the slashes option was selected, change to the default stars
226 | if ([self.mtxPrefixOptions.selectedCell isEqual:self.btnPrefixWithSlashes]) {
227 | [self.mtxPrefixOptions selectCell:self.btnPrefixWithStar];
228 |
229 | // Update the settings in addition to the display
230 | [self.mtxPrefixOptions sendAction];
231 | }
232 | } else {
233 | self.btnPrefixWithSlashes.enabled = YES;
234 | }
235 | }
236 | - (IBAction)blankLinesBetweenSections:(id)sender {
237 | [[VVDocumenterSetting defaultSetting] setBlankLinesBetweenSections:self.btnBlankLinesBetweenSections.state];
238 | }
239 |
240 | - (IBAction)alignArgumentComments:(id)sender {
241 | [[VVDocumenterSetting defaultSetting] setAlignArgumentComments:self.btnAlightArgumentComments.state];
242 | }
243 |
244 | @end
245 |
--------------------------------------------------------------------------------
/DocumenterXcode/Setting/VVDocumenterSetting.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenterSetting.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-8-3.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | typedef NS_ENUM(NSInteger, VVDSinceOption) {
30 | VVDSinceOptionPlaceholder,
31 | VVDSinceOptionProjectVersion,
32 | VVDSinceOptionSpecificVersion,
33 | };
34 |
35 | extern NSString *const VVDDefaultTriggerString;
36 | extern NSString *const VVDDefaultAuthorString;
37 | extern NSString *const VVDDefaultDateInfomationFormat;
38 |
39 | @interface VVDocumenterSetting : NSObject
40 | + (VVDocumenterSetting *)defaultSetting;
41 |
42 | @property (readonly) NSInteger keyVCode;
43 | @property BOOL useSpaces;
44 | @property NSInteger spaceCount;
45 | @property NSString *triggerString;
46 | @property VVDSinceOption sinceOption;
47 | @property BOOL prefixWithStar;
48 | @property BOOL prefixWithSlashes;
49 | @property BOOL addSinceToComments;
50 | @property NSString *sinceVersion;
51 | @property BOOL briefDescription;
52 | @property BOOL useHeaderDoc;
53 | @property BOOL blankLinesBetweenSections;
54 | @property BOOL alignArgumentComments;
55 | @property BOOL useAuthorInformation;
56 | @property NSString *authorInformation;
57 | @property BOOL useDateInformation;
58 | @property NSString *dateInformationFormat;
59 | @property (readonly) NSString *spacesString;
60 | @end
61 |
--------------------------------------------------------------------------------
/DocumenterXcode/Setting/VVDocumenterSetting.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenterSetting.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-8-3.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVDocumenterSetting.h"
28 | #import
29 |
30 | NSString *const VVDDefaultTriggerString = @"///";
31 | NSString *const VVDDefaultAuthorString = @"";
32 | NSString *const VVDDefaultDateInfomationFormat = @"YY-MM-dd HH:MM:ss";
33 |
34 | NSString *const kVVDUseSpaces = @"com.onevcat.VVDocumenter.useSpaces";
35 | NSString *const kVVDSpaceCount = @"com.onevcat.VVDocumenter.spaceCount";
36 | NSString *const kVVDTriggerString = @"com.onevcat.VVDocumenter.triggerString";
37 | NSString *const kVVDPrefixWithStar = @"com.onevcat.VVDocumenter.prefixWithStar";
38 | NSString *const kVVDPrefixWithSlashes = @"com.onevcat.VVDocumenter.prefixWithSlashes";
39 | NSString *const kVVDAddSinceToComments = @"com.onevcat.VVDocumenter.addSinceToComments";
40 | NSString *const kVVDSinceVersion = @"com.onevcat.VVDocumenter.sinceVersion";
41 | NSString *const kVVDSinceOption = @"com.onevcat.VVDocumenter.sinceOption";
42 | NSString *const kVVDBriefDescription = @"com.onevcat.VVDocumenter.briefDescription";
43 | NSString *const kVVDUserHeaderDoc = @"com.onevcat.VVDocumenter.useHeaderDoc";
44 | NSString *const kVVDNoBlankLinesBetweenFields = @"com.onevcat.VVDocumenter.noBlankLinesBetweenFields";
45 | NSString *const kVVDNoArgumentPadding = @"com.onevcat.VVDocumenter.noArgumentPadding";
46 | NSString *const kVVDUseAuthorInformation = @"com.onevcat.VVDocumenter.useAuthorInformation";
47 | NSString *const kVVDAuthorInfomation = @"com.onevcat.VVDocumenter.authorInfomation";
48 | NSString *const kVVDUseDateInformation = @"com.onevcat.VVDocumenter.useDateInformation";
49 | NSString *const kVVDDateInformationFormat = @"com.onevcat.VVDocumenter.dateInformationFomat";
50 |
51 |
52 | @implementation VVDocumenterSetting {
53 | NSUserDefaults *myDefaults;
54 | }
55 |
56 | - (instancetype)init
57 | {
58 | self = [super init];
59 | if (self) {
60 | myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"22AFPHX3AU.com.slon.Documenter"];
61 |
62 | NSDictionary *defaults = @{kVVDPrefixWithStar: @YES,
63 | kVVDUseSpaces: @YES,
64 | kVVDAuthorInfomation: @""
65 | };
66 | [myDefaults registerDefaults:defaults];
67 | [myDefaults synchronize];
68 | }
69 | return self;
70 | }
71 |
72 | + (VVDocumenterSetting *)defaultSetting
73 | {
74 | static dispatch_once_t once;
75 | static VVDocumenterSetting *defaultSetting;
76 | dispatch_once(&once, ^ {
77 | defaultSetting = [[VVDocumenterSetting alloc] init];
78 | });
79 | return defaultSetting;
80 | }
81 |
82 | -(BOOL) useSpaces
83 | {
84 | return [myDefaults boolForKey:kVVDUseSpaces];
85 | }
86 |
87 | -(void) setUseSpaces:(BOOL)useSpace
88 | {
89 | [myDefaults setBool:useSpace forKey:kVVDUseSpaces];
90 | [myDefaults synchronize];
91 | }
92 |
93 | -(NSInteger) keyVCode
94 | {
95 | TISInputSourceRef inputSource = TISCopyCurrentKeyboardLayoutInputSource();
96 | NSString *layoutID = (__bridge NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);
97 | CFRelease(inputSource);
98 |
99 | // Possible dvorak layout SourceIDs:
100 | // com.apple.keylayout.Dvorak (System Qwerty)
101 | // But exclude:
102 | // com.apple.keylayout.DVORAK-QWERTYCMD (System Qwerty ⌘)
103 | // org.unknown.keylayout.DvorakImproved-Qwerty⌘ (http://www.macupdate.com/app/mac/24137/dvorak-improved-keyboard-layout)
104 | if ([layoutID localizedCaseInsensitiveContainsString:@"dvorak"] && ![layoutID localizedCaseInsensitiveContainsString: @"qwerty"]) {
105 | return kVK_ANSI_Period;
106 | }
107 |
108 | // Possible workman layout SourceIDs (https://github.com/ojbucao/Workman):
109 | // org.sil.ukelele.keyboardlayout.workman.workman
110 | // org.sil.ukelele.keyboardlayout.workman.workmanextended
111 | // org.sil.ukelele.keyboardlayout.workman.workman-io
112 | // org.sil.ukelele.keyboardlayout.workman.workman-p
113 | // org.sil.ukelele.keyboardlayout.workman.workman-pextended
114 | // org.sil.ukelele.keyboardlayout.workman.workman-dead
115 | if ([layoutID localizedCaseInsensitiveContainsString:@"workman"]) {
116 | return kVK_ANSI_B;
117 | }
118 |
119 | return kVK_ANSI_V;
120 | }
121 |
122 |
123 | -(NSInteger) spaceCount
124 | {
125 | NSInteger count = [myDefaults integerForKey:kVVDSpaceCount];
126 | return (count <= 0) ? 2 : count;
127 | }
128 |
129 | -(void) setSpaceCount:(NSInteger)spaceCount
130 | {
131 | if (spaceCount < 1) {
132 | spaceCount = 1;
133 | } else if (spaceCount > 10) {
134 | spaceCount = 10;
135 | }
136 |
137 | [myDefaults setInteger:spaceCount forKey:kVVDSpaceCount];
138 | [myDefaults synchronize];
139 | }
140 |
141 | -(NSString *) triggerString
142 | {
143 | NSString *s = [myDefaults stringForKey:kVVDTriggerString];
144 | if (s.length == 0) {
145 | s = VVDDefaultTriggerString;
146 | }
147 | return s;
148 | }
149 |
150 | -(void) setTriggerString:(NSString *)triggerString
151 | {
152 | if (triggerString.length == 0) {
153 | [myDefaults setObject:VVDDefaultTriggerString forKey:kVVDTriggerString];
154 | } else {
155 | [myDefaults setObject:triggerString forKey:kVVDTriggerString];
156 | }
157 |
158 | [myDefaults synchronize];
159 | }
160 |
161 | -(VVDSinceOption) sinceOption
162 | {
163 | return (VVDSinceOption)[myDefaults integerForKey:kVVDSinceOption];
164 | }
165 |
166 | - (void)setSinceOption:(VVDSinceOption)sinceOption
167 | {
168 | [myDefaults setInteger:sinceOption forKey:kVVDSinceOption];
169 | [myDefaults synchronize];
170 | }
171 |
172 | -(BOOL) prefixWithStar
173 | {
174 | return [myDefaults boolForKey:kVVDPrefixWithStar];
175 | }
176 |
177 | -(void) setPrefixWithStar:(BOOL)prefix
178 | {
179 | [myDefaults setBool:prefix forKey:kVVDPrefixWithStar];
180 | [myDefaults synchronize];
181 | }
182 |
183 | -(BOOL) prefixWithSlashes
184 | {
185 | return [myDefaults boolForKey:kVVDPrefixWithSlashes];
186 | }
187 |
188 | -(void) setPrefixWithSlashes:(BOOL)prefix
189 | {
190 | [myDefaults setBool:prefix forKey:kVVDPrefixWithSlashes];
191 | [myDefaults synchronize];
192 | }
193 |
194 | -(BOOL) addSinceToComments
195 | {
196 | return [myDefaults boolForKey:kVVDAddSinceToComments];
197 | }
198 |
199 | -(void) setAddSinceToComments:(BOOL)add
200 | {
201 | [myDefaults setBool:add forKey:kVVDAddSinceToComments];
202 | [myDefaults synchronize];
203 | }
204 |
205 | - (NSString *)sinceVersion
206 | {
207 | NSString *sinceVersion = [myDefaults objectForKey:kVVDSinceVersion];
208 |
209 | if ( ! sinceVersion ) {
210 | sinceVersion = @"";
211 | }
212 |
213 | return sinceVersion;
214 | }
215 |
216 | - (void)setSinceVersion:(NSString *)sinceVersion
217 | {
218 | [myDefaults setObject:sinceVersion forKey:kVVDSinceVersion];
219 | [myDefaults synchronize];
220 | }
221 |
222 | -(BOOL) briefDescription
223 | {
224 | return [myDefaults boolForKey:kVVDBriefDescription];
225 | }
226 |
227 | -(void) setBriefDescription:(BOOL)brief
228 | {
229 | [myDefaults setBool:brief forKey:kVVDBriefDescription];
230 | [myDefaults synchronize];
231 | }
232 |
233 | -(BOOL) useHeaderDoc
234 | {
235 | return [myDefaults boolForKey:kVVDUserHeaderDoc];
236 | }
237 | -(void) setUseHeaderDoc:(BOOL)use
238 | {
239 | [myDefaults setBool:use forKey:kVVDUserHeaderDoc];
240 | [myDefaults synchronize];
241 | }
242 |
243 | -(BOOL) blankLinesBetweenSections
244 | {
245 | return ![myDefaults boolForKey:kVVDNoBlankLinesBetweenFields];
246 | }
247 | -(void) setBlankLinesBetweenSections:(BOOL)blankLinesBetweenFields
248 | {
249 | [myDefaults setBool:!blankLinesBetweenFields forKey:kVVDNoBlankLinesBetweenFields];
250 | [myDefaults synchronize];
251 | }
252 |
253 | -(BOOL) alignArgumentComments
254 | {
255 | return ![myDefaults boolForKey:kVVDNoArgumentPadding];
256 | }
257 | -(void) setAlignArgumentComments:(BOOL)alignArgumentComments
258 | {
259 | [myDefaults setBool:!alignArgumentComments forKey:kVVDNoArgumentPadding];
260 | [myDefaults synchronize];
261 | }
262 |
263 | -(BOOL)useAuthorInformation
264 | {
265 | return [myDefaults boolForKey:kVVDUseAuthorInformation];
266 | }
267 | -(void) setUseAuthorInformation:(BOOL)useAuthorInformation
268 | {
269 | [myDefaults setBool:useAuthorInformation forKey:kVVDUseAuthorInformation];
270 | [myDefaults synchronize];
271 | }
272 |
273 | -(NSString *)authorInformation {
274 | return [myDefaults objectForKey:kVVDAuthorInfomation];
275 | }
276 |
277 | -(void)setAuthorInformation:(NSString *)authorInformation {
278 | [myDefaults setObject:authorInformation forKey:kVVDAuthorInfomation];
279 | [myDefaults synchronize];
280 | }
281 |
282 | -(BOOL)useDateInformation
283 | {
284 | return [myDefaults boolForKey:kVVDUseDateInformation];
285 | }
286 | -(void) setUseDateInformation:(BOOL)useDateInformation
287 | {
288 | [myDefaults setBool:useDateInformation forKey:kVVDUseDateInformation];
289 | [myDefaults synchronize];
290 | }
291 |
292 | -(NSString *)dateInformationFormat {
293 | NSString *formatString = [myDefaults objectForKey:kVVDDateInformationFormat];
294 | if (formatString == nil || formatString.length <= 0) {
295 | formatString = VVDDefaultDateInfomationFormat;
296 | }
297 | return formatString;
298 | }
299 | -(void)setDateInformationFormat:(NSString *)dateInformationFormat {
300 | [myDefaults setObject:dateInformationFormat forKey:kVVDDateInformationFormat];
301 | [myDefaults synchronize];
302 | }
303 |
304 | -(NSString *) spacesString
305 | {
306 | if ([self useSpaces]) {
307 | return [@"" stringByPaddingToLength:[self spaceCount] withString:@" " startingAtIndex:0];
308 | } else {
309 | return @"\t";
310 | }
311 | }
312 |
313 | @end
314 |
--------------------------------------------------------------------------------
/DocumenterXcode/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Documenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, const char * argv[]) {
12 | return NSApplicationMain(argc, argv);
13 | }
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DocumenterXcode
2 | Xcode source editor extension which helps you write documentation comment easier, for both Objective-C and Swift.
3 |
4 | This project is an attempt to give a new life for [VVDocumenter-Xcode](https://github.com/onevcat/VVDocumenter-Xcode) for Xcode as source editor extension.
5 |
6 | This repository contains settings app and xcode source editor extension.
7 |
8 |
9 | ## What is this?
10 | Writing documentation is so important for developing, but it is really painful with Xcode. Starting from Xcode 9 apple added support for code documenting. This project is providing more flexible code documenting process. You can use various settings to write your documentation.
11 |
12 | ##
13 |
14 |
15 |
16 |
17 |
18 | ## How to install and use:
19 |
20 | ### Install
21 | You can build it by your own, just checkout this repo, open DocumenterXcode.xcodeproj and press run.
22 |
23 | Also you can Download app and extension from [releases](https://github.com/serhii-londar/DocumenterXcode/releases).
24 |
25 | Do not forget to enable Documenter Xcode in Settings:
26 |
27 |
28 |
29 |
30 | ### Usage
31 |
32 | To create documentation fou your method you need to set cursor about this methot and execute extension using : Editor -> DocumenterXcodeExtension -> Comment.
33 |
34 |
35 |
36 |
37 |
38 | ## TO DO
39 |
40 | - [ ] Fix issue with swift documenting.
41 | - [ ] Support swift 3.0 and more.
42 | - [ ] Rewrite to swift.
43 |
44 | ## License
45 |
46 | DocumenterXcode is published under MIT License. See the LICENSE file for more.
--------------------------------------------------------------------------------
/Screenshots/Documenter.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/Screenshots/Documenter.gif
--------------------------------------------------------------------------------
/Screenshots/DocumenterSettings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/Screenshots/DocumenterSettings.png
--------------------------------------------------------------------------------
/Screenshots/Settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/serhii-londar/DocumenterXcode/0e9bb11f46233b9b2f5b7f446d177b9dc2f84456/Screenshots/Settings.png
--------------------------------------------------------------------------------
/VVDocumenter/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | DocumenterXcode
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | XPC!
19 | CFBundleShortVersionString
20 | 0.3
21 | CFBundleVersion
22 | 1
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSExtension
26 |
27 | NSExtensionAttributes
28 |
29 | XCSourceEditorCommandDefinitions
30 |
31 |
32 | XCSourceEditorCommandClassName
33 | SourceEditorCommand
34 | XCSourceEditorCommandIdentifier
35 | $(PRODUCT_BUNDLE_IDENTIFIER).SourceEditorCommand
36 | XCSourceEditorCommandName
37 | Comment
38 |
39 |
40 | XCSourceEditorExtensionPrincipalClass
41 | SourceEditorExtension
42 |
43 | NSExtensionPointIdentifier
44 | com.apple.dt.Xcode.extension.source-editor
45 |
46 | NSHumanReadableCopyright
47 | Copyright © 2017 slon. All rights reserved.
48 |
49 |
50 |
--------------------------------------------------------------------------------
/VVDocumenter/SourceEditorCommand.h:
--------------------------------------------------------------------------------
1 | //
2 | // SourceEditorCommand.h
3 | // VVDocumenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SourceEditorCommand : NSObject
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/VVDocumenter/SourceEditorCommand.m:
--------------------------------------------------------------------------------
1 | //
2 | // SourceEditorCommand.m
3 | // VVDocumenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import "SourceEditorCommand.h"
10 | #import "VVDocumenter.h"
11 |
12 | @implementation SourceEditorCommand
13 |
14 | - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation
15 | completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler {
16 | XCSourceTextRange *textRange = invocation.buffer.selections.firstObject;
17 | NSInteger currentLine = textRange.start.line;
18 | if(invocation.buffer.lines.count - 1 == currentLine) {
19 | completionHandler([[NSError alloc] initWithDomain:@"Error Inserting documentation in last line." code:500 userInfo:@{}]);
20 | }
21 |
22 | NSInteger methodLine = currentLine + 1;
23 |
24 |
25 | NSMutableString *methodString = [self detectMethodStringFromLine:methodLine inBuffer:invocation.buffer];
26 | if(methodString == nil) {
27 | completionHandler(nil);
28 | return;
29 | }
30 | VVDocumenter* doc = [[VVDocumenter alloc] initWithCode:methodString];
31 | NSString *documentation = [doc document];
32 | if(documentation == nil){
33 | completionHandler(nil);
34 | return;
35 | }
36 |
37 | [self insertDocumentation:documentation buffer:invocation.buffer line:currentLine];
38 |
39 | completionHandler(nil);
40 | }
41 |
42 | - (void)insertDocumentation:(NSString *)documentation buffer:(XCSourceTextBuffer *)buffer line: (NSInteger)line {
43 | NSArray *documentationArray = [documentation componentsSeparatedByString:@"\n"];
44 | for (NSInteger i = 0; i < documentationArray.count; i++) {
45 | NSString *lineToInsert = documentationArray[documentationArray.count - i - 1];
46 | [buffer.lines insertObject:lineToInsert atIndex:line];
47 | }
48 | }
49 |
50 | - (NSMutableString *)detectMethodStringFromLine:(NSInteger)line inBuffer:(XCSourceTextBuffer *)buffer {
51 | NSMutableString *methodString = [buffer.lines[line] mutableCopy];
52 | NSInteger currentLine = line;
53 | if([methodString containsString:@"func"] == YES) {
54 | while ([methodString containsString: @"{"] == NO) {
55 | if(buffer.lines.count - 1 == currentLine) {
56 | return nil;
57 | }
58 | currentLine += 1;
59 | [methodString appendString:buffer.lines[currentLine]];
60 | }
61 | return methodString;
62 | } else if([methodString containsString:@"-"] || [methodString containsString:@"+"]) {
63 | while ([methodString containsString: @";"] == NO) {
64 | if(buffer.lines.count - 1 == currentLine) {
65 | return nil;
66 | }
67 | currentLine += 1;
68 | [methodString appendString:buffer.lines[currentLine]];
69 | }
70 | return methodString;
71 | } else {
72 | return nil;
73 | }
74 | }
75 |
76 | @end
77 |
--------------------------------------------------------------------------------
/VVDocumenter/SourceEditorExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // SourceEditorExtension.h
3 | // VVDocumenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SourceEditorExtension : NSObject
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/VVDocumenter/SourceEditorExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // SourceEditorExtension.m
3 | // VVDocumenter
4 | //
5 | // Created by Serhii Londar on 11/15/17.
6 | // Copyright © 2017 slon. All rights reserved.
7 | //
8 |
9 | #import "SourceEditorExtension.h"
10 |
11 | @implementation SourceEditorExtension
12 |
13 | - (instancetype)init {
14 | self = [super init];
15 | if (self) {
16 |
17 | }
18 | return self;
19 | }
20 |
21 | - (void)extensionDidFinishLaunching {
22 |
23 | }
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'VVDocumenter-Xcode' target in the 'VVDocumenter-Xcode' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #import "NSString+PDRegex.h"
8 | #endif
9 |
10 | //#define __DEBUG__ 1
11 | #ifdef __DEBUG__
12 | #define VVLog(...) NSLog(__VA_ARGS__)
13 | #else
14 | #define VVLog(...) do{} while(0)
15 | #endif
16 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.application-groups
8 |
9 | $(TeamIdentifierPrefix)
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVArgument.h:
--------------------------------------------------------------------------------
1 | //
2 | // Argument.h
3 | // VVDocumenter-Xcode
4 |
5 | //
6 | // Created by 王 巍 on 13-7-19.
7 | //
8 | // Copyright (c) 2015 Wei Wang
9 | //
10 | // Permission is hereby granted, free of charge, to any person obtaining a copy
11 | // of this software and associated documentation files (the "Software"), to deal
12 | // in the Software without restriction, including without limitation the rights
13 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | // copies of the Software, and to permit persons to whom the Software is
15 | // furnished to do so, subject to the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be included in
18 | // all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 | // THE SOFTWARE.
27 |
28 | #import
29 |
30 | @interface VVArgument : NSObject
31 | @property (nonatomic, copy) NSString *type;
32 | @property (nonatomic, copy) NSString *name;
33 | @end
34 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVArgument.m:
--------------------------------------------------------------------------------
1 | //
2 | // Argument.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-19.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVArgument.h"
28 | #import "NSString+PDRegex.h"
29 |
30 | @implementation VVArgument
31 |
32 | -(void)setType:(NSString *)type
33 | {
34 | if (type != _type) {
35 | _type = [[[type vv_stringByReplacingRegexPattern:@"&$" withString:@""]
36 | vv_stringByReplacingRegexPattern:@"\\s*\\*$" withString:@""]
37 | stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
38 | }
39 | }
40 |
41 | -(void)setName:(NSString *)name
42 | {
43 | if (name != _name) {
44 | _name = [[[[[[[name vv_stringByReplacingRegexPattern:@"\\(|\\)" withString:@""]
45 | vv_stringByReplacingRegexPattern:@"^&" withString:@""]
46 | vv_stringByReplacingRegexPattern:@"^\\*+" withString:@""]
47 | vv_stringByReplacingRegexPattern:@"\\[.*$" withString:@""]
48 | vv_stringByReplacingRegexPattern:@",$" withString:@""]
49 | vv_stringByReplacingRegexPattern:@";$" withString:@""]
50 | stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
51 | }
52 | }
53 |
54 | - (NSString *)description {
55 | return [NSString stringWithFormat:@"%@< type: %@, name: %@>", self.class, self.type, self.name];
56 | }
57 |
58 | - (BOOL)isEqual:(id)other {
59 | if (other == self) {
60 | return YES;
61 | }
62 | if ([other isKindOfClass:self.class]) {
63 | return [((VVArgument *)other).type isEqualToString:self.type]
64 | && [((VVArgument *)other).name isEqualToString:self.name];
65 | }
66 | return NO;
67 | }
68 |
69 | @end
70 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVBaseCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVBaseCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVBaseCommenter : NSObject
30 |
31 | @property (nonatomic, copy) NSString *indent;
32 | @property (nonatomic, copy) NSString *code;
33 | @property (nonatomic, strong) NSMutableArray *arguments;
34 | @property (nonatomic, assign) BOOL hasReturn;
35 | @property (nonatomic, assign) BOOL hasThrows;
36 |
37 | -(instancetype) initWithIndentString:(NSString *)indent codeString:(NSString *)code;
38 |
39 | -(NSString *) document;
40 |
41 | -(NSString *) documentForC;
42 | -(NSString *) documentForSwift;
43 | -(NSString *) documentForSwiftEnum;
44 |
45 | -(void) parseArgumentsInputArgs:(NSString *)rawArgsCode;
46 |
47 | -(BOOL) shouldComment;
48 |
49 | // Comment methods
50 | -(NSString *) startComment;
51 | -(NSString *) startCommentWithDescriptionTag:(NSString *)tag;
52 | -(NSString *) argumentsComment;
53 | -(NSString *) endComment;
54 | -(NSString *) returnComment;
55 | -(NSString *) sinceComment;
56 |
57 | @end
58 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-18.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #ifndef CommentTest_Commenter_h
28 | #define CommentTest_Commenter_h
29 |
30 | #import "VVBaseCommenter.h"
31 | #import "VVMethodCommenter.h"
32 | #import "VVPropertyCommenter.h"
33 | #import "VVFunctionCommenter.h"
34 | #import "VVMacroCommenter.h"
35 | #import "VVEnumCommenter.h"
36 | #import "VVStructCommenter.h"
37 | #import "VVVariableCommenter.h"
38 | #import "VVArgument.h"
39 | #import "VVSwiftFunctionCommenter.h"
40 | #import "VVSwiftEnumCommenter.h"
41 | #import "VVSwiftPropertyCommenter.h"
42 | #import "VVSwiftExtensionCommenter.h"
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVEnumCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVEnumCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVEnumCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVEnumCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVEnumCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVEnumCommenter.h"
28 | #import "NSString+PDRegex.h"
29 |
30 | @implementation VVEnumCommenter
31 |
32 | - (NSString *)document {
33 | //Regular comment documentation
34 | NSString *finalString = [NSString stringWithFormat:@"%@%@%@", [self startComment],
35 | [self sinceComment],
36 | [self endComment]];
37 |
38 | if (![finalString hasSuffix:@"\n"]) {
39 | finalString = [finalString stringByAppendingString:@"\n"];
40 | }
41 |
42 | // Grab everything from the start of the line to the opening brace, which
43 | // may be on a different line.
44 | NSString *enumDefinePattern = @"^\\s*(\\w+\\s+)?NS_(ENUM|OPTIONS)[\\s\\S]*?\\{";
45 |
46 | NSRegularExpression *enumDefineExpression = [NSRegularExpression regularExpressionWithPattern:enumDefinePattern options:0 error:nil];
47 | NSTextCheckingResult *enumDefineResult = [enumDefineExpression firstMatchInString:self.code options:0 range:NSMakeRange(0, self.code.length)];
48 |
49 | finalString = [finalString stringByAppendingString:[self.code substringWithRange:[enumDefineResult rangeAtIndex:0]]];
50 | finalString = [finalString substringToIndex:finalString.length - 1];
51 | finalString = [finalString stringByAppendingString:@" {\n"];
52 |
53 | NSString *endPattern = @"\\}\\s*;";
54 | NSString *enumPartsString = [[self.code vv_stringByReplacingRegexPattern:enumDefinePattern withString:@""]
55 | vv_stringByReplacingRegexPattern:endPattern withString:@""];
56 | NSArray *enumParts = [enumPartsString componentsSeparatedByString:@","];
57 |
58 | for (NSString *part in enumParts) {
59 | NSString *trimmedPart = [part stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
60 | //Only append when there is a enum define. (In case of the last comma, followed no define)
61 | if (trimmedPart.length != 0) {
62 | NSString *temp = [NSString stringWithFormat:@"%@%@%@", [self startCommentWithDescriptionTag:@""],
63 | [self sinceComment],
64 | [self endComment]];
65 |
66 | if ([temp hasSuffix:@"\n"]) {
67 | // comment has a newline suffix, so trimmedPart will go on
68 | // the next line
69 | temp = [temp stringByAppendingString:trimmedPart];
70 | } else {
71 | // comment does not have a newline suffix, so trimmedPart
72 | // needs to be moved to the next line
73 | temp = [temp stringByAppendingFormat:@"\n%@", trimmedPart];
74 | }
75 |
76 | if (part != [enumParts lastObject]) {
77 | temp = [temp stringByAppendingString:@",\n"];
78 | } else {
79 | // since trimmedPart was used there is no trailing newline
80 | temp = [temp stringByAppendingString:@"\n"];
81 | }
82 | finalString = [finalString stringByAppendingString:temp];
83 | }
84 | }
85 |
86 | return [finalString stringByAppendingString:@"};"];
87 | }
88 |
89 | @end
90 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVFunctionCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVFunctionCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVFunctionCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVFunctionCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVFunctionCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVFunctionCommenter.h"
28 | #import "VVArgument.h"
29 | #import "NSString+PDRegex.h"
30 |
31 | @implementation VVFunctionCommenter
32 |
33 | -(void) captureReturnType
34 | {
35 | NSArray *arr = [self.code componentsSeparatedByString:@"("];
36 | if (arr.count > 0 && (![arr[0] vv_matchesPatternRegexPattern:@"^\\s*void\\s*[^*]*\\s*\\w+$"] &&
37 | ![arr[0] vv_matchesPatternRegexPattern:@"^\\w+\\svoid"])) {
38 | self.hasReturn = YES;
39 | }
40 | }
41 |
42 | -(void) captureParameters
43 | {
44 | NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^].*?)\\)(?:__attribute__\\(\\(.*\\)\\))?"];
45 | if (braceGroups.count > 0) {
46 | [self parseArgumentsInputArgs:braceGroups[0]];
47 | }
48 |
49 | //Remove void arg in block
50 | NSArray *tempArray = [NSArray arrayWithArray:self.arguments];
51 | [tempArray enumerateObjectsUsingBlock:^(VVArgument *arg, NSUInteger idx, BOOL *stop) {
52 | if ([arg.type isEqualToString:@""] && [arg.name isEqualToString:@"void"]) {
53 | [self.arguments removeObject:arg];
54 | }
55 | }];
56 | }
57 |
58 | -(NSString *) document
59 | {
60 | [self captureReturnType];
61 | [self captureParameters];
62 |
63 | return [super documentForC];
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVMacroCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVMacroCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVMacroCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVMacroCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVMacroCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVMacroCommenter.h"
28 | #import "NSString+PDRegex.h"
29 |
30 | @implementation VVMacroCommenter
31 |
32 | -(void) captureReturnType
33 | {
34 | self.hasReturn = YES;
35 | }
36 |
37 | -(void) captureParameters
38 | {
39 | NSArray * braceGroups = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\(([^\\^][^\\(\\)]*)\\)"];
40 | if (braceGroups.count > 0) {
41 | [self parseArgumentsInputArgs:braceGroups[0]];
42 | }
43 | }
44 |
45 | -(NSString *) document
46 | {
47 | [self captureReturnType];
48 | [self captureParameters];
49 |
50 | return [super documentForC];
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVMethodCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVMethodCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVMethodCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVMethodCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVMethodCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVMethodCommenter.h"
28 | #import "NSString+PDRegex.h"
29 | #import "VVArgument.h"
30 |
31 | @implementation VVMethodCommenter
32 |
33 | -(void) captureReturnType
34 | {
35 | NSArray * matchedTypes = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"^\\s*[+-]\\s*\\(([^\\(\\)]*)\\)"];
36 |
37 | if (matchedTypes.count == 1) {
38 | if (![matchedTypes[0] vv_matchesPatternRegexPattern:@"^\\s*void\\s*[^*]*\\s*$"] &&
39 | ![matchedTypes[0] vv_matchesPatternRegexPattern:@"^\\s*IBAction\\s*$"]) {
40 | self.hasReturn = YES;
41 | }
42 | }
43 | }
44 |
45 | -(void) captureParameters
46 | {
47 | NSArray * matchedParams = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"\\:\\(([^:]+)\\)(\\w+)"];
48 | VVLog(@"matchedParams: %@",matchedParams);
49 | for (int i = 0; i < (int)matchedParams.count - 1; i = i + 2) {
50 | VVArgument *arg = [[VVArgument alloc] init];
51 | arg.type = [matchedParams[i] vv_stringByReplacingRegexPattern:@"[\\s*;.*]" withString:@""];
52 | arg.name = [matchedParams[i + 1] vv_stringByReplacingRegexPattern:@"[\\s*;.*]" withString:@""];
53 | [self.arguments addObject:arg];
54 | }
55 | }
56 |
57 | -(NSString *) document
58 | {
59 | [self captureReturnType];
60 | [self captureParameters];
61 |
62 | return [super documentForC];
63 | }
64 |
65 | @end
66 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVPropertyCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVPropertyCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVPropertyCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVPropertyCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVPropertyCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVPropertyCommenter.h"
28 |
29 | @implementation VVPropertyCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVStructCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVStructCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVStructCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVStructCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVStructCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVStructCommenter.h"
28 |
29 | @implementation VVStructCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftEnumCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftEnumCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-30.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVSwiftEnumCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftEnumCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftEnumCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-30.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVSwiftEnumCommenter.h"
28 | #import "VVArgument.h"
29 | #import "NSString+PDRegex.h"
30 |
31 | @implementation VVSwiftEnumCommenter
32 |
33 | -(void) captureParameters
34 | {
35 | NSString *normalizedCode = [self.code vv_stringByReplacingRegexPattern:@"\\s*\\n\\s*" withString:@"\n"];
36 | NSArray *lines = [normalizedCode componentsSeparatedByString:@"\n"];
37 | [lines enumerateObjectsUsingBlock:^(NSString *line, NSUInteger idx, BOOL *stop) {
38 | if ([line vv_matchesPatternRegexPattern:@"^case\\s+"]) {
39 | NSString * plainCase = [line vv_stringByReplacingRegexPattern:@"\\(.*?\\)" withString:@""];
40 | plainCase = [[plainCase vv_stringByReplacingRegexPattern:@"^case\\s+" withString:@""] vv_stringByReplacingRegexPattern:@"\\s+" withString:@""];
41 | NSArray *cases = [plainCase componentsSeparatedByString:@","];
42 | [cases enumerateObjectsUsingBlock:^(NSString *name, NSUInteger idx, BOOL *stop) {
43 | NSString *plainName = [name vv_stringByReplacingRegexPattern:@"=\\s*.*$" withString:@""];
44 | if ([plainName hasPrefix:@"."]) {
45 | return;
46 | }
47 | VVArgument *arg = [[VVArgument alloc] init];
48 | arg.name = plainName;
49 | [self.arguments addObject:arg];
50 | }];
51 | }
52 | }];
53 | }
54 |
55 | -(NSString *) document
56 | {
57 | [self captureParameters];
58 | return [super documentForSwiftEnum];
59 | }
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftExtensionCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftExtensionCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by WANG WEI on 2015/06/17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVSwiftExtensionCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftExtensionCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftExtensionCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by WANG WEI on 2015/06/17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVSwiftExtensionCommenter.h"
28 |
29 | @implementation VVSwiftExtensionCommenter
30 | -(NSString *) document
31 | {
32 | NSArray *component = [[self.code stringByReplacingOccurrencesOfString:@"{" withString:@""] componentsSeparatedByString:@":"];
33 | NSString *description = @"Description";
34 | if (component.count == 2) {
35 | description = [component.lastObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
36 | }
37 |
38 | return [NSString stringWithFormat:@"// MARK: - <#%@#>", description];
39 | }
40 | @end
41 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftFunctionCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftFunctionCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-30.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVSwiftFunctionCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftFunctionCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftFunctionCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-30.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVSwiftFunctionCommenter.h"
28 | #import "VVArgument.h"
29 | #import "NSString+VVTextGetter.h"
30 | #import "VVTextResult.h"
31 | #import "NSString+PDRegex.h"
32 |
33 | @implementation VVSwiftFunctionCommenter
34 | -(void) captureReturnType
35 | {
36 | VVTextResult *funcParenthesesResult = [self.code vv_textResultMatchPartWithPairOpenString:@"(" closeString:@")" currentLocation:0];
37 | NSString * funcSignatureWithoutParams = [self.code stringByReplacingCharactersInRange:funcParenthesesResult.range withString:@" "];
38 |
39 | if ([funcSignatureWithoutParams vv_matchesPatternRegexPattern:@"\\s+(throws|rethrows)\\s+"]) {
40 | self.hasThrows = YES;
41 | }
42 |
43 | if ([funcSignatureWithoutParams vv_matchesPatternRegexPattern:@"\\s*->\\s*\\(?(\\Void?|\\(\\s*\\))\\)?\\s*[{]"]) {
44 | self.hasReturn = NO;
45 | } else if ([funcSignatureWithoutParams vv_matchesPatternRegexPattern:@"s*->\\s*"]) {
46 | self.hasReturn = YES;
47 | } else if ([funcSignatureWithoutParams vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?(init|subscript)\\s*"]) {
48 | self.hasReturn = YES;
49 | } else {
50 | self.hasReturn = NO;
51 | }
52 | }
53 |
54 | -(void) captureParameters
55 | {
56 | VVTextResult *funcParenthesesResult = [self.code vv_textResultMatchPartWithPairOpenString:@"(" closeString:@")" currentLocation:0];
57 | NSArray * braceGroups = [funcParenthesesResult.string vv_stringsByExtractingGroupsUsingRegexPattern:@"\\((.*)\\)"];
58 | if (braceGroups.count > 0) {
59 | NSString *content = braceGroups[0];
60 | NSString *trimmed = [content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
61 | if (trimmed.length != 0) {
62 | [self parseSwiftArgumentsInputArgs:trimmed];
63 | }
64 | }
65 | }
66 |
67 | -(void) parseSwiftArgumentsInputArgs:(NSString *)rawArgsCode
68 | {
69 | [self.arguments removeAllObjects];
70 | if (rawArgsCode.length == 0) {
71 | return;
72 | }
73 |
74 | NSString *removedUnwantComma = [rawArgsCode vv_stringByReplacingRegexPattern:@"[{].*?[^}],.*?[)}]" withString:@""];
75 | NSString *removedUnwantParentheses = [removedUnwantComma copy];
76 |
77 | VVTextResult *parenthesesInParam = [removedUnwantComma vv_textResultMatchPartWithPairOpenString:@"(" closeString:@")" currentLocation:0];
78 | while (parenthesesInParam.string) {
79 | removedUnwantParentheses = [removedUnwantParentheses stringByReplacingOccurrencesOfString:parenthesesInParam.string withString:@""];
80 | parenthesesInParam = [removedUnwantParentheses vv_textResultMatchPartWithPairOpenString:@"(" closeString:@")" currentLocation:0];
81 | }
82 |
83 | NSArray *argumentStrings = [removedUnwantParentheses componentsSeparatedByString:@","];
84 | for (__strong NSString *argumentString in argumentStrings) {
85 | VVArgument *arg = [[VVArgument alloc] init];
86 | argumentString = [argumentString vv_stringByReplacingRegexPattern:@"=\\s*\\w*" withString:@""];
87 | argumentString = [argumentString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
88 | argumentString = [argumentString vv_stringByReplacingRegexPattern:@"\\s+" withString:@" "];
89 | NSMutableArray *tempArgs = [[argumentString componentsSeparatedByString:@":"] mutableCopy];
90 | if (tempArgs.count == 1) { //There is no ":", it is not a arg
91 | continue;
92 | }
93 |
94 | NSString *firstPart = [[tempArgs firstObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
95 | if ([firstPart rangeOfString:@" "].location != NSNotFound) {
96 | arg.name = [[[firstPart componentsSeparatedByString:@" "] lastObject] vv_stringByReplacingRegexPattern:@"#" withString:@""];
97 | } else {
98 | arg.name = [firstPart vv_stringByReplacingRegexPattern:@"#" withString:@""];
99 | }
100 |
101 | VVLog(@"arg name: %@", arg.name);
102 |
103 | [self.arguments addObject:arg];
104 | }
105 | }
106 |
107 | -(NSString *) document
108 | {
109 | [self captureReturnType];
110 | [self captureParameters];
111 |
112 | return [super documentForSwift];
113 | }
114 | @end
115 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftPropertyCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftPropertyCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVSwiftPropertyCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVSwiftPropertyCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVSwiftPropertyCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVSwiftPropertyCommenter.h"
28 |
29 | @implementation VVSwiftPropertyCommenter
30 |
31 | -(NSString *) document
32 | {
33 | return [NSString stringWithFormat:@"/// <#Description#>"];
34 | }
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVVariableCommenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVVariableCommenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVBaseCommenter.h"
28 |
29 | @interface VVVariableCommenter : VVBaseCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/Commenter/VVVariableCommenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVVariableCommenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE./
26 |
27 | #import "VVVariableCommenter.h"
28 |
29 | @implementation VVVariableCommenter
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/KeyboardHelper/VVKeyboardEventSender.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVKeyboardEventSender.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-26.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 | #import
29 |
30 |
31 | @interface VVKeyboardEventSender : NSObject
32 | -(void) beginKeyBoradEvents;
33 | -(void) sendKeyCode:(NSInteger)keyCode;
34 | -(void) sendKeyCode:(NSInteger)keyCode withModifierCommand:(BOOL)command
35 | alt:(BOOL)alt
36 | shift:(BOOL)shift
37 | control:(BOOL)control;
38 | -(void) sendKeyCode:(NSInteger)keyCode withModifier:(NSInteger)modifierMask;
39 | -(void) endKeyBoradEvents;
40 | @end
41 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/KeyboardHelper/VVKeyboardEventSender.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVKeyboardEventSender.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-26.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVKeyboardEventSender.h"
28 |
29 | @interface VVKeyboardEventSender()
30 | {
31 | CGEventSourceRef _source;
32 | CGEventTapLocation _location;
33 | }
34 | @end
35 |
36 | @implementation VVKeyboardEventSender
37 | -(void) beginKeyBoradEvents
38 | {
39 | _source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
40 | _location = kCGHIDEventTap;
41 | }
42 |
43 | -(void) sendKeyCode:(NSInteger)keyCode
44 | {
45 | [self sendKeyCode:keyCode withModifier:0];
46 | }
47 |
48 | -(void) sendKeyCode:(NSInteger)keyCode withModifierCommand:(BOOL)command
49 | alt:(BOOL)alt
50 | shift:(BOOL)shift
51 | control:(BOOL)control
52 | {
53 | NSInteger modifier = 0;
54 | if (command) {
55 | modifier = modifier ^ kCGEventFlagMaskCommand;
56 | }
57 | if (alt) {
58 | modifier = modifier ^ kCGEventFlagMaskAlternate;
59 | }
60 | if (shift) {
61 | modifier = modifier ^ kCGEventFlagMaskShift;
62 | }
63 | if (control) {
64 | modifier = modifier ^ kCGEventFlagMaskControl;
65 | }
66 |
67 | [self sendKeyCode:keyCode withModifier:modifier];
68 | }
69 |
70 | -(void) sendKeyCode:(NSInteger)keyCode withModifier:(NSInteger)modifierMask
71 | {
72 | NSAssert(_source != NULL, @"You should call -beginKeyBoradEvents before sending a key event");
73 | CGEventRef event;
74 | event = CGEventCreateKeyboardEvent(_source, keyCode, true);
75 | CGEventSetFlags(event, modifierMask);
76 | CGEventPost(_location, event);
77 | CFRelease(event);
78 |
79 | event = CGEventCreateKeyboardEvent(_source, keyCode, false);
80 | CGEventSetFlags(event, modifierMask);
81 | CGEventPost(_location, event);
82 | CFRelease(event);
83 | }
84 |
85 | -(void) endKeyBoradEvents
86 | {
87 | NSAssert(_source != NULL, @"You should call -beginKeyBoradEvents before end current keyborad event");
88 | CFRelease(_source);
89 | _source = nil;
90 | }
91 | @end
92 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+PDRegex/NSString+PDRegex.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+PDRegex.h
3 | // RegexOnNSString
4 | //
5 | // Created by Carl Brown on 10/3/11.
6 | // Copyright 2011 PDAgent, LLC. Released under MIT License.
7 | //
8 |
9 | #import
10 |
11 | @interface NSString (PDRegex)
12 |
13 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement;
14 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL) ignoreCase;
15 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine;
16 | -(NSArray *) vv_stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex;
17 | -(NSArray *) vv_stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine;
18 | -(BOOL) vv_matchesPatternRegexPattern:(NSString *)regex;
19 | -(BOOL) vv_matchesPatternRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+PDRegex/NSString+PDRegex.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+PDRegex.m
3 | // RegexOnNSString
4 | //
5 | // Created by Carl Brown on 10/3/11.
6 | // Copyright 2011 PDAgent, LLC. Released under MIT License.
7 | //
8 |
9 | #import "NSString+PDRegex.h"
10 |
11 | @implementation NSString (PDRegex)
12 |
13 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL)ignoreCase {
14 | return [self vv_stringByReplacingRegexPattern:regex withString:replacement caseInsensitive:ignoreCase treatAsOneLine:NO];
15 | }
16 |
17 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine {
18 |
19 | NSUInteger options=0;
20 | if (ignoreCase) {
21 | options = options | NSRegularExpressionCaseInsensitive;
22 | }
23 | if (assumeMultiLine) {
24 | options = options | NSRegularExpressionDotMatchesLineSeparators;
25 | }
26 |
27 | NSError *error=nil;
28 | NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
29 | if (error) {
30 | NSLog(@"Error creating Regex: %@",[error description]);
31 | return nil;
32 | }
33 |
34 | NSString *retVal= [pattern stringByReplacingMatchesInString:self options:0 range:NSMakeRange(0, [self length]) withTemplate:replacement];
35 | return retVal;
36 | }
37 |
38 | -(NSString *) vv_stringByReplacingRegexPattern:(NSString *)regex withString:(NSString *) replacement {
39 | return [self vv_stringByReplacingRegexPattern:regex withString:replacement caseInsensitive:NO treatAsOneLine:NO];
40 | }
41 |
42 | -(NSArray *) vv_stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine {
43 | NSUInteger options=0;
44 | if (ignoreCase) {
45 | options = options | NSRegularExpressionCaseInsensitive;
46 | }
47 | if (assumeMultiLine) {
48 | options = options | NSRegularExpressionDotMatchesLineSeparators;
49 | }
50 |
51 | NSError *error=nil;
52 | NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
53 | if (error) {
54 | NSLog(@"Error creating Regex: %@",[error description]);
55 | return nil;
56 | }
57 |
58 | __block NSMutableArray *retVal = [NSMutableArray array];
59 | [pattern enumerateMatchesInString:self options:0 range:NSMakeRange(0, [self length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
60 | //Note, we only want to return the things in parens, so we're skipping index 0 intentionally
61 | for (int i=1; i<[result numberOfRanges]; i++) {
62 | NSString *matchedString=[self substringWithRange:[result rangeAtIndex:i]];
63 | [retVal addObject:matchedString];
64 | }
65 | }];
66 | return retVal;
67 | }
68 |
69 | -(NSArray *) vv_stringsByExtractingGroupsUsingRegexPattern:(NSString *)regex {
70 | return [self vv_stringsByExtractingGroupsUsingRegexPattern:regex caseInsensitive:NO treatAsOneLine:NO];
71 | }
72 |
73 | -(BOOL) vv_matchesPatternRegexPattern:(NSString *)regex caseInsensitive:(BOOL) ignoreCase treatAsOneLine:(BOOL) assumeMultiLine {
74 | NSUInteger options=0;
75 | if (ignoreCase) {
76 | options = options | NSRegularExpressionCaseInsensitive;
77 | }
78 | if (assumeMultiLine) {
79 | options = options | NSRegularExpressionDotMatchesLineSeparators;
80 | }
81 |
82 | NSError *error=nil;
83 | NSRegularExpression *pattern = [NSRegularExpression regularExpressionWithPattern:regex options:options error:&error];
84 | if (error) {
85 | NSLog(@"Error creating Regex: %@",[error description]);
86 | return NO; //Can't possibly match an invalid Regex
87 | }
88 |
89 | return ([pattern numberOfMatchesInString:self options:0 range:NSMakeRange(0, [self length])] > 0);
90 | }
91 |
92 | -(BOOL) vv_matchesPatternRegexPattern:(NSString *)regex {
93 | return [self vv_matchesPatternRegexPattern:regex caseInsensitive:NO treatAsOneLine:NO];
94 | }
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+VVSyntax/NSString+VVSyntax.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+VVSyntax.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-18.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface NSString (VVSyntax)
30 | -(NSString *) vv_stringByConvertingToUniform;
31 | -(NSString *) vv_stringByTrimEndSpaces;
32 |
33 | -(BOOL) vv_isObjCMethod;
34 | -(BOOL) vv_isProperty;
35 | -(BOOL) vv_isCFunction;
36 | -(BOOL) vv_isMacro;
37 | -(BOOL) vv_isEnum;
38 | -(BOOL) vv_isStruct;
39 | -(BOOL) vv_isUnion;
40 | -(BOOL) vv_isComplieKeyword;
41 | -(BOOL) vv_isSwiftFunction;
42 | -(BOOL) vv_isSwiftEnum;
43 | -(BOOL) vv_isSwiftProperty;
44 | -(BOOL) vv_isSwiftExtension;
45 |
46 | @end
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+VVSyntax.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-18.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "NSString+VVSyntax.h"
28 | #import "NSString+PDRegex.h"
29 |
30 | @implementation NSString (VVSyntax)
31 | -(NSString *) vv_stringByConvertingToUniform
32 | {
33 | return [[[self vv_stringByReplacingRegexPattern:@"\\s*\\(" withString:@"("]
34 | vv_stringByReplacingRegexPattern:@"\\)\\s*" withString:@")"]
35 | vv_stringByReplacingRegexPattern:@"\\s*\n\\s*" withString:@" "];
36 | }
37 |
38 | -(NSString *) vv_stringByTrimEndSpaces
39 | {
40 | return [self vv_stringByReplacingRegexPattern:@"\\s*\n" withString:@"\n"];
41 | }
42 |
43 | -(BOOL) vv_isObjCMethod
44 | {
45 | return [self vv_matchesPatternRegexPattern:@"^\\s*[+-]"];
46 | }
47 |
48 | -(BOOL) vv_isCFunction
49 | {
50 | return ![self vv_isEnum] &&
51 | ![self vv_isMacro] &&
52 | ![self vv_isObjCMethod] &&
53 | ![self vv_isProperty] &&
54 | ![self vv_isComplieKeyword] &&
55 | ![self vv_isSwiftFunction] &&
56 | ![self vv_isSwiftEnum] &&
57 | ![self vv_isSwiftProperty] &&
58 | [self vv_matchesPatternRegexPattern:@".+\\s+.+\\("];
59 | }
60 |
61 | -(BOOL) vv_isProperty
62 | {
63 | return [self vv_matchesPatternRegexPattern:@"^\\s*\\@property"];
64 | }
65 |
66 | -(BOOL) vv_isMacro
67 | {
68 | return [self vv_matchesPatternRegexPattern:@"^\\s*\\#define"];
69 | }
70 |
71 | -(BOOL) vv_isStruct
72 | {
73 | return [self vv_matchesPatternRegexPattern:@"^\\s*(\\w+\\s)?struct.*\\{"];
74 | }
75 |
76 | -(BOOL) vv_isEnum
77 | {
78 | return [self vv_matchesPatternRegexPattern:@"^\\s*(\\w+\\s+)?NS_(ENUM|OPTIONS)\\b"];
79 | }
80 |
81 | -(BOOL) vv_isUnion
82 | {
83 | return [self vv_matchesPatternRegexPattern:@"^\\s*(\\w+\\s)?union.*\\{"];
84 | }
85 |
86 | -(BOOL) vv_isComplieKeyword
87 | {
88 | return ![self vv_isProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*\\@"];
89 | }
90 |
91 | -(BOOL) vv_isSwiftFunction
92 | {
93 | return ![self vv_isObjCMethod] && ![self vv_isSwiftProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?(func\\s+)|(init|deinit|subscript)"];
94 | }
95 |
96 | -(BOOL) vv_isSwiftEnum
97 | {
98 | return ![self vv_isSwiftProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?enum\\s+"];
99 | }
100 |
101 | -(BOOL) vv_isSwiftProperty
102 | {
103 | // Opt out the situation of `class func`
104 | if ([self vv_matchesPatternRegexPattern:@"class func"]) {
105 | return NO;
106 | }
107 |
108 | // `let`/`var` can be in swift func, but `(` appear before `let`/`var` only
109 | // happens when `private(set)` or `internal(set)` is used
110 | // typealias is considered to share the same comment as property.
111 | return [self vv_matchesPatternRegexPattern:@"^\\s*([^(]*?)(((\\s*let|var|typealias|class\\s*)\\s+)|(\\(\\s*set\\s*\\)))"];
112 | }
113 |
114 | -(BOOL) vv_isSwiftExtension
115 | {
116 | return [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?extension\\s+"];
117 | }
118 |
119 | @end
120 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+VVTextGetter/NSString+VVTextGetter.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+VVTextGetter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @class VVTextResult;
30 |
31 | @interface NSString (VVTextGetter)
32 |
33 | -(VVTextResult *) vv_textResultOfCurrentLineCurrentLocation:(NSInteger)location;
34 |
35 | -(VVTextResult *) vv_textResultOfPreviousLineCurrentLocation:(NSInteger)location;
36 |
37 | -(VVTextResult *) vv_textResultOfNextLineCurrentLocation:(NSInteger)location;
38 |
39 | -(VVTextResult *) vv_textResultUntilNextString:(NSString *)findString currentLocation:(NSInteger)location;
40 |
41 | -(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open
42 | closeString:(NSString *)close
43 | currentLocation:(NSInteger)location;
44 |
45 | -(VVTextResult *) vv_textResultMatchPartWithPairOpenString:(NSString *)open
46 | closeString:(NSString *)close
47 | currentLocation:(NSInteger)location;
48 |
49 | -(VVTextResult *) vv_textResultToEndOfFileCurrentLocation:(NSInteger)location;
50 | @end
51 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSString+VVTextGetter/NSString+VVTextGetter.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+VVTextGetter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "NSString+VVTextGetter.h"
28 | #import "VVTextResult.h"
29 |
30 | @implementation NSString (VVTextGetter)
31 |
32 | -(VVTextResult *) vv_textResultOfCurrentLineCurrentLocation:(NSInteger)location
33 | {
34 | NSInteger curseLocation = location;
35 | NSRange range = NSMakeRange(0, curseLocation);
36 | NSRange thisLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:NSBackwardsSearch range:range];
37 |
38 | NSString *line = nil;
39 | if (thisLineRange.location != NSNotFound) {
40 | NSRange lineRange = NSMakeRange(thisLineRange.location + 1, curseLocation - thisLineRange.location - 1);
41 | if (lineRange.location < [self length] && NSMaxRange(lineRange) < [self length]) {
42 | line = [self substringWithRange:lineRange];
43 | return [[VVTextResult alloc] initWithRange:lineRange string:line];
44 | } else {
45 | return nil;
46 | }
47 | } else {
48 | return nil;
49 | }
50 | }
51 |
52 |
53 | -(VVTextResult *) vv_textResultOfPreviousLineCurrentLocation:(NSInteger)location
54 | {
55 | NSInteger curseLocation = location;
56 | NSRange range = NSMakeRange(0, curseLocation);
57 | NSRange thisLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:NSBackwardsSearch range:range];
58 |
59 | NSString *line = nil;
60 | if (thisLineRange.location != NSNotFound) {
61 | range = NSMakeRange(0, thisLineRange.location);
62 | NSRange previousLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:NSBackwardsSearch range:range];
63 |
64 | if (previousLineRange.location != NSNotFound) {
65 | NSRange lineRange = NSMakeRange(previousLineRange.location + 1, thisLineRange.location - previousLineRange.location);
66 | if (lineRange.location < [self length] && NSMaxRange(lineRange) < [self length]) {
67 | line = [self substringWithRange:lineRange];
68 | return [[VVTextResult alloc] initWithRange:lineRange string:line];
69 | } else {
70 | return nil;
71 | }
72 | } else {
73 | return nil;
74 | }
75 | } else {
76 | return nil;
77 | }
78 | }
79 |
80 | -(VVTextResult *) vv_textResultOfNextLineCurrentLocation:(NSInteger)location
81 | {
82 | NSInteger curseLocation = location;
83 | NSRange range = NSMakeRange(curseLocation, self.length - curseLocation);
84 | NSRange thisLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:0 range:range];
85 |
86 | NSString *line = nil;
87 | if (thisLineRange.location != NSNotFound) {
88 | range = NSMakeRange(thisLineRange.location + 1, self.length - thisLineRange.location - 1);
89 | NSRange nextLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:0 range:range];
90 |
91 | if (nextLineRange.location != NSNotFound) {
92 | NSRange lineRange = NSMakeRange(thisLineRange.location + 1, NSMaxRange(nextLineRange) - NSMaxRange(thisLineRange));
93 | if (lineRange.location < [self length] && NSMaxRange(lineRange) < [self length]) {
94 | line = [self substringWithRange:lineRange];
95 | return [[VVTextResult alloc] initWithRange:lineRange string:line];
96 | } else {
97 | return nil;
98 | }
99 | } else {
100 | return nil;
101 | }
102 | } else {
103 | return nil;
104 | }
105 | }
106 |
107 | -(VVTextResult *) vv_textResultUntilNextString:(NSString *)findString currentLocation:(NSInteger)location
108 | {
109 | NSInteger curseLocation = location;
110 |
111 | NSRange range = NSMakeRange(curseLocation, self.length - curseLocation);
112 | NSRange nextLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:0 range:range];
113 | NSRange rangeToString = [self rangeOfString:findString options:0 range:range];
114 |
115 | NSString *line = nil;
116 | if (nextLineRange.location != NSNotFound && rangeToString.location != NSNotFound && nextLineRange.location <= rangeToString.location) {
117 | NSRange lineRange = NSMakeRange(nextLineRange.location + 1, rangeToString.location - nextLineRange.location);
118 | if (lineRange.location < [self length] && NSMaxRange(lineRange) <= [self length]) {
119 | line = [self substringWithRange:lineRange];
120 | return [[VVTextResult alloc] initWithRange:lineRange string:line];
121 | } else {
122 | return nil;
123 | }
124 | } else {
125 | return nil;
126 | }
127 | }
128 |
129 | -(VVTextResult *) vv_textResultMatchPartWithPairOpenString:(NSString *)open
130 | closeString:(NSString *)close
131 | currentLocation:(NSInteger)location
132 | {
133 | return [self textResultWithPairOpenString:open closeString:close currentLocation:location extractMatch:YES];
134 | }
135 |
136 | -(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open
137 | closeString:(NSString *)close
138 | currentLocation:(NSInteger)location
139 | {
140 | return [self textResultWithPairOpenString:open closeString:close currentLocation:location extractMatch:NO];
141 | }
142 |
143 | -(VVTextResult *) vv_textResultToEndOfFileCurrentLocation:(NSInteger)location
144 | {
145 | NSRange range = NSMakeRange(location, self.length - location);
146 | VVTextResult *result = [[VVTextResult alloc] initWithRange:range string:[self substringWithRange:range]];
147 | return result;
148 | }
149 |
150 | -(VVTextResult *) textResultWithPairOpenString:(NSString *)open
151 | closeString:(NSString *)close
152 | currentLocation:(NSInteger)location
153 | extractMatch:(BOOL)extract
154 | {
155 | // Find all content from current positon to the last paired scope. Useful when pairing `{}` or `()`
156 | NSInteger curseLocation = location;
157 |
158 | NSRange range = NSMakeRange(curseLocation, self.length - curseLocation);
159 |
160 | // searchRange will be updated to new range later, for search the next open/close token.
161 | NSRange searchRange = range;
162 | VVLog(@"Begin Search Range: %lu, %lu", (unsigned long)searchRange.location, (unsigned long)searchRange.length);
163 |
164 | NSInteger openCount = 0;
165 | NSInteger closeCount = 0;
166 |
167 | NSRange nextOpenRange = [self rangeOfString:open options:0 range:searchRange];
168 | NSRange nextCloseRange = [self rangeOfString:close options:0 range:searchRange];
169 |
170 | NSRange firstOpenRange = nextOpenRange;
171 |
172 | // Not even open. Early return
173 | if (nextOpenRange.location == NSNotFound || nextCloseRange.location == NSNotFound || nextCloseRange.location < nextOpenRange.location) {
174 | return nil;
175 | }
176 |
177 | openCount++;
178 |
179 | // Update the search range: from current token to the end.
180 | searchRange = NSMakeRange(nextOpenRange.location + 1, self.length - nextOpenRange.location - 1);
181 | VVLog(@"Update Search Range: %lu, %lu", (unsigned long)searchRange.location, (unsigned long)searchRange.length);
182 |
183 | // Try to find the scope by pairing open and close count
184 | NSRange targetRange = NSMakeRange(0,0);
185 | while (openCount != closeCount) {
186 | // Get next open and close token location
187 | nextOpenRange = [self rangeOfString:open options:0 range:searchRange];
188 | nextCloseRange = [self rangeOfString:close options:0 range:searchRange];
189 |
190 | // No new close token. This scope will not close.
191 | if (nextCloseRange.location == NSNotFound) {
192 | return nil;
193 | }
194 |
195 | if (nextOpenRange.location < nextCloseRange.location) {
196 | targetRange = nextOpenRange;
197 | openCount++;
198 | } else {
199 | targetRange = nextCloseRange;
200 | closeCount++;
201 | }
202 |
203 | VVLog(@"Open:%ld, Close:%ld",(long)openCount,(long)closeCount);
204 | // Update the search range: from current token to the end.
205 | searchRange = NSMakeRange(targetRange.location + 1, self.length - targetRange.location - 1);
206 | VVLog(@"Target Range: %lu, %lu",targetRange.location,targetRange.length);
207 | VVLog(@"Update Search Range: %lu, %lu", (unsigned long)searchRange.location, (unsigned long)searchRange.length);
208 | }
209 |
210 | NSRange resultRange;
211 | if (extract) {
212 | resultRange = NSMakeRange(firstOpenRange.location, targetRange.location - firstOpenRange.location + 1);
213 | } else {
214 | // Extract the code need to be documented. From next line to the matched scope end.
215 | NSRange nextLineRange = [self rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:0 range:range];
216 | resultRange = NSMakeRange(nextLineRange.location + 1, targetRange.location - nextLineRange.location);
217 | }
218 |
219 | if (resultRange.location < [self length] && NSMaxRange(resultRange) <= [self length]) {
220 | NSString *result = [self substringWithRange:resultRange];
221 | return [[VVTextResult alloc] initWithRange:resultRange string:result];
222 | } else {
223 | return nil;
224 | }
225 |
226 | }
227 | @end
228 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSTextView+VVTextGetter/NSTextView+VVTextGetter.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSTextView+VVTextGetter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @class VVTextResult;
30 |
31 | @interface NSTextView (VVTextGetter)
32 | -(NSInteger) vv_currentCurseLocation;
33 |
34 | -(VVTextResult *) vv_textResultOfCurrentLine;
35 |
36 | -(VVTextResult *) vv_textResultOfPreviousLine;
37 |
38 | -(VVTextResult *) vv_textResultOfNextLine;
39 |
40 | -(VVTextResult *) vv_textResultUntilNextString:(NSString *)findString;
41 |
42 | -(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open closeString:(NSString *)close;
43 |
44 | -(VVTextResult *) vv_textResultToEndOfFile;
45 | @end
46 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/NSTextView+VVTextGetter/NSTextView+VVTextGetter.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSTextView+VVTextGetter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "NSTextView+VVTextGetter.h"
28 | #import "VVTextResult.h"
29 | #import "NSString+VVTextGetter.h"
30 |
31 | @implementation NSTextView (VVTextGetter)
32 | -(NSInteger) vv_currentCurseLocation
33 | {
34 | return [[[self selectedRanges] objectAtIndex:0] rangeValue].location;
35 | }
36 |
37 | -(VVTextResult *) vv_textResultOfCurrentLine
38 | {
39 | return [self.textStorage.string vv_textResultOfCurrentLineCurrentLocation:[self vv_currentCurseLocation]];
40 | }
41 |
42 | -(VVTextResult *) vv_textResultOfPreviousLine
43 | {
44 | return [self.textStorage.string vv_textResultOfPreviousLineCurrentLocation:[self vv_currentCurseLocation]];
45 | }
46 |
47 | -(VVTextResult *) vv_textResultOfNextLine
48 | {
49 | return [self.textStorage.string vv_textResultOfNextLineCurrentLocation:[self vv_currentCurseLocation]];
50 | }
51 |
52 | -(VVTextResult *) vv_textResultUntilNextString:(NSString *)findString
53 | {
54 | return [self.textStorage.string vv_textResultUntilNextString:findString currentLocation:[self vv_currentCurseLocation]];
55 | }
56 |
57 | -(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open closeString:(NSString *)close
58 | {
59 | return [self.textStorage.string vv_textResultWithPairOpenString:open closeString:close currentLocation:[self vv_currentCurseLocation]];
60 | }
61 |
62 | -(VVTextResult *) vv_textResultToEndOfFile
63 | {
64 | return [self.textStorage.string vv_textResultToEndOfFileCurrentLocation:[self vv_currentCurseLocation]];
65 | }
66 |
67 | @end
68 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/VVTextResult.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVTextResult.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVTextResult : NSObject
30 |
31 | @property (nonatomic, assign) NSRange range;
32 | @property (nonatomic, copy) NSString *string;
33 |
34 | -(instancetype) initWithRange:(NSRange)aRange string:(NSString *)aString;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/OCCategory/VVTextResult.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVTextResult.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 14-7-31.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVTextResult.h"
28 |
29 | @implementation VVTextResult
30 |
31 | -(instancetype) initWithRange:(NSRange)aRange string:(NSString *)aString
32 |
33 | {
34 | self = [super init];
35 | if (self) {
36 | _range = aRange;
37 | _string = aString;
38 | }
39 | return self;
40 | }
41 |
42 | -(NSString *)description
43 | {
44 | return [NSString stringWithFormat:@"Location:%ld, Length:%ld, String:%@",self.range.location,self.range.length,self.string];
45 | }
46 |
47 | @end
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/ProjectHelper/VVProject.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVProject.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 夏天味道 on 15/6/25.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVProject : NSObject
30 |
31 | @property (nonatomic, copy) NSString *directoryPath;
32 |
33 | @property (nonatomic,copy,readonly) NSString *workspacePath;
34 |
35 | @property (nonatomic, copy) NSString *projectName;
36 |
37 | @property (nonatomic, copy) NSDictionary *infoDictionary;
38 |
39 | @property (nonatomic, copy) NSString *projectVersion;
40 |
41 | @property (nonatomic,copy) NSDictionary *pbxprojDictionary;
42 |
43 | @property (nonatomic,copy) NSString *organizeationName;
44 |
45 |
46 | + (instancetype)projectForKeyWindow;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/ProjectHelper/VVProject.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVProject.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 夏天味道 on 15/6/25.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVProject.h"
28 | #import "VVWorkspaceManager.h"
29 |
30 | @implementation VVProject
31 |
32 | + (instancetype)projectForKeyWindow
33 | {
34 | id workspace = [VVWorkspaceManager workspaceForKeyWindow];
35 |
36 | id contextManager = [workspace valueForKey:@"_runContextManager"];
37 |
38 | for (id scheme in[contextManager valueForKey:@"runContexts"]) {
39 | NSString *schemeName = [scheme valueForKey:@"name"];
40 | if (![schemeName hasPrefix:@"Pods-"]) {
41 | NSString *path = [VVWorkspaceManager directoryPathForWorkspace:workspace];
42 | return [[VVProject alloc] initWithName:schemeName path:path];
43 | }
44 | }
45 |
46 | return nil;
47 | }
48 |
49 | - (id)initWithName:(NSString *)name
50 | path:(NSString *)path
51 | {
52 | if (self = [self init]) {
53 | _projectName = name;
54 | _directoryPath = path;
55 |
56 |
57 | NSString *pbxprojPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xcodeproj/project.pbxproj",name]];
58 | _pbxprojDictionary = [NSDictionary dictionaryWithContentsOfFile:pbxprojPath];
59 |
60 |
61 |
62 | _organizeationName = [self getOrganizeationName];
63 | NSString *infoplistName = [self infoplistNameWithAtScheme:name];
64 |
65 | NSString *infoPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", infoplistName]];
66 |
67 |
68 | _infoDictionary = [NSDictionary dictionaryWithContentsOfFile:infoPath];
69 |
70 | _projectVersion = self.infoDictionary[@"CFBundleShortVersionString"];
71 | }
72 |
73 | return self;
74 | }
75 |
76 | -(NSString *)getOrganizeationName{
77 | NSDictionary *objects = [_pbxprojDictionary objectForKey:@"objects"];
78 | NSString *rootObjectId = [_pbxprojDictionary objectForKey:@"rootObject"];
79 |
80 | NSDictionary *pbxProjectDic = [objects objectForKey:rootObjectId];
81 | NSDictionary *attributes = [pbxProjectDic objectForKey:@"attributes"];
82 | NSString *organizeationName = [attributes objectForKey:@"ORGANIZATIONNAME"];
83 | return organizeationName;
84 | }
85 |
86 | -(NSString *)infoplistNameWithAtScheme:(NSString *)currentSchemeName{
87 | NSDictionary *objects = [_pbxprojDictionary objectForKey:@"objects"];
88 | NSString *rootObjectId = [_pbxprojDictionary objectForKey:@"rootObject"];
89 |
90 | NSDictionary *pbxProjectDic = [objects objectForKey:rootObjectId];
91 | NSArray *targetIds = [pbxProjectDic objectForKey:@"targets"];
92 | NSString *currentTargetId;
93 | for (NSString *targetId in targetIds) {
94 | NSDictionary *targetDic = [objects objectForKey:targetId];
95 | NSString *targetName = [targetDic objectForKey:@"name"];
96 | if ([targetName isEqualToString:currentSchemeName]) {
97 | currentTargetId = targetId;
98 | break;
99 | }
100 | }
101 | if (!currentTargetId) {
102 | currentTargetId = [targetIds firstObject];
103 | }
104 |
105 | NSDictionary *targetDic = [objects objectForKey:currentTargetId];
106 | NSString *buildConfigurationListId = [targetDic objectForKey:@"buildConfigurationList"];
107 |
108 | NSDictionary *buildConfigurationListDic = [objects objectForKey:buildConfigurationListId];
109 | NSArray *buildConfigurationIds = [buildConfigurationListDic objectForKey:@"buildConfigurations"];
110 |
111 | NSString *debugBuildConfigurationId;
112 | for (NSString *buildConfigurationId in buildConfigurationIds) {
113 | NSDictionary *buildConfigurationDic = [objects objectForKey:buildConfigurationId];
114 | NSString *name = [buildConfigurationDic objectForKey:@"name"];
115 | if ([name isEqualToString:@"Debug"]) {
116 | debugBuildConfigurationId = buildConfigurationId;
117 | break;
118 | }
119 | }
120 | if (!debugBuildConfigurationId) {
121 | debugBuildConfigurationId = [buildConfigurationIds firstObject];
122 | }
123 |
124 | NSDictionary *buildConfigurationDic = [objects objectForKey:debugBuildConfigurationId];
125 | NSDictionary *buildSettings = [buildConfigurationDic objectForKey:@"buildSettings"];
126 | NSString *infoplistName = [buildSettings objectForKey:@"INFOPLIST_FILE"];
127 | return infoplistName;
128 | }
129 |
130 | @end
131 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/ProjectHelper/VVWorkspaceManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVWorkspaceManager.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 夏天味道 on 15/6/25.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVWorkspaceManager : NSObject
30 |
31 | + (id)workspaceForKeyWindow;
32 |
33 | + (NSString *)currentWorkspaceDirectoryPath;
34 | + (NSString *)directoryPathForWorkspace:(id)workspace;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/ProjectHelper/VVWorkspaceManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVWorkspaceManager.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 夏天味道 on 15/6/25.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 | #import "VVWorkspaceManager.h"
29 |
30 | @implementation VVWorkspaceManager
31 |
32 | + (NSString *)currentWorkspaceDirectoryPath
33 | {
34 | return [self directoryPathForWorkspace:[self workspaceForKeyWindow]];
35 | }
36 |
37 | + (NSString *)directoryPathForWorkspace:(id)workspace
38 | {
39 | NSString *workspacePath = [[workspace valueForKey:@"representingFilePath"] valueForKey:@"_pathString"];
40 | return [workspacePath stringByDeletingLastPathComponent];
41 | }
42 |
43 | #pragma mark - Private
44 |
45 | + (id)workspaceForKeyWindow
46 | {
47 | return [self workspaceForWindow:[NSApp mainWindow]];
48 | }
49 |
50 | + (id)workspaceForWindow:(NSWindow *)window
51 | {
52 | NSArray *workspaceWindowControllers = [NSClassFromString(@"IDEWorkspaceWindowController") valueForKey:@"workspaceWindowControllers"];
53 |
54 | for (id controller in workspaceWindowControllers) {
55 | if ([[controller valueForKey:@"window"] isEqual:window]) {
56 | return [controller valueForKey:@"_workspace"];
57 | }
58 | }
59 | return nil;
60 | }
61 |
62 | @end
63 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/VVDocumenter.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenter.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVDocumenter : NSObject
30 |
31 | -(instancetype) initWithCode:(NSString *)code;
32 | -(NSString *) baseIndentation;
33 | -(NSString *) document;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/VVDocumenter.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenter.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-17.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVDocumenter.h"
28 | #import "NSString+VVSyntax.h"
29 | #import "NSString+PDRegex.h"
30 | #import "VVCommenter.h"
31 |
32 | @interface VVDocumenter()
33 |
34 | @property (nonatomic, copy) NSString *code;
35 | @property (nonatomic, assign) BOOL isEnum;
36 | @property (nonatomic, assign) BOOL isSwiftEnum;
37 |
38 | @end
39 |
40 | @implementation VVDocumenter
41 |
42 | -(instancetype) initWithCode:(NSString *)code
43 | {
44 | self = [super init];
45 | if (self) {
46 | NSString *trimmed = [[code vv_stringByReplacingRegexPattern:@"\\s*(\\(.*\?\\))\\s*" withString:@"$1"]
47 | vv_stringByReplacingRegexPattern:@"\\s*\n\\s*" withString:@" "];
48 | _isEnum = [trimmed vv_isEnum];
49 | _isSwiftEnum = [trimmed vv_isSwiftEnum];
50 | if (_isEnum || _isSwiftEnum) {
51 | _code = code;
52 | } else {
53 | //Trim the space around the braces
54 | //Then trim the new line character
55 | _code = trimmed;
56 | }
57 | }
58 | return self;
59 | }
60 |
61 | -(NSString *) baseIndentation
62 | {
63 | NSArray *matchedSpaces = [self.code vv_stringsByExtractingGroupsUsingRegexPattern:@"^(\\s*)"];
64 | if (matchedSpaces.count > 0) {
65 | return matchedSpaces[0];
66 | } else {
67 | return @"";
68 | }
69 | }
70 |
71 | -(NSString *) document
72 | {
73 | NSString *trimCode = [self.code stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
74 | NSString *baseIndent = [self baseIndentation];
75 |
76 | VVBaseCommenter *commenter = nil;
77 |
78 | if (self.isEnum) {
79 | commenter = [[VVEnumCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
80 | } else if (self.isSwiftEnum) {
81 | commenter = [[VVSwiftEnumCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
82 | } else if ([trimCode vv_isProperty]) {
83 | commenter = [[VVPropertyCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
84 | } else if ([trimCode vv_isCFunction]) {
85 | commenter = [[VVFunctionCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
86 | } else if ([trimCode vv_isMacro]) {
87 | commenter = [[VVMacroCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
88 | } else if ([trimCode vv_isStruct]) {
89 | commenter = [[VVStructCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
90 | } else if ([trimCode vv_isUnion]) {
91 | commenter = [[VVStructCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
92 | } else if ([trimCode vv_isObjCMethod]) {
93 | commenter = [[VVMethodCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
94 | } else if ([trimCode vv_isSwiftFunction]) {
95 | commenter = [[VVSwiftFunctionCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
96 | } else if ([trimCode vv_isSwiftProperty]) {
97 | commenter = [[VVSwiftPropertyCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
98 | } else if ([trimCode vv_isSwiftExtension]) {
99 | commenter = [[VVSwiftExtensionCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
100 | } else {
101 | commenter = [[VVVariableCommenter alloc] initWithIndentString:baseIndent codeString:trimCode];
102 | }
103 |
104 | if ([commenter shouldComment]) {
105 | return [commenter document];
106 | } else {
107 | return nil;
108 | }
109 | }
110 |
111 |
112 |
113 | @end
114 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/VVDocumenterManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenterManager.h
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-16.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import
28 |
29 | @interface VVDocumenterManager : NSObject
30 |
31 | +(instancetype) shared;
32 |
33 | - (void) subscribeToEvents;
34 | - (void) addSettingMenu;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/VVDocumenter/VVDocumenter/VVDocumenterManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // VVDocumenterManager.m
3 | // VVDocumenter-Xcode
4 | //
5 | // Created by 王 巍 on 13-7-16.
6 | //
7 | // Copyright (c) 2015 Wei Wang
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | #import "VVDocumenterManager.h"
28 | #import "NSTextView+VVTextGetter.h"
29 | #import "NSString+VVSyntax.h"
30 | #import "VVDocumenter.h"
31 | #import "VVKeyboardEventSender.h"
32 | #import "VVDocumenterSetting.h"
33 | #import "VVTextResult.h"
34 | #import "NSString+PDRegex.h"
35 |
36 | @interface VVDocumenterManager()
37 | @property (nonatomic, strong) id eventMonitor;
38 | @property (nonatomic, assign) BOOL prefixTyped;
39 | @end
40 |
41 | @implementation VVDocumenterManager
42 | +(void)pluginDidLoad:(NSBundle *)plugin {
43 | VVLog(@"VVDocumenter: Plugin loaded successfully");
44 | [self shared];
45 | }
46 |
47 | +(instancetype) shared {
48 | static dispatch_once_t once;
49 | static id instance = nil;
50 | dispatch_once(&once, ^{
51 | instance = [[self alloc] init];
52 | });
53 | return instance;
54 | }
55 |
56 | - (instancetype)init {
57 | if (self = [super init]) {
58 | [[NSNotificationCenter defaultCenter] addObserver:self
59 | selector:@selector(applicationDidFinishLaunching:)
60 | name:NSApplicationDidFinishLaunchingNotification
61 | object:nil];
62 | }
63 | return self;
64 | }
65 |
66 | - (void) applicationDidFinishLaunching: (NSNotification*) noti {
67 | [[NSNotificationCenter defaultCenter] addObserver:self
68 | selector:@selector(textStorageDidChange:)
69 | name:NSTextDidChangeNotification
70 | object:nil];
71 | [self addSettingMenu];
72 | }
73 |
74 | -(void) addSettingMenu
75 | {
76 | NSMenuItem *editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Window"];
77 | if (editMenuItem) {
78 | [[editMenuItem submenu] addItem:[NSMenuItem separatorItem]];
79 |
80 | NSMenuItem *newMenuItem = [[NSMenuItem alloc] initWithTitle:@"VVDocumenter" action:@selector(showSettingPanel:) keyEquivalent:@""];
81 |
82 | [newMenuItem setTarget:self];
83 | [[editMenuItem submenu] addItem:newMenuItem];
84 | }
85 | }
86 |
87 | -(void) showSettingPanel:(NSNotification *)noti {
88 | // self.settingPanel = [[VVDSettingPanelWindowController alloc] initWithWindowNibName:@"VVDSettingPanelWindowController"];
89 | // [self.settingPanel showWindow:self.settingPanel];
90 | }
91 |
92 | - (void) subscribeToEvents {
93 | [[NSNotificationCenter defaultCenter] addObserver:self
94 | selector:@selector(textStorageDidChange:)
95 | name:NSTextDidChangeNotification
96 | object:nil];
97 | }
98 |
99 |
100 | - (void) textStorageDidChange:(NSNotification *)noti {
101 |
102 | if ([[noti object] isKindOfClass:[NSTextView class]]) {
103 | NSTextView *textView = (NSTextView *)[noti object];
104 | VVTextResult *currentLineResult = [textView vv_textResultOfCurrentLine];
105 | if (currentLineResult) {
106 |
107 | //Check if there is a "//" already typed in. We do this to solve the undo issue
108 | //Otherwise when you press Cmd+Z, "///" will be recognized and trigger the doc inserting, so you can not perform an undo.
109 | NSString *triggerString = [[VVDocumenterSetting defaultSetting] triggerString];
110 |
111 | if (triggerString.length > 1) {
112 | NSString *preTypeString = [triggerString substringToIndex:triggerString.length - 2];
113 | self.prefixTyped = [currentLineResult.string vv_matchesPatternRegexPattern:[NSString stringWithFormat:@"^\\s*%@$",[NSRegularExpression escapedPatternForString:preTypeString]]] | self.prefixTyped;
114 | } else {
115 | self.prefixTyped = YES;
116 | }
117 |
118 | if ([currentLineResult.string vv_matchesPatternRegexPattern:[NSString stringWithFormat:@"^\\s*%@$",[NSRegularExpression escapedPatternForString:triggerString]]] && self.prefixTyped) {
119 | VVTextResult *previousLineResult = [textView vv_textResultOfPreviousLine];
120 |
121 | // Previous line is a documentation comment, so ignore this
122 | if ([previousLineResult.string vv_matchesPatternRegexPattern:@"^\\s*///"]) {
123 | return;
124 | }
125 |
126 | VVTextResult *nextLineResult = [textView vv_textResultOfNextLine];
127 |
128 | // Next line is a documentation comment, so ignore this
129 | if ([nextLineResult.string vv_matchesPatternRegexPattern:@"^\\s*///"]) {
130 | return;
131 | }
132 |
133 | //Get a @"///" (triggerString) typed in by user. Do work!
134 | self.prefixTyped = NO;
135 |
136 | __block BOOL shouldReplace = NO;
137 |
138 | //Decide which is closer to the cursor. A semicolon or a half brace.
139 | //We just want to document the next valid line.
140 | VVTextResult *resultUntilSemiColon = [textView vv_textResultUntilNextString:@";"];
141 | VVTextResult *resultUntilBrace = [textView vv_textResultUntilNextString:@"{"];
142 | VVTextResult *resultUntilFileEnd = [textView vv_textResultToEndOfFile];
143 |
144 | VVTextResult *resultToDocument = nil;
145 |
146 | if (resultUntilSemiColon && resultUntilBrace) {
147 | resultToDocument = (resultUntilSemiColon.range.length < resultUntilBrace.range.length) ? resultUntilSemiColon : resultUntilBrace;
148 | } else if (resultUntilBrace) {
149 | resultToDocument = resultUntilBrace;
150 | } else if (resultUntilSemiColon) {
151 | resultToDocument = resultUntilSemiColon;
152 | } else {
153 | resultToDocument = resultUntilFileEnd;
154 | }
155 |
156 | //We always write document until semicolon for enum. (Maybe struct later)
157 | if ([resultToDocument.string vv_isEnum]) {
158 | resultToDocument = resultUntilSemiColon;
159 | shouldReplace = YES;
160 | }
161 |
162 | NSString *inputCode = nil;
163 | if ([resultToDocument.string vv_isSwiftEnum]) {
164 | inputCode = [textView vv_textResultWithPairOpenString:@"{" closeString:@"}"].string;
165 | } else {
166 | inputCode = [resultToDocument.string vv_stringByConvertingToUniform];
167 | }
168 |
169 | VVDocumenter *doc = [[VVDocumenter alloc] initWithCode:inputCode];
170 | NSString *documentationString = [doc document];
171 |
172 | if (!documentationString) {
173 | //Leave the user's input there.
174 | //It might be no need to parse doc or something wrong.
175 | return;
176 | }
177 |
178 | //Now we are using a simulation of keyboard event to insert the docs, instead of using the IDE's private method.
179 | //See more at https://github.com/onevcat/VVDocumenter-Xcode/issues/3
180 |
181 | //Save current content in paste board
182 | NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
183 | NSString *originPBString = [pasteBoard stringForType:NSPasteboardTypeString];
184 |
185 | //Set the doc comments in it
186 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
187 | [pasteBoard setString:documentationString forType:NSStringPboardType];
188 |
189 | //Begin to simulate keyborad pressing
190 | VVKeyboardEventSender *kes = [[VVKeyboardEventSender alloc] init];
191 | [kes beginKeyBoradEvents];
192 | //Cmd+delete Delete current line
193 | [kes sendKeyCode:kVK_Delete withModifierCommand:YES alt:NO shift:NO control:NO];
194 | //if (shouldReplace) [textView setSelectedRange:resultToDocument.range];
195 | //Cmd+V, paste (which key to actually use is based on the current keyboard layout)
196 | NSInteger kKeyVCode = [[VVDocumenterSetting defaultSetting] keyVCode];
197 | [kes sendKeyCode:kKeyVCode withModifierCommand:YES alt:NO shift:NO control:NO];
198 |
199 | //The key down is just a defined finish signal by me. When we receive this key, we know operation above is finished.
200 | [kes sendKeyCode:kVK_F20];
201 |
202 | self.eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *incomingEvent) {
203 | if ([incomingEvent type] == NSEventTypeKeyDown && [incomingEvent keyCode] == kVK_F20) {
204 | //Finish signal arrived, no need to observe the event
205 | [NSEvent removeMonitor:self.eventMonitor];
206 | self.eventMonitor = nil;
207 |
208 | //Restore previois patse board content
209 | [pasteBoard setString:originPBString forType:NSStringPboardType];
210 |
211 | //Set cursor before the inserted documentation. So we can use tab to begin edit.
212 | int baseIndentationLength = (int)[doc baseIndentation].length;
213 | [textView setSelectedRange:NSMakeRange(currentLineResult.range.location + baseIndentationLength, 0)];
214 |
215 | //Send a 'tab' after insert the doc. For our lazy programmers. :)
216 | [kes sendKeyCode:kVK_Tab];
217 | [kes endKeyBoradEvents];
218 |
219 | shouldReplace = NO;
220 |
221 | //Invalidate the finish signal, in case you set it to do some other thing.
222 | return nil;
223 | } else if ([incomingEvent type] == NSEventTypeKeyDown && [incomingEvent keyCode] == kKeyVCode && shouldReplace == YES) {
224 | //Select input line and the define code block.
225 | NSRange r = [textView vv_textResultUntilNextString:@";"].range;
226 |
227 | //NSRange r begins from the starting of enum(struct) line. Select 1 character before to include the trigger input line.
228 | [textView setSelectedRange:NSMakeRange(r.location - 1, r.length + 1)];
229 | return incomingEvent;
230 | } else {
231 | return incomingEvent;
232 | }
233 | }];
234 | }
235 | }
236 | }
237 | }
238 |
239 | - (void)dealloc {
240 |
241 | }
242 |
243 | @end
244 |
--------------------------------------------------------------------------------