Skip to content

Commit 0efca8b

Browse files
add hashable command
1 parent 99f1f6d commit 0efca8b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CodeGenerator.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
A0A02CCB1E1A6A3F001900DC /* Generator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A02CC21E1A60EA001900DC /* Generator.swift */; };
5757
A0A02CD01E1A6DE3001900DC /* SelectableGeneratorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A02CCE1E1A6DE3001900DC /* SelectableGeneratorCommand.swift */; };
5858
A0A02CD31E1A7236001900DC /* GenerateEquatableCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A02CD11E1A7236001900DC /* GenerateEquatableCommand.swift */; };
59+
A0A02CD51E1A739A001900DC /* GenerateHashableCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A02CD41E1A739A001900DC /* GenerateHashableCommand.swift */; };
5960
A0A82AE71E11571200F27EA3 /* interface1.txt in Resources */ = {isa = PBXBuildFile; fileRef = A0A82AE61E11571200F27EA3 /* interface1.txt */; };
6061
A0A82AE91E11593800F27EA3 /* interface1Mock.txt in Resources */ = {isa = PBXBuildFile; fileRef = A0A82AE81E11593800F27EA3 /* interface1Mock.txt */; };
6162
A0A82AEB1E1159C200F27EA3 /* NSObject+file.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A82AEA1E1159C200F27EA3 /* NSObject+file.swift */; };
@@ -147,6 +148,7 @@
147148
A0A02CC81E1A68D8001900DC /* GeneratedHash.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GeneratedHash.txt; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
148149
A0A02CCE1E1A6DE3001900DC /* SelectableGeneratorCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectableGeneratorCommand.swift; sourceTree = "<group>"; };
149150
A0A02CD11E1A7236001900DC /* GenerateEquatableCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenerateEquatableCommand.swift; sourceTree = "<group>"; };
151+
A0A02CD41E1A739A001900DC /* GenerateHashableCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenerateHashableCommand.swift; sourceTree = "<group>"; };
150152
A0A82AE61E11571200F27EA3 /* interface1.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = interface1.txt; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
151153
A0A82AE81E11593800F27EA3 /* interface1Mock.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = interface1Mock.txt; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
152154
A0A82AEA1E1159C200F27EA3 /* NSObject+file.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSObject+file.swift"; sourceTree = "<group>"; };
@@ -289,6 +291,7 @@
289291
A01E46881E0FF95900395AED /* Source */,
290292
A03920841E0F3A8B005A6E89 /* SourceEditorExtension.swift */,
291293
A0A02CD11E1A7236001900DC /* GenerateEquatableCommand.swift */,
294+
A0A02CD41E1A739A001900DC /* GenerateHashableCommand.swift */,
292295
A0A02CCE1E1A6DE3001900DC /* SelectableGeneratorCommand.swift */,
293296
A03920861E0F3A8B005A6E89 /* GenerateMockCommand.swift */,
294297
A03920901E0F3AEF005A6E89 /* String+regexr.swift */,
@@ -527,6 +530,7 @@
527530
A0A02CC31E1A60EA001900DC /* Generator.swift in Sources */,
528531
A0E2765D1E142670003CC557 /* ParamMocker.swift in Sources */,
529532
A01E468A1E100FB200395AED /* FuncParam.swift in Sources */,
533+
A0A02CD51E1A739A001900DC /* GenerateHashableCommand.swift in Sources */,
530534
);
531535
runOnlyForDeploymentPostprocessing = 0;
532536
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// GenerateHashableCommand.swift
3+
// CodeGenerator
4+
//
5+
// Created by WANG Jie on 02/01/2017.
6+
// Copyright © 2017 wangjie. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import XcodeKit
11+
12+
class GenerateHashableCommand: NSObject, SelectableGeneratorCommand {
13+
14+
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void) {
15+
swiftPerform(with: invocation, completionHandler: completionHandler)
16+
}
17+
18+
19+
func generator(with invocation: XCSourceEditorCommandInvocation, selections: [XCSourceTextRange]) -> Generator {
20+
let selectedVars = selectedLines(with: invocation, selections: selections).flatMap { VarSignature(string: $0) }
21+
return HashableGenerator(interfaceDefinition: interfaceSignature(of: invocation).definition, varSignatures: selectedVars, indentation: " ".repeating(invocation.buffer.indentationWidth))
22+
}
23+
24+
func generator(with invocation: XCSourceEditorCommandInvocation) -> Generator {
25+
return HashableGenerator(interfaceSignature: interfaceSignature(of: invocation), indentation: " ".repeating(invocation.buffer.indentationWidth))
26+
}
27+
}

Generate.../Info.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
<key>XCSourceEditorCommandName</key>
4545
<string>Equatable</string>
4646
</dict>
47+
<dict>
48+
<key>XCSourceEditorCommandClassName</key>
49+
<string>$(PRODUCT_MODULE_NAME).GenerateHashableCommand</string>
50+
<key>XCSourceEditorCommandIdentifier</key>
51+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).GenerateHashableCommand</string>
52+
<key>XCSourceEditorCommandName</key>
53+
<string>Hashable</string>
54+
</dict>
4755
</array>
4856
<key>XCSourceEditorExtensionPrincipalClass</key>
4957
<string>$(PRODUCT_MODULE_NAME).SourceEditorExtension</string>

0 commit comments

Comments
 (0)