1515//
1616
1717import Foundation
18- import SourceKittenFramework
1918
2019public 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 }
0 commit comments