Skip to content

Commit 451bba0

Browse files
author
Ellie Shin
committed
Merge uber/remove-sourcekit
Remove sourcekitten parser
1 parent 1c19e4a commit 451bba0

File tree

18 files changed

+14
-730
lines changed

18 files changed

+14
-730
lines changed

MockoloFramework.podspec

Lines changed: 0 additions & 17 deletions
This file was deleted.

Package.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PackageDescription
44
var dependencies: [Package.Dependency] = [
55
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.0.4")),
66
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")),
7-
.package(url: "https://github.com/jpsim/SourceKitten", from: "0.29.0"),
87
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .exact("0.50200.0"))
98
]
109

@@ -29,7 +28,6 @@ let package = Package(
2928
.target(
3029
name: "MockoloFramework",
3130
dependencies: [
32-
.product(name: "SourceKittenFramework", package: "SourceKitten"),
3331
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
3432
]
3533
),

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ OPTIONS:
103103
--testable-imports, -i If set, @testable import statments will be added for each module name in this list.
104104
--concurrency-limit, -j Maximum number of threads to execute concurrently (default = number of cores on the running machine).
105105
--logging-level, -v The logging level to use. Default is set to 0 (info only). Set 1 for verbose, 2 for warning, and 3 for error.
106-
--use-sourcekit If this argument is added, it will use SourceKit for parsing. By default it uses SwiftSyntax.
107106
--help, -h Displays available options.
108107
```
109108

@@ -270,7 +269,6 @@ public class FooMock: Foo {
270269
## Used libraries
271270

272271
[SwiftSyntax](https://github.com/apple/swift-syntax) |
273-
[SourceKitten](https://github.com/jpsim/SourceKitten)
274272

275273

276274
## How to contribute to Mockolo

Sources/Mockolo/Executor.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Executor {
4040
private var useMockObservable: OptionArgument<Bool>!
4141
private var mockAll: OptionArgument<Bool>!
4242
private var concurrencyLimit: OptionArgument<Int>!
43-
private var useSourceKit: OptionArgument<Bool>!
4443

4544
/// Initializer.
4645
///
@@ -129,9 +128,6 @@ class Executor {
129128
shortName: "-j",
130129
kind: Int.self,
131130
usage: "Maximum number of threads to execute concurrently (default = number of cores on the running machine).")
132-
useSourceKit = parser.add(option: "--use-sourcekit",
133-
kind: Bool.self,
134-
usage: "Whether to use SourceKit for parsing. By default it will use SwiftSyntax.")
135131
}
136132

137133
private func fullPath(_ path: String) -> String {
@@ -185,15 +181,14 @@ class Executor {
185181
let testableImports = arguments.get(self.testableImports)
186182
let customImports = arguments.get(self.customImports)
187183
let excludeImports = arguments.get(self.excludeImports)
188-
let shouldUseSourceKit = arguments.get(useSourceKit) ?? false
189184
let shouldUseTemplateFunc = arguments.get(useTemplateFunc) ?? false
190185
let shouldUseMockObservable = arguments.get(useMockObservable) ?? false
191186
let shouldMockAll = arguments.get(mockAll) ?? false
192187

193188
do {
194189
try generate(sourceDirs: srcDirs,
195190
sourceFiles: srcs,
196-
parser: shouldUseSourceKit ? ParserViaSourceKit() : ParserViaSwiftSyntax(),
191+
parser: ParserViaSwiftSyntax(),
197192
exclusionSuffixes: exclusionSuffixes,
198193
mockFilePaths: mockFilePaths,
199194
annotation: annotation,

Sources/MockoloFramework/Models/MethodModel.swift

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616

1717
import Foundation
18-
import SourceKittenFramework
1918

2019
public enum MethodKind: Equatable {
2120
case funcKind
@@ -128,65 +127,6 @@ final class MethodModel: Model {
128127
self.accessLevel = acl
129128
}
130129

131-
init(_ ast: Structure, encloserType: DeclType, filepath: String, data: Data, processed: Bool) {
132-
// This will split func signature into name and the rest (params, return type). In case it's a generic func,
133-
// its type parameters will be in its substrctures (and < > are omitted in the func ast.name), so it will only
134-
// give the name part that we expect.
135-
var comps = ast.name.components(separatedBy: CharacterSet(arrayLiteral: ":", "(", ")")).filter {!$0.isEmpty}
136-
let nameString = comps.removeFirst()
137-
self.filePath = filepath
138-
self.data = data
139-
self.name = nameString
140-
self.type = Type(ast.typeName)
141-
self.isStatic = ast.isStaticMethod
142-
self.processed = processed
143-
self.shouldOverride = ast.isOverride || encloserType == .classType
144-
if ast.isSubscript {
145-
self.kind = .subscriptKind
146-
} else if ast.isInitializer {
147-
let isRequired = ast.isRequired || encloserType == .protocolType
148-
self.kind = .initKind(required: isRequired, override: shouldOverride)
149-
} else {
150-
self.kind = .funcKind
151-
}
152-
self.offset = ast.range.offset
153-
self.length = ast.range.length
154-
let needVarDecl = encloserType == .protocolType // Params in protocol init should be declared as private vars if not done already
155-
156-
let paramDecls = ast.substructures.filter(path: \.isVarParameter)
157-
assert(paramDecls.count == comps.count)
158-
159-
let zippedParams = zip(paramDecls, comps)
160-
self.params = zippedParams.map { (argAst: Structure, argLabel: String) -> ParamModel in
161-
return ParamModel(argAst, label: argLabel, offset: argAst.offset, length: argAst.length, data: data, inInit: ast.isInitializer, needVarDecl: needVarDecl)
162-
}
163-
164-
self.genericTypeParams = ast.substructures
165-
.filter(path: \.isGenericTypeParam)
166-
.map { (arg: Structure) -> ParamModel in
167-
ParamModel(arg, label: arg.name, offset: arg.offset, length: arg.length, data: data, isGeneric: true, needVarDecl: false)
168-
}
169-
170-
// Sourcekit structure api doesn't provide info on throws/rethrows, so manually parse it here
171-
let suffixOffset = ast.nameOffset + ast.nameLength + 1
172-
let suffixLen = ast.offset + ast.length - suffixOffset
173-
if suffixLen > 0, suffixOffset > ast.bodyOffset - 1 {
174-
let suffixPart = data.toString(offset: suffixOffset, length: suffixLen).trimmingCharacters(in: .whitespacesAndNewlines)
175-
if suffixPart.hasPrefix("\(String.SwiftKeywords.rethrows.rawValue)") {
176-
self.suffix = String.SwiftKeywords.rethrows.rawValue
177-
} else if suffixPart.hasPrefix("\(String.SwiftKeywords.throws.rawValue)") {
178-
self.suffix = String.SwiftKeywords.throws.rawValue
179-
} else {
180-
self.suffix = ""
181-
}
182-
} else {
183-
self.suffix = ""
184-
}
185-
186-
self.accessLevel = ast.accessLevel
187-
self.attributes = ast.hasAvailableAttribute ? ast.extractAttributes(data, filterOn: SwiftDeclarationAttributeKind.available.rawValue) : []
188-
}
189-
190130
var fullName: String {
191131
return self.name + self.signatureComponents.joined() + staticKind
192132
}
@@ -204,7 +144,7 @@ final class MethodModel: Model {
204144
if processed {
205145
var prefix = shouldOverride ? "\(String.override) " : ""
206146

207-
if case .initKind(required: let isRequired, override: let override) = self.kind {
147+
if case .initKind(required: let isRequired, override: _) = self.kind {
208148
if isRequired {
209149
prefix = ""
210150
}

Sources/MockoloFramework/Models/ParamModel.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616

1717
import Foundation
18-
import SourceKittenFramework
1918

2019
final class ParamModel: Model {
2120
var name: String
@@ -51,21 +50,6 @@ final class ParamModel: Model {
5150
self.needVarDecl = needVarDecl
5251
}
5352

54-
init(_ ast: Structure, label: String = "", offset: Int64, length: Int64, data: Data, isGeneric: Bool = false, inInit: Bool = false, needVarDecl: Bool) {
55-
self.name = ast.name
56-
self.offset = offset
57-
self.length = length
58-
// Sourcekit doesn't specify if a func arg is variadic, so look ahead for the following characters to determine.
59-
let lookahead = data.toString(offset: offset + length, length: 3)
60-
let isVariadic = lookahead == "..."
61-
self.isGeneric = isGeneric
62-
self.inInit = inInit
63-
self.needVarDecl = needVarDecl
64-
let typeArg = isGeneric ? (ast.inheritedTypes.first ?? .unknownVal) : (isVariadic ? ast.typeName + "..." : ast.typeName)
65-
self.type = Type(typeArg)
66-
self.label = ast.name != label ? label : ""
67-
}
68-
6953
var underlyingName: String {
7054
return "_\(name)"
7155
}

Sources/MockoloFramework/Models/ParsedEntity.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616

1717
import Foundation
18-
import SourceKittenFramework
1918

2019
/// Metadata containing unique models and potential init params ready to be rendered for output
2120
struct ResolvedEntity {

Sources/MockoloFramework/Models/TypeAliasModel.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
//
1616

1717
import Foundation
18-
import SourceKittenFramework
19-
2018

2119
final class TypeAliasModel: Model {
2220
var filePath: String = ""
@@ -55,32 +53,6 @@ final class TypeAliasModel: Model {
5553
}
5654
}
5755

58-
init(_ ast: Structure, filepath: String, data: Data, overrideTypes: [String: String]?, processed: Bool) {
59-
self.name = ast.name
60-
self.filePath = filepath
61-
self.offset = ast.offset
62-
self.length = ast.length
63-
self.typeOffset = ast.nameOffset + ast.nameLength + 1
64-
self.typeLength = ast.offset + ast.length - typeOffset
65-
self.accessLevel = ast.accessLevel
66-
self.processed = processed
67-
self.overrideTypes = overrideTypes
68-
self.modelDescription = ast.description
69-
// If there's an override typealias value, set it to type
70-
if let val = overrideTypes?[self.name] {
71-
self.type = Type(val)
72-
} else {
73-
// Sourcekit doesn't give inheritance type info for an associatedtype, so need to manually parse it from the content
74-
if typeLength < 0 {
75-
self.type = Type(String.any)
76-
} else {
77-
let charset = CharacterSet(arrayLiteral: "=", ":").union(.whitespaces)
78-
let typeArg = data.toString(offset: typeOffset, length: typeLength).trimmingCharacters(in: charset)
79-
self.type = Type(typeArg)
80-
}
81-
}
82-
}
83-
8456
var fullName: String {
8557
return self.name + self.type.displayName
8658
}

Sources/MockoloFramework/Models/VariableModel.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import SourceKittenFramework
32

43
final class VariableModel: Model {
54
var name: String
@@ -58,22 +57,6 @@ final class VariableModel: Model {
5857
self.modelDescription = modelDescription
5958
}
6059

61-
init(_ ast: Structure, encloserType: DeclType, filepath: String, data: Data, overrideTypes: [String: String]?, processed: Bool) {
62-
name = ast.name
63-
type = Type(ast.typeName)
64-
offset = ast.range.offset
65-
length = ast.range.length
66-
canBeInitParam = ast.canBeInitParam
67-
isStatic = ast.isStaticVariable
68-
shouldOverride = ast.isOverride || encloserType == .classType
69-
accessLevel = ast.accessLevel
70-
attributes = ast.hasAvailableAttribute ? ast.extractAttributes(data, filterOn: SwiftDeclarationAttributeKind.available.rawValue) : nil
71-
self.processed = processed
72-
self.overrideTypes = overrideTypes
73-
self.data = data
74-
self.filePath = filepath
75-
}
76-
7760
func render(with identifier: String, encloser: String, useTemplateFunc: Bool = false, useMockObservable: Bool = false) -> String? {
7861
if processed {
7962
var prefix = ""

Sources/MockoloFramework/Operations/Generator.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ enum InputError: Error {
2121
case sourceFilesError
2222
}
2323

24-
public enum ParserType {
25-
case swiftSyntax
26-
case sourceKit
27-
case random
28-
}
29-
3024
/// Performs end to end mock generation flow
3125
public func generate(sourceDirs: [String]?,
3226
sourceFiles: [String]?,

0 commit comments

Comments
 (0)