diff --git a/.sourcery-macOS.yml b/.sourcery-macOS.yml new file mode 100644 index 00000000..9218d92a --- /dev/null +++ b/.sourcery-macOS.yml @@ -0,0 +1,10 @@ +sources: + - SourceryRuntime/Sources/Common + - SourceryRuntime/Sources/macOS +templates: + - Sourcery/Templates/Coding.stencil + - Sourcery/Templates/JSExport.ejs + - Sourcery/Templates/Typed.stencil + - Sourcery/Templates/TypedSpec.stencil +output: + SourceryRuntime/Sources/Generated diff --git a/.sourcery-ubuntu.yml b/.sourcery-ubuntu.yml new file mode 100644 index 00000000..c797c0ab --- /dev/null +++ b/.sourcery-ubuntu.yml @@ -0,0 +1,10 @@ +sources: + - SourceryRuntime/Sources/Common + - SourceryRuntime/Sources/Linux +templates: + - Sourcery/Templates/Coding.stencil + - Sourcery/Templates/JSExport.ejs + - Sourcery/Templates/Typed.stencil + - Sourcery/Templates/TypedSpec.stencil +output: + SourceryRuntime/Sources/Generated diff --git a/.sourcery.yml b/.sourcery.yml deleted file mode 100644 index 3133e272..00000000 --- a/.sourcery.yml +++ /dev/null @@ -1,6 +0,0 @@ -sources: - - SourceryRuntime/Sources -templates: - - Sourcery/Templates -output: - SourceryRuntime/Sources/Generated diff --git a/Rakefile b/Rakefile index 84caa905..558f0f29 100644 --- a/Rakefile +++ b/Rakefile @@ -87,12 +87,14 @@ end task :run_sourcery do print_info "Generating internal boilerplate code" - sh "#{CLI_DIR}bin/sourcery" + sh "#{CLI_DIR}bin/sourcery --config .sourcery-macOS.yml" + sh "#{CLI_DIR}bin/sourcery --config .sourcery-ubuntu.yml" end desc "Update internal boilerplate code" -task :generate_internal_boilerplate_code => [:fat_build, :run_sourcery, :clean] do - sh "Scripts/package_content \"SourceryRuntime/Sources\" > \"SourcerySwift/Sources/SourceryRuntime.content.generated.swift\"" +task :generate_internal_boilerplate_code => [:build, :run_sourcery] do + sh "Scripts/package_content \"SourceryRuntime/Sources/Common,SourceryRuntime/Sources/macOS,SourceryRuntime/Sources/Generated\" \"true\" > \"SourcerySwift/Sources/SourceryRuntime.content.generated.swift\"" + sh "Scripts/package_content \"SourceryRuntime/Sources/Common,SourceryRuntime/Sources/Linux,SourceryRuntime/Sources/Generated\" \"false\" > \"SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift\"" generated_files = `git status --porcelain` .split("\n") .select { |item| item.include?('.generated.') } diff --git a/Scripts/package_content b/Scripts/package_content index 8810f8f9..6addd3b5 100755 --- a/Scripts/package_content +++ b/Scripts/package_content @@ -4,7 +4,8 @@ /// Merge all Swift files contained in FOLDER into swift code that can be used by the FolderSynchronizer. /// Example: $0 Sources/SourceryRuntime > file.swift /// Options: -/// FOLDER: the path where the Swift files to merge are +/// FOLDERS: the paths where the Swift files to merge are, separated with comma "," +/// isForDarwinPlatform: if true, the generated code will be compilable on Darwin platforms /// -h: Display this help message import Foundation @@ -40,37 +41,45 @@ extension String { } } -func package(folder folderPath: String) throws { - print("let sourceryRuntimeFiles: [FolderSynchronizer.File] = [") - let folderURL = URL(fileURLWithPath: folderPath) - - guard let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else { - print("Unable to retrieve file enumerator") - exit(1) +func package(folders folderPaths: [String], isForDarwinPlatform: Bool) throws { + if !isForDarwinPlatform { + print("#if !canImport(ObjectiveC)") + } else { + print("#if canImport(ObjectiveC)") } - var files = [URL]() - for case let fileURL as URL in enumerator { - do { - let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) - if fileAttributes.isRegularFile! { - files.append(fileURL) + print("let sourceryRuntimeFiles: [FolderSynchronizer.File] = [") + for folderPath in folderPaths { + let folderURL = URL(fileURLWithPath: folderPath) + + guard let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) else { + print("Unable to retrieve file enumerator") + exit(1) + } + var files = [URL]() + for case let fileURL as URL in enumerator { + do { + let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) + if fileAttributes.isRegularFile! { + files.append(fileURL) + } + } catch { + print(error, fileURL) } - } catch { - print(error, fileURL) + } + + try files + .sorted(by: { $0.lastPathComponent < $1.lastPathComponent }) + .forEach { sourceFileURL in + print(" .init(name: \"\(sourceFileURL.lastPathComponent)\", content:") + print("\"\"\"") + let content = try String(contentsOf: sourceFileURL, encoding: .utf8) + .escapedSwiftTokens() + print(content) + print("\"\"\"),") } } - - try files - .sorted(by: { $0.lastPathComponent < $1.lastPathComponent }) - .forEach { sourceFileURL in - print(" .init(name: \"\(sourceFileURL.lastPathComponent)\", content:") - print("\"\"\"") - let content = try String(contentsOf: sourceFileURL, encoding: .utf8) - .escapedSwiftTokens() - print(content) - print("\"\"\"),") - } print("]") + print("#endif") } func main() { @@ -82,10 +91,16 @@ func main() { print("Missing folderPath argument") exit(1) } - let folder = CommandLine.arguments[1] + guard CommandLine.arguments.count > 2 else { + print("Missing isForDarwinPlatform argument") + exit(1) + } + let foldersPaths = CommandLine.arguments[1] + let isForDarwinPlatform = Bool(CommandLine.arguments[2]) ?? false + let folders = foldersPaths.split(separator: ",").map(String.init) do { - try package(folder: folder) + try package(folders: folders, isForDarwinPlatform: isForDarwinPlatform) } catch { print("Failed with error: \(error)") exit(1) diff --git a/Sourcery/Templates/JSExport.ejs b/Sourcery/Templates/JSExport.ejs index 8ef0e1f9..daacf162 100644 --- a/Sourcery/Templates/JSExport.ejs +++ b/Sourcery/Templates/JSExport.ejs @@ -1,5 +1,6 @@ // swiftlint:disable vertical_whitespace trailing_newline +#if canImport(JavaScriptCore) import JavaScriptCore <%_ for (type of types.implementing.AutoJSExport) { -%> @@ -15,3 +16,4 @@ import JavaScriptCore extension <%= type.name %>: <%= type.name %>AutoJSExport {} <%_ } %> <%_ } %> +#endif \ No newline at end of file diff --git a/Sourcery/Templates/Typed.stencil b/Sourcery/Templates/Typed.stencil index dee50a05..5df972d8 100644 --- a/Sourcery/Templates/Typed.stencil +++ b/Sourcery/Templates/Typed.stencil @@ -17,6 +17,8 @@ extension {{ type.name }} { {{ type.accessLevel }} var isClosure: Bool { return typeName.isClosure } /// Whether type is an array. Shorthand for `typeName.isArray` {{ type.accessLevel }} var isArray: Bool { return typeName.isArray } + /// Whether type is a set. Shorthand for `typeName.isSet` + {{ type.accessLevel }} var isSet: Bool { return typeName.isSet } /// Whether type is a dictionary. Shorthand for `typeName.isDictionary` {{ type.accessLevel }} var isDictionary: Bool { return typeName.isDictionary } }{% endfor %} diff --git a/Sourcery/Templates/TypedSpec.stencil b/Sourcery/Templates/TypedSpec.stencil index 586f8e76..49a985e4 100644 --- a/Sourcery/Templates/TypedSpec.stencil +++ b/Sourcery/Templates/TypedSpec.stencil @@ -28,6 +28,7 @@ class TypedSpec: QuickSpec { return variable?.typeName ?? TypeName(name: "") } +#if canImport(ObjectiveC) it("can report optional via KVC") { expect({{ type.name }}(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true)) expect({{ type.name }}(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true)) @@ -68,6 +69,7 @@ class TypedSpec: QuickSpec { sut.typeName.actualTypeName = typeName("Int") expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Int"))) } +#endif } {% endfor %} } diff --git a/SourceryRuntime/Sources/AST/AccessLevel.swift b/SourceryRuntime/Sources/Common/AST/AccessLevel.swift similarity index 100% rename from SourceryRuntime/Sources/AST/AccessLevel.swift rename to SourceryRuntime/Sources/Common/AST/AccessLevel.swift diff --git a/SourceryRuntime/Sources/AST/Actor.swift b/SourceryRuntime/Sources/Common/AST/Actor.swift similarity index 91% rename from SourceryRuntime/Sources/AST/Actor.swift rename to SourceryRuntime/Sources/Common/AST/Actor.swift index 0d5e2283..2c6b20db 100644 --- a/SourceryRuntime/Sources/AST/Actor.swift +++ b/SourceryRuntime/Sources/Common/AST/Actor.swift @@ -11,7 +11,7 @@ public final class Actor: Type { /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -54,11 +54,12 @@ public final class Actor: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \(String(describing: self.kind)), " - string += "isFinal = \(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \(String(describing: self.kind)), ") + string.append("isFinal = \(String(describing: self.isFinal))") return string } @@ -72,6 +73,8 @@ public final class Actor: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) diff --git a/SourceryRuntime/Sources/AST/Annotations.swift b/SourceryRuntime/Sources/Common/AST/Annotations.swift similarity index 100% rename from SourceryRuntime/Sources/AST/Annotations.swift rename to SourceryRuntime/Sources/Common/AST/Annotations.swift diff --git a/SourceryRuntime/Sources/AST/Attribute.swift b/SourceryRuntime/Sources/Common/AST/Attribute.swift similarity index 99% rename from SourceryRuntime/Sources/AST/Attribute.swift rename to SourceryRuntime/Sources/Common/AST/Attribute.swift index 4120f797..4a80be35 100644 --- a/SourceryRuntime/Sources/AST/Attribute.swift +++ b/SourceryRuntime/Sources/Common/AST/Attribute.swift @@ -166,6 +166,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/Class.swift b/SourceryRuntime/Sources/Common/AST/Class.swift similarity index 91% rename from SourceryRuntime/Sources/AST/Class.swift rename to SourceryRuntime/Sources/Common/AST/Class.swift index fe955e39..10d5acce 100644 --- a/SourceryRuntime/Sources/AST/Class.swift +++ b/SourceryRuntime/Sources/Common/AST/Class.swift @@ -10,7 +10,7 @@ public final class Class: Type { /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -53,11 +53,12 @@ public final class Class: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \(String(describing: self.kind)), " - string += "isFinal = \(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \(String(describing: self.kind)), ") + string.append("isFinal = \(String(describing: self.isFinal))") return string } @@ -71,6 +72,8 @@ public final class Class: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) diff --git a/SourceryRuntime/Sources/AST/Definition.swift b/SourceryRuntime/Sources/Common/AST/Definition.swift similarity index 100% rename from SourceryRuntime/Sources/AST/Definition.swift rename to SourceryRuntime/Sources/Common/AST/Definition.swift diff --git a/SourceryRuntime/Sources/AST/Documentation.swift b/SourceryRuntime/Sources/Common/AST/Documentation.swift similarity index 100% rename from SourceryRuntime/Sources/AST/Documentation.swift rename to SourceryRuntime/Sources/Common/AST/Documentation.swift diff --git a/SourceryRuntime/Sources/AST/Import.swift b/SourceryRuntime/Sources/Common/AST/Import.swift similarity index 98% rename from SourceryRuntime/Sources/AST/Import.swift rename to SourceryRuntime/Sources/Common/AST/Import.swift index ce46c576..c4463f0f 100644 --- a/SourceryRuntime/Sources/AST/Import.swift +++ b/SourceryRuntime/Sources/Common/AST/Import.swift @@ -50,6 +50,8 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.kind) diff --git a/SourceryRuntime/Sources/AST/Modifier.swift b/SourceryRuntime/Sources/Common/AST/Modifier.swift similarity index 98% rename from SourceryRuntime/Sources/AST/Modifier.swift rename to SourceryRuntime/Sources/Common/AST/Modifier.swift index 3d8d6838..dddc359c 100644 --- a/SourceryRuntime/Sources/AST/Modifier.swift +++ b/SourceryRuntime/Sources/Common/AST/Modifier.swift @@ -38,6 +38,8 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/PhantomProtocols.swift b/SourceryRuntime/Sources/Common/AST/PhantomProtocols.swift similarity index 100% rename from SourceryRuntime/Sources/AST/PhantomProtocols.swift rename to SourceryRuntime/Sources/Common/AST/PhantomProtocols.swift diff --git a/SourceryRuntime/Sources/AST/Protocol.swift b/SourceryRuntime/Sources/Common/AST/Protocol.swift similarity index 93% rename from SourceryRuntime/Sources/AST/Protocol.swift rename to SourceryRuntime/Sources/Common/AST/Protocol.swift index 1b82f6b8..7b2354f5 100644 --- a/SourceryRuntime/Sources/AST/Protocol.swift +++ b/SourceryRuntime/Sources/Common/AST/Protocol.swift @@ -27,6 +27,7 @@ public final class Protocol: Type { } } + // sourcery: skipCoding /// list of generic requirements public override var genericRequirements: [GenericRequirement] { didSet { @@ -75,11 +76,12 @@ public final class Protocol: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \(String(describing: self.kind)), " - string += "associatedTypes = \(String(describing: self.associatedTypes)), " + string.append(", ") + string.append("kind = \(String(describing: self.kind)), ") + string.append("associatedTypes = \(String(describing: self.associatedTypes)), ") return string } @@ -94,6 +96,8 @@ public final class Protocol: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.associatedTypes) diff --git a/SourceryRuntime/Sources/AST/ProtocolComposition.swift b/SourceryRuntime/Sources/Common/AST/ProtocolComposition.swift similarity index 98% rename from SourceryRuntime/Sources/AST/ProtocolComposition.swift rename to SourceryRuntime/Sources/Common/AST/ProtocolComposition.swift index 24fce2fa..a3fea9cc 100644 --- a/SourceryRuntime/Sources/AST/ProtocolComposition.swift +++ b/SourceryRuntime/Sources/Common/AST/ProtocolComposition.swift @@ -56,6 +56,7 @@ public final class ProtocolComposition: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -75,6 +76,8 @@ public final class ProtocolComposition: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.composedTypeNames) diff --git a/SourceryRuntime/Sources/AST/Struct.swift b/SourceryRuntime/Sources/Common/AST/Struct.swift similarity index 97% rename from SourceryRuntime/Sources/AST/Struct.swift rename to SourceryRuntime/Sources/Common/AST/Struct.swift index c3ff3685..4560abd0 100644 --- a/SourceryRuntime/Sources/AST/Struct.swift +++ b/SourceryRuntime/Sources/Common/AST/Struct.swift @@ -58,6 +58,7 @@ public final class Struct: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -75,6 +76,8 @@ public final class Struct: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) diff --git a/SourceryRuntime/Sources/AST/TypeName/Array.swift b/SourceryRuntime/Sources/Common/AST/TypeName/Array.swift similarity index 89% rename from SourceryRuntime/Sources/AST/TypeName/Array.swift rename to SourceryRuntime/Sources/Common/AST/TypeName/Array.swift index 9b8c25e9..2a35e746 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Array.swift +++ b/SourceryRuntime/Sources/Common/AST/TypeName/Array.swift @@ -34,12 +34,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "elementTypeName = \(String(describing: self.elementTypeName)), " - string += "asGeneric = \(String(describing: self.asGeneric)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("elementTypeName = \(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \(String(describing: self.asGeneric)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -54,6 +55,8 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/Dictionary.swift b/SourceryRuntime/Sources/Common/AST/TypeName/Dictionary.swift similarity index 90% rename from SourceryRuntime/Sources/AST/TypeName/Dictionary.swift rename to SourceryRuntime/Sources/Common/AST/TypeName/Dictionary.swift index 12665712..f3044d86 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Dictionary.swift +++ b/SourceryRuntime/Sources/Common/AST/TypeName/Dictionary.swift @@ -44,13 +44,14 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "valueTypeName = \(String(describing: self.valueTypeName)), " - string += "keyTypeName = \(String(describing: self.keyTypeName)), " - string += "asGeneric = \(String(describing: self.asGeneric)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("valueTypeName = \(String(describing: self.valueTypeName)), ") + string.append("keyTypeName = \(String(describing: self.keyTypeName)), ") + string.append("asGeneric = \(String(describing: self.asGeneric)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -66,6 +67,8 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/Generic.swift b/SourceryRuntime/Sources/Common/AST/TypeName/Generic.swift similarity index 98% rename from SourceryRuntime/Sources/AST/TypeName/Generic.swift rename to SourceryRuntime/Sources/Common/AST/TypeName/Generic.swift index c38c8511..96ff26e7 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Generic.swift +++ b/SourceryRuntime/Sources/Common/AST/TypeName/Generic.swift @@ -39,6 +39,8 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/Set.swift b/SourceryRuntime/Sources/Common/AST/TypeName/Set.swift similarity index 88% rename from SourceryRuntime/Sources/AST/TypeName/Set.swift rename to SourceryRuntime/Sources/Common/AST/TypeName/Set.swift index 927776a1..6f5c1d63 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Set.swift +++ b/SourceryRuntime/Sources/Common/AST/TypeName/Set.swift @@ -34,12 +34,13 @@ public final class SetType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "elementTypeName = \(String(describing: self.elementTypeName)), " - string += "asGeneric = \(String(describing: self.asGeneric)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("elementTypeName = \(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \(String(describing: self.asGeneric)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -54,6 +55,8 @@ public final class SetType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -73,13 +76,13 @@ public final class SetType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { + guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { withVaList(["elementTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/TypeName/Typed.swift b/SourceryRuntime/Sources/Common/AST/TypeName/Typed.swift similarity index 100% rename from SourceryRuntime/Sources/AST/TypeName/Typed.swift rename to SourceryRuntime/Sources/Common/AST/TypeName/Typed.swift diff --git a/SourceryRuntime/Sources/AST/Typealias.swift b/SourceryRuntime/Sources/Common/AST/Typealias.swift similarity index 90% rename from SourceryRuntime/Sources/AST/Typealias.swift rename to SourceryRuntime/Sources/Common/AST/Typealias.swift index 6278113b..702b6684 100644 --- a/SourceryRuntime/Sources/AST/Typealias.swift +++ b/SourceryRuntime/Sources/Common/AST/Typealias.swift @@ -55,16 +55,17 @@ public final class Typealias: NSObject, Typed, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "aliasName = \(String(describing: self.aliasName)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "module = \(String(describing: self.module)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "parentName = \(String(describing: self.parentName)), " - string += "name = \(String(describing: self.name)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " + string.append("aliasName = \(String(describing: self.aliasName)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("module = \(String(describing: self.module)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("parentName = \(String(describing: self.parentName)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") return string } @@ -84,6 +85,8 @@ public final class Typealias: NSObject, Typed, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.aliasName) @@ -127,6 +130,18 @@ public final class Typealias: NSObject, Typed, SourceryModel, Diffable { }; self.typeName = typeName self.type = aDecoder.decode(forKey: "type") self.module = aDecoder.decode(forKey: "module") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation self.parent = aDecoder.decode(forKey: "parent") guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { withVaList(["accessLevel"]) { arguments in @@ -134,18 +149,6 @@ public final class Typealias: NSObject, Typed, SourceryModel, Diffable { } fatalError() }; self.accessLevel = accessLevel - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation self.parentName = aDecoder.decode(forKey: "parentName") } @@ -155,11 +158,11 @@ public final class Typealias: NSObject, Typed, SourceryModel, Diffable { aCoder.encode(self.typeName, forKey: "typeName") aCoder.encode(self.type, forKey: "type") aCoder.encode(self.module, forKey: "module") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") aCoder.encode(self.parent, forKey: "parent") aCoder.encode(self.accessLevel, forKey: "accessLevel") aCoder.encode(self.parentName, forKey: "parentName") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.annotations, forKey: "annotations") } // sourcery:end } diff --git a/SourceryRuntime/Sources/Array+Parallel.swift b/SourceryRuntime/Sources/Common/Array+Parallel.swift similarity index 100% rename from SourceryRuntime/Sources/Array+Parallel.swift rename to SourceryRuntime/Sources/Common/Array+Parallel.swift diff --git a/SourceryRuntime/Sources/BytesRange.swift b/SourceryRuntime/Sources/Common/BytesRange.swift similarity index 96% rename from SourceryRuntime/Sources/BytesRange.swift rename to SourceryRuntime/Sources/Common/BytesRange.swift index c0e45b2b..554fe86e 100644 --- a/SourceryRuntime/Sources/BytesRange.swift +++ b/SourceryRuntime/Sources/Common/BytesRange.swift @@ -24,6 +24,7 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " string += "offset = \(String(describing: self.offset)), " @@ -42,6 +43,8 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.offset) diff --git a/SourceryRuntime/Sources/Composer/Composer.swift b/SourceryRuntime/Sources/Common/Composer/Composer.swift similarity index 100% rename from SourceryRuntime/Sources/Composer/Composer.swift rename to SourceryRuntime/Sources/Common/Composer/Composer.swift diff --git a/SourceryRuntime/Sources/Composer/ParserResultsComposed.swift b/SourceryRuntime/Sources/Common/Composer/ParserResultsComposed.swift similarity index 96% rename from SourceryRuntime/Sources/Composer/ParserResultsComposed.swift rename to SourceryRuntime/Sources/Common/Composer/ParserResultsComposed.swift index 351063ed..16cb2f1b 100644 --- a/SourceryRuntime/Sources/Composer/ParserResultsComposed.swift +++ b/SourceryRuntime/Sources/Common/Composer/ParserResultsComposed.swift @@ -75,37 +75,42 @@ internal struct ParserResultsComposed { } } + // if it had contained types, they might have been fully defined and so their name has to be noted in uniques + private mutating func rewriteChildren(of type: Type) { + // child is never an extension so no need to check + for child in type.containedTypes { + typeMap[child.globalName] = child + rewriteChildren(of: child) + } + } + private mutating func unifyTypes() -> [Type] { /// Resolve actual names of extensions, as they could have been done on typealias and note updated child names in uniques if needed parsedTypes .filter { $0.isExtension } - .forEach { - let oldName = $0.globalName + .forEach { (type: Type) in + let oldName = type.globalName - if $0.parent == nil, $0.localName.contains(".") { - resolveExtensionOfNestedType($0) + let hasDotInLocalName = type.localName.contains(".") as Bool + if let _ = type.parent, hasDotInLocalName { + resolveExtensionOfNestedType(type) } - if let resolved = resolveGlobalName(for: oldName, containingType: $0.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { - $0.localName = resolved.replacingOccurrences(of: "\($0.module != nil ? "\($0.module!)." : "")", with: "") + if let resolved = resolveGlobalName(for: oldName, containingType: type.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { + var moduleName: String = "" + if let module = type.module { + moduleName = "\(module)." + } + type.localName = resolved.replacingOccurrences(of: moduleName, with: "") } else { return } // nothing left to do - guard oldName != $0.globalName else { + guard oldName != type.globalName else { return } - - // if it had contained types, they might have been fully defined and so their name has to be noted in uniques - func rewriteChildren(of type: Type) { - // child is never an extension so no need to check - for child in type.containedTypes { - typeMap[child.globalName] = child - rewriteChildren(of: child) - } - } - rewriteChildren(of: $0) + rewriteChildren(of: type) } // extend all types with their extensions diff --git a/SourceryRuntime/Sources/Diffable.swift b/SourceryRuntime/Sources/Common/Diffable.swift similarity index 95% rename from SourceryRuntime/Sources/Diffable.swift rename to SourceryRuntime/Sources/Common/Diffable.swift index 749fdd54..3671ac9d 100644 --- a/SourceryRuntime/Sources/Diffable.swift +++ b/SourceryRuntime/Sources/Common/Diffable.swift @@ -61,6 +61,8 @@ public class DiffableResult: NSObject, AutoEquatable { var isEmpty: Bool { return results.isEmpty } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.identifier) @@ -76,7 +78,9 @@ public class DiffableResult: NSObject, AutoEquatable { public override var description: String { guard !results.isEmpty else { return "" } - return "\(identifier.flatMap { "\($0) " } ?? "")" + results.joined(separator: "\n") + var description = "\(identifier.flatMap { "\($0) " } ?? "")" + description.append(results.joined(separator: "\n")) + return description } } @@ -97,7 +101,9 @@ public extension DiffableResult { /// :nodoc: @discardableResult func trackDifference(actual: T?, expected: T?) -> DiffableResult { if actual != expected { - let result = DiffableResult(results: [""]) + let expected = expected.map({ "\($0)" }) ?? "nil" + let actual = actual.map({ "\($0)" }) ?? "nil" + let result = DiffableResult(results: [""]) append(contentsOf: result) } return self diff --git a/SourceryRuntime/Sources/Extensions.swift b/SourceryRuntime/Sources/Common/Extensions.swift similarity index 86% rename from SourceryRuntime/Sources/Extensions.swift rename to SourceryRuntime/Sources/Common/Extensions.swift index 607c625f..dc23f359 100644 --- a/SourceryRuntime/Sources/Extensions.swift +++ b/SourceryRuntime/Sources/Common/Extensions.swift @@ -189,29 +189,37 @@ public extension String { defer { i = self.index(i, offsetBy: offset) } - let currentlyScanned = self[i..<(self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) ?? self.endIndex)] - if let openString = between.open.first(where: { String(self[i...]).starts(with: $0) }) { - if !(boundingCharactersCount == 0 && String(self[i]) == delimiter) { + var currentlyScannedEnd: Index = self.endIndex + if let endIndex = self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) { + currentlyScannedEnd = endIndex + } + let currentlyScanned: String = String(self[i..` - if !(self[i] == ">" && item.last == "-") { + if !((self[i] == ">") as Bool && (item.last == "-") as Bool) { boundingCharactersCount = max(0, boundingCharactersCount - 1) } offset = closeString.count } - if self[i] == "\"" { + if (self[i] == "\"") as Bool { quotesCount += 1 } - if currentlyScanned == delimiter && boundingCharactersCount == 0 && quotesCount % 2 == 0 { + let currentIsDelimiter = (currentlyScanned == delimiter) as Bool + let boundingCountIsZero = (boundingCharactersCount == 0) as Bool + let hasEvenQuotes = (quotesCount % 2 == 0) as Bool + if currentIsDelimiter && boundingCountIsZero && hasEvenQuotes { items.append(item) item = "" i = self.index(i, offsetBy: delimiter.count - 1) } else { - item += self[i.. Any? { switch member { case "name": @@ -38,10 +34,11 @@ public final class AssociatedType: NSObject, SourceryModel, DynamicMemberLookup } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName))") return string } @@ -56,6 +53,8 @@ public final class AssociatedType: NSObject, SourceryModel, DynamicMemberLookup return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -75,7 +74,7 @@ public final class AssociatedType: NSObject, SourceryModel, DynamicMemberLookup /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/AssociatedValue_Linux.swift b/SourceryRuntime/Sources/Linux/AST/AssociatedValue_Linux.swift similarity index 90% rename from SourceryRuntime/Sources/AST/AssociatedValue_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/AssociatedValue_Linux.swift index 8eea4491..195d78a4 100644 --- a/SourceryRuntime/Sources/AST/AssociatedValue_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/AssociatedValue_Linux.swift @@ -4,13 +4,9 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Defines enum case associated value -public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable, DynamicMemberLookup { +public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "externalName": @@ -66,13 +62,14 @@ public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Ty } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "localName = \(String(describing: self.localName)), " - string += "externalName = \(String(describing: self.externalName)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations))" + string.append("localName = \(String(describing: self.localName)), ") + string.append("externalName = \(String(describing: self.externalName)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations))") return string } @@ -90,6 +87,8 @@ public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Ty return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.localName) diff --git a/SourceryRuntime/Sources/AST/ClosureParameter_Linux.swift b/SourceryRuntime/Sources/Linux/AST/ClosureParameter_Linux.swift similarity index 88% rename from SourceryRuntime/Sources/AST/ClosureParameter_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/ClosureParameter_Linux.swift index c5a89a38..30be9be6 100644 --- a/SourceryRuntime/Sources/AST/ClosureParameter_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/ClosureParameter_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil // sourcery: skipDiffing -public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, DynamicMemberLookup { +public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "argumentLabel": @@ -89,6 +85,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, return (labels.nilIfEmpty ?? "_") + typeSuffix } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.argumentLabel) @@ -102,16 +100,17 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "argumentLabel = \(String(describing: self.argumentLabel)), " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "`inout` = \(String(describing: self.`inout`)), " - string += "typeAttributes = \(String(describing: self.typeAttributes)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("argumentLabel = \(String(describing: self.argumentLabel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("`inout` = \(String(describing: self.`inout`)), ") + string.append("typeAttributes = \(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -141,8 +140,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, fatalError() }; self.typeName = typeName self.`inout` = aDecoder.decode(forKey: "`inout`") - self.isVariadic = aDecoder.decode(forKey: "isVariadic") self.type = aDecoder.decode(forKey: "type") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") self.defaultValue = aDecoder.decode(forKey: "defaultValue") guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in @@ -158,8 +157,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, aCoder.encode(self.name, forKey: "name") aCoder.encode(self.typeName, forKey: "typeName") aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.isVariadic, forKey: "isVariadic") aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.isVariadic, forKey: "isVariadic") aCoder.encode(self.defaultValue, forKey: "defaultValue") aCoder.encode(self.annotations, forKey: "annotations") } diff --git a/SourceryRuntime/Sources/AST/EnumCase_Linux.swift b/SourceryRuntime/Sources/Linux/AST/EnumCase_Linux.swift similarity index 89% rename from SourceryRuntime/Sources/AST/EnumCase_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/EnumCase_Linux.swift index fa3349aa..c8577ca7 100644 --- a/SourceryRuntime/Sources/AST/EnumCase_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/EnumCase_Linux.swift @@ -4,13 +4,9 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Defines enum case -public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable, DynamicMemberLookup { +public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "name": @@ -67,15 +63,16 @@ public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "rawValue = \(String(describing: self.rawValue)), " - string += "associatedValues = \(String(describing: self.associatedValues)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "indirect = \(String(describing: self.indirect)), " - string += "hasAssociatedValue = \(String(describing: self.hasAssociatedValue))" + string.append("name = \(String(describing: self.name)), ") + string.append("rawValue = \(String(describing: self.rawValue)), ") + string.append("associatedValues = \(String(describing: self.associatedValues)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("indirect = \(String(describing: self.indirect)), ") + string.append("hasAssociatedValue = \(String(describing: self.hasAssociatedValue))") return string } @@ -94,6 +91,8 @@ public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/Enum_Linux.swift b/SourceryRuntime/Sources/Linux/AST/Enum_Linux.swift similarity index 94% rename from SourceryRuntime/Sources/AST/Enum_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/Enum_Linux.swift index 3c9935e2..5bd2f6e2 100644 --- a/SourceryRuntime/Sources/AST/Enum_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/Enum_Linux.swift @@ -101,12 +101,13 @@ public final class Enum: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "cases = \(String(describing: self.cases)), " - string += "rawTypeName = \(String(describing: self.rawTypeName)), " - string += "hasAssociatedValues = \(String(describing: self.hasAssociatedValues))" + string.append(", ") + string.append("cases = \(String(describing: self.cases)), ") + string.append("rawTypeName = \(String(describing: self.rawTypeName)), ") + string.append("hasAssociatedValues = \(String(describing: self.hasAssociatedValues))") return string } @@ -122,6 +123,8 @@ public final class Enum: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.cases) diff --git a/SourceryRuntime/Sources/AST/GenericParameter_Linux.swift b/SourceryRuntime/Sources/Linux/AST/GenericParameter_Linux.swift similarity index 88% rename from SourceryRuntime/Sources/AST/GenericParameter_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/GenericParameter_Linux.swift index a058edd0..86ef566b 100644 --- a/SourceryRuntime/Sources/AST/GenericParameter_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/GenericParameter_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Descibes Swift generic parameter -public final class GenericParameter: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +public final class GenericParameter: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "name": @@ -31,10 +27,11 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable, DynamicM } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "inheritedTypeName = \(String(describing: self.inheritedTypeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("inheritedTypeName = \(String(describing: self.inheritedTypeName))") return string } @@ -49,6 +46,8 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable, DynamicM return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -68,7 +67,7 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable, DynamicM /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/GenericRequirement_Linux.swift b/SourceryRuntime/Sources/Linux/AST/GenericRequirement_Linux.swift similarity index 88% rename from SourceryRuntime/Sources/AST/GenericRequirement_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/GenericRequirement_Linux.swift index 394252c5..bd1ae461 100644 --- a/SourceryRuntime/Sources/AST/GenericRequirement_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/GenericRequirement_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Descibes Swift generic requirement -public class GenericRequirement: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +public class GenericRequirement: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "leftType": @@ -53,12 +49,13 @@ public class GenericRequirement: NSObject, SourceryModel, Diffable, DynamicMembe } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "leftType = \(String(describing: self.leftType)), " - string += "rightType = \(String(describing: self.rightType)), " - string += "relationship = \(String(describing: self.relationship)), " - string += "relationshipSyntax = \(String(describing: self.relationshipSyntax))" + string.append("leftType = \(String(describing: self.leftType)), ") + string.append("rightType = \(String(describing: self.rightType)), ") + string.append("relationship = \(String(describing: self.relationship)), ") + string.append("relationshipSyntax = \(String(describing: self.relationshipSyntax))") return string } @@ -75,6 +72,8 @@ public class GenericRequirement: NSObject, SourceryModel, Diffable, DynamicMembe return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.leftType) @@ -98,25 +97,25 @@ public class GenericRequirement: NSObject, SourceryModel, Diffable, DynamicMembe /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { + guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { withVaList(["leftType"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.leftType = leftType - guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { + guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { withVaList(["rightType"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.rightType = rightType - guard let relationship: String = aDecoder.decode(forKey: "relationship") else { + guard let relationship: String = aDecoder.decode(forKey: "relationship") else { withVaList(["relationship"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.relationship = relationship - guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { + guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { withVaList(["relationshipSyntax"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/MethodParameter_Linux.swift b/SourceryRuntime/Sources/Linux/AST/MethodParameter_Linux.swift similarity index 90% rename from SourceryRuntime/Sources/AST/MethodParameter_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/MethodParameter_Linux.swift index 3b7d3dd6..496c232b 100644 --- a/SourceryRuntime/Sources/AST/MethodParameter_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/MethodParameter_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Describes method parameter -public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable, DynamicMemberLookup { +public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "argumentLabel": @@ -97,17 +93,18 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "argumentLabel = \(String(describing: self.argumentLabel)), " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "`inout` = \(String(describing: self.`inout`)), " - string += "isVariadic = \(String(describing: self.isVariadic)), " - string += "typeAttributes = \(String(describing: self.typeAttributes)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("argumentLabel = \(String(describing: self.argumentLabel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("`inout` = \(String(describing: self.`inout`)), ") + string.append("isVariadic = \(String(describing: self.isVariadic)), ") + string.append("typeAttributes = \(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -127,6 +124,8 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.argumentLabel) diff --git a/SourceryRuntime/Sources/AST/Method_Linux.swift b/SourceryRuntime/Sources/Linux/AST/Method_Linux.swift similarity index 92% rename from SourceryRuntime/Sources/AST/Method_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/Method_Linux.swift index 0a46d4f7..1181215a 100644 --- a/SourceryRuntime/Sources/AST/Method_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/Method_Linux.swift @@ -1,15 +1,11 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// :nodoc: public typealias SourceryMethod = Method /// Describes method -public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, DynamicMemberLookup { +public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "definedInType": @@ -256,25 +252,26 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "selectorName = \(String(describing: self.selectorName)), " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "`rethrows` = \(String(describing: self.`rethrows`)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "isStatic = \(String(describing: self.isStatic)), " - string += "isClass = \(String(describing: self.isClass)), " - string += "isFailableInitializer = \(String(describing: self.isFailableInitializer)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers))" - string += "genericRequirements = \(String(describing: self.genericRequirements))" + string.append("name = \(String(describing: self.name)), ") + string.append("selectorName = \(String(describing: self.selectorName)), ") + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("`rethrows` = \(String(describing: self.`rethrows`)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("isStatic = \(String(describing: self.isStatic)), ") + string.append("isClass = \(String(describing: self.isClass)), ") + string.append("isFailableInitializer = \(String(describing: self.isFailableInitializer)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers))") + string.append("genericRequirements = \(String(describing: self.genericRequirements))") return string } @@ -304,6 +301,8 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -416,7 +415,7 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin } fatalError() }; self.modifiers = modifiers - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/Subscript_Linux.swift b/SourceryRuntime/Sources/Linux/AST/Subscript_Linux.swift similarity index 88% rename from SourceryRuntime/Sources/AST/Subscript_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/Subscript_Linux.swift index c65241fe..bb3ebcf3 100644 --- a/SourceryRuntime/Sources/AST/Subscript_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/Subscript_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Describes subscript -public final class Subscript: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, DynamicMemberLookup { +public final class Subscript: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { @@ -186,26 +182,27 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.throws)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), " - string += "genericParameters = \(String(describing: self.genericParameters)), " - string += "genericRequirements = \(String(describing: self.genericRequirements)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers))" + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), ") + string.append("isFinal = \(String(describing: self.isFinal)), ") + string.append("readAccess = \(String(describing: self.readAccess)), ") + string.append("writeAccess = \(String(describing: self.writeAccess)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.throws)), ") + string.append("isMutable = \(String(describing: self.isMutable)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), ") + string.append("genericParameters = \(String(describing: self.genericParameters)), ") + string.append("genericRequirements = \(String(describing: self.genericRequirements)), ") + string.append("isGeneric = \(String(describing: self.isGeneric)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers))") return string } @@ -231,6 +228,8 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.parameters) @@ -272,71 +271,71 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { withVaList(["parameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { withVaList(["returnTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.returnTypeName = returnTypeName self.returnType = aDecoder.decode(forKey: "returnType") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { withVaList(["writeAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.writeAccess = writeAccess - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers - guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { + guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { withVaList(["genericParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericParameters = genericParameters - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + }; self.genericParameters = genericParameters + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericRequirements = genericRequirements + }; self.genericRequirements = genericRequirements } /// :nodoc: @@ -352,10 +351,10 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De aCoder.encode(self.documentation, forKey: "documentation") aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.genericParameters, forKey: "genericParameters") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericParameters, forKey: "genericParameters") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") } // sourcery:end diff --git a/SourceryRuntime/Sources/AST/TypeName/Closure_Linux.swift b/SourceryRuntime/Sources/Linux/AST/TypeName/Closure_Linux.swift similarity index 90% rename from SourceryRuntime/Sources/AST/TypeName/Closure_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/TypeName/Closure_Linux.swift index bbdfae16..651a6f96 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Closure_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/TypeName/Closure_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil -/// Describes closure type -public final class ClosureType: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +/// Describes closure type +public final class ClosureType: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "name": @@ -102,17 +98,18 @@ public final class ClosureType: NSObject, SourceryModel, Diffable, DynamicMember } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "asyncKeyword = \(String(describing: self.asyncKeyword)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "throwsOrRethrowsKeyword = \(String(describing: self.throwsOrRethrowsKeyword)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("asyncKeyword = \(String(describing: self.asyncKeyword)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("throwsOrRethrowsKeyword = \(String(describing: self.throwsOrRethrowsKeyword)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -132,6 +129,8 @@ public final class ClosureType: NSObject, SourceryModel, Diffable, DynamicMember return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter_Linux.swift b/SourceryRuntime/Sources/Linux/AST/TypeName/GenericTypeParameter_Linux.swift similarity index 89% rename from SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/TypeName/GenericTypeParameter_Linux.swift index 4cc8badb..0fc1e881 100644 --- a/SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/TypeName/GenericTypeParameter_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Descibes Swift generic type parameter -public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "typeName": @@ -32,9 +28,10 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, Dyna } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "typeName = \(String(describing: self.typeName))" + string.append("typeName = \(String(describing: self.typeName))") return string } @@ -48,6 +45,8 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, Dyna return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.typeName) @@ -65,7 +64,7 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, Dyna /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/TypeName/Tuple_Linux.swift b/SourceryRuntime/Sources/Linux/AST/TypeName/Tuple_Linux.swift similarity index 91% rename from SourceryRuntime/Sources/AST/TypeName/Tuple_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/TypeName/Tuple_Linux.swift index e1ed0fd8..eb3fbe22 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Tuple_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/TypeName/Tuple_Linux.swift @@ -1,12 +1,8 @@ #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Describes tuple type -public final class TupleType: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +public final class TupleType: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "elements": @@ -35,10 +31,11 @@ public final class TupleType: NSObject, SourceryModel, Diffable, DynamicMemberLo } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "elements = \(String(describing: self.elements))" + string.append("name = \(String(describing: self.name)), ") + string.append("elements = \(String(describing: self.elements))") return string } @@ -53,6 +50,8 @@ public final class TupleType: NSObject, SourceryModel, Diffable, DynamicMemberLo return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -95,7 +94,7 @@ public final class TupleType: NSObject, SourceryModel, Diffable, DynamicMemberLo } /// Describes tuple type element -public final class TupleElement: NSObject, SourceryModel, Typed, Diffable, DynamicMemberLookup { +public final class TupleElement: NSObject, SourceryModel, Typed, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "name": @@ -132,11 +131,12 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable, Dynam } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -151,6 +151,8 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable, Dynam return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/TypeName_Linux.swift b/SourceryRuntime/Sources/Linux/AST/TypeName/TypeName_Linux.swift similarity index 98% rename from SourceryRuntime/Sources/AST/TypeName/TypeName_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/TypeName/TypeName_Linux.swift index 46adab4e..1b7308ae 100644 --- a/SourceryRuntime/Sources/AST/TypeName/TypeName_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/TypeName/TypeName_Linux.swift @@ -4,13 +4,9 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// Describes name of the type used in typed declaration (variable, method parameter or return value etc.) -public final class TypeName: NSObject, SourceryModelWithoutDescription, LosslessStringConvertible, Diffable, DynamicMemberLookup { +public final class TypeName: NSObject, SourceryModelWithoutDescription, LosslessStringConvertible, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "tuple": @@ -225,6 +221,8 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/Type_Linux.swift b/SourceryRuntime/Sources/Linux/AST/Type_Linux.swift similarity index 92% rename from SourceryRuntime/Sources/AST/Type_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/Type_Linux.swift index 620a5a67..e007a4f2 100644 --- a/SourceryRuntime/Sources/AST/Type_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/Type_Linux.swift @@ -4,16 +4,12 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// :nodoc: public typealias AttributeList = [String: [Attribute]] /// Defines Swift type -public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, DynamicMemberLookup { +public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "implements": @@ -473,41 +469,42 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, Dyn } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "module = \(String(describing: self.module)), " - string += "imports = \(String(describing: self.imports)), " - string += "allImports = \(String(describing: self.allImports)), " - string += "typealiases = \(String(describing: self.typealiases)), " - string += "isExtension = \(String(describing: self.isExtension)), " - string += "kind = \(String(describing: self.kind)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "name = \(String(describing: self.name)), " - string += "isUnknownExtension = \(String(describing: self.isUnknownExtension)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "localName = \(String(describing: self.localName)), " - string += "rawVariables = \(String(describing: self.rawVariables)), " - string += "rawMethods = \(String(describing: self.rawMethods)), " - string += "rawSubscripts = \(String(describing: self.rawSubscripts)), " - string += "initializers = \(String(describing: self.initializers)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "staticVariables = \(String(describing: self.staticVariables)), " - string += "staticMethods = \(String(describing: self.staticMethods)), " - string += "classMethods = \(String(describing: self.classMethods)), " - string += "instanceVariables = \(String(describing: self.instanceVariables)), " - string += "instanceMethods = \(String(describing: self.instanceMethods)), " - string += "computedVariables = \(String(describing: self.computedVariables)), " - string += "storedVariables = \(String(describing: self.storedVariables)), " - string += "inheritedTypes = \(String(describing: self.inheritedTypes)), " - string += "inherits = \(String(describing: self.inherits)), " - string += "containedTypes = \(String(describing: self.containedTypes)), " - string += "parentName = \(String(describing: self.parentName)), " - string += "parentTypes = \(String(describing: self.parentTypes)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers)), " - string += "fileName = \(String(describing: self.fileName)), " - string += "genericRequirements = \(String(describing: self.genericRequirements))" + string.append("module = \(String(describing: self.module)), ") + string.append("imports = \(String(describing: self.imports)), ") + string.append("allImports = \(String(describing: self.allImports)), ") + string.append("typealiases = \(String(describing: self.typealiases)), ") + string.append("isExtension = \(String(describing: self.isExtension)), ") + string.append("kind = \(String(describing: self.kind)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("isUnknownExtension = \(String(describing: self.isUnknownExtension)), ") + string.append("isGeneric = \(String(describing: self.isGeneric)), ") + string.append("localName = \(String(describing: self.localName)), ") + string.append("rawVariables = \(String(describing: self.rawVariables)), ") + string.append("rawMethods = \(String(describing: self.rawMethods)), ") + string.append("rawSubscripts = \(String(describing: self.rawSubscripts)), ") + string.append("initializers = \(String(describing: self.initializers)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("staticVariables = \(String(describing: self.staticVariables)), ") + string.append("staticMethods = \(String(describing: self.staticMethods)), ") + string.append("classMethods = \(String(describing: self.classMethods)), ") + string.append("instanceVariables = \(String(describing: self.instanceVariables)), ") + string.append("instanceMethods = \(String(describing: self.instanceMethods)), ") + string.append("computedVariables = \(String(describing: self.computedVariables)), ") + string.append("storedVariables = \(String(describing: self.storedVariables)), ") + string.append("inheritedTypes = \(String(describing: self.inheritedTypes)), ") + string.append("inherits = \(String(describing: self.inherits)), ") + string.append("containedTypes = \(String(describing: self.containedTypes)), ") + string.append("parentName = \(String(describing: self.parentName)), ") + string.append("parentTypes = \(String(describing: self.parentTypes)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers)), ") + string.append("fileName = \(String(describing: self.fileName)), ") + string.append("genericRequirements = \(String(describing: self.genericRequirements))") return string } @@ -541,6 +538,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, Dyn return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.module) @@ -621,13 +620,7 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, Dyn fatalError() }; self.accessLevel = accessLevel self.isGeneric = aDecoder.decode(forKey: "isGeneric") - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - guard let localName: String = aDecoder.decode(forKey: "localName") else { + guard let localName: String = aDecoder.decode(forKey: "localName") else { withVaList(["localName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -723,6 +716,12 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, Dyn fatalError() }; self.modifiers = modifiers self.path = aDecoder.decode(forKey: "path") + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements self.fileName = aDecoder.decode(forKey: "fileName") } @@ -755,8 +754,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, Dyn aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") aCoder.encode(self.path, forKey: "path") - aCoder.encode(self.fileName, forKey: "fileName") aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + aCoder.encode(self.fileName, forKey: "fileName") } // sourcery:end diff --git a/SourceryRuntime/Sources/AST/Variable_Linux.swift b/SourceryRuntime/Sources/Linux/AST/Variable_Linux.swift similarity index 89% rename from SourceryRuntime/Sources/AST/Variable_Linux.swift rename to SourceryRuntime/Sources/Linux/AST/Variable_Linux.swift index 95a899d5..a3924997 100644 --- a/SourceryRuntime/Sources/AST/Variable_Linux.swift +++ b/SourceryRuntime/Sources/Linux/AST/Variable_Linux.swift @@ -4,16 +4,12 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// :nodoc: public typealias SourceryVariable = Variable /// Defines variable -public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable, DynamicMemberLookup { +public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "readAccess": @@ -165,28 +161,29 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "isComputed = \(String(describing: self.isComputed)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "isStatic = \(String(describing: self.isStatic)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "isLazy = \(String(describing: self.isLazy)), " - string += "isDynamic = \(String(describing: self.isDynamic)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("isComputed = \(String(describing: self.isComputed)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("isStatic = \(String(describing: self.isStatic)), ") + string.append("readAccess = \(String(describing: self.readAccess)), ") + string.append("writeAccess = \(String(describing: self.writeAccess)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("isMutable = \(String(describing: self.isMutable)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers)), ") + string.append("isFinal = \(String(describing: self.isFinal)), ") + string.append("isLazy = \(String(describing: self.isLazy)), ") + string.append("isDynamic = \(String(describing: self.isDynamic)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName))") return string } @@ -213,6 +210,8 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/Linux/DynamicMemberLookup_Linux.swift b/SourceryRuntime/Sources/Linux/DynamicMemberLookup_Linux.swift new file mode 100644 index 00000000..4b086512 --- /dev/null +++ b/SourceryRuntime/Sources/Linux/DynamicMemberLookup_Linux.swift @@ -0,0 +1,37 @@ +// +// Stencil +// Copyright © 2022 Stencil +// MIT Licence +// + +#if !canImport(ObjectiveC) +#if canImport(Stencil) +import Stencil +#else +// This is not supposed to work at all, since in Stencil there is a protocol conformance check against `DynamicMemberLookup`, +// and, of course, a substitute with the "same name" but in `Sourcery` will never satisfy that check. +// Here, we are just mimicking `Stencil.DynamicMemberLookup` to showcase what is happening within the `Sourcery` during runtime. + +/// Marker protocol so we can know which types support `@dynamicMemberLookup`. Add this to your own types that support +/// lookup by String. +public protocol DynamicMemberLookup { + /// Get a value for a given `String` key + subscript(dynamicMember member: String) -> Any? { get } +} + +public extension DynamicMemberLookup where Self: RawRepresentable { + /// Get a value for a given `String` key + subscript(dynamicMember member: String) -> Any? { + switch member { + case "rawValue": + return rawValue + default: + return nil + } + } +} +#endif + +public protocol SourceryDynamicMemberLookup: DynamicMemberLookup {} + +#endif diff --git a/SourceryRuntime/Sources/AST/NSException_Linux.swift b/SourceryRuntime/Sources/Linux/NSException_Linux.swift similarity index 100% rename from SourceryRuntime/Sources/AST/NSException_Linux.swift rename to SourceryRuntime/Sources/Linux/NSException_Linux.swift diff --git a/SourceryRuntime/Sources/TypesCollection_Linux.swift b/SourceryRuntime/Sources/Linux/TypesCollection_Linux.swift similarity index 89% rename from SourceryRuntime/Sources/TypesCollection_Linux.swift rename to SourceryRuntime/Sources/Linux/TypesCollection_Linux.swift index d1a7b371..a5ff674b 100644 --- a/SourceryRuntime/Sources/TypesCollection_Linux.swift +++ b/SourceryRuntime/Sources/Linux/TypesCollection_Linux.swift @@ -4,13 +4,9 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil /// :nodoc: -public class TypesCollection: NSObject, AutoJSExport, DynamicMemberLookup { +public class TypesCollection: NSObject, AutoJSExport, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { return try? types(forKey: member) } diff --git a/SourceryRuntime/Sources/Types_Linux.swift b/SourceryRuntime/Sources/Linux/Types_Linux.swift similarity index 94% rename from SourceryRuntime/Sources/Types_Linux.swift rename to SourceryRuntime/Sources/Linux/Types_Linux.swift index fd5b1b45..b5d93c26 100644 --- a/SourceryRuntime/Sources/Types_Linux.swift +++ b/SourceryRuntime/Sources/Linux/Types_Linux.swift @@ -4,14 +4,10 @@ // #if !canImport(ObjectiveC) import Foundation -// For DynamicMemberLookup we need to import Stencil, -// however, this is different from SourceryRuntime.content.generated.swift, because -// it cannot reference Stencil -import Stencil // sourcery: skipJSExport /// Collection of scanned types for accessing in templates -public final class Types: NSObject, SourceryModel, Diffable, DynamicMemberLookup { +public final class Types: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "types": @@ -52,10 +48,11 @@ public final class Types: NSObject, SourceryModel, Diffable, DynamicMemberLookup } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "types = \(String(describing: self.types)), " - string += "typealiases = \(String(describing: self.typealiases))" + string.append("types = \(String(describing: self.types)), ") + string.append("typealiases = \(String(describing: self.typealiases))") return string } @@ -70,6 +67,8 @@ public final class Types: NSObject, SourceryModel, Diffable, DynamicMemberLookup return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.types) diff --git a/SourceryRuntime/Sources/AST/AssociatedType.swift b/SourceryRuntime/Sources/macOS/AST/AssociatedType.swift similarity index 92% rename from SourceryRuntime/Sources/AST/AssociatedType.swift rename to SourceryRuntime/Sources/macOS/AST/AssociatedType.swift index 0f485d41..51c5ade9 100644 --- a/SourceryRuntime/Sources/AST/AssociatedType.swift +++ b/SourceryRuntime/Sources/macOS/AST/AssociatedType.swift @@ -22,10 +22,11 @@ public final class AssociatedType: NSObject, SourceryModel { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName))") return string } @@ -40,6 +41,8 @@ public final class AssociatedType: NSObject, SourceryModel { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/AssociatedValue.swift b/SourceryRuntime/Sources/macOS/AST/AssociatedValue.swift similarity index 91% rename from SourceryRuntime/Sources/AST/AssociatedValue.swift rename to SourceryRuntime/Sources/macOS/AST/AssociatedValue.swift index be66733e..1fcb2915 100644 --- a/SourceryRuntime/Sources/AST/AssociatedValue.swift +++ b/SourceryRuntime/Sources/macOS/AST/AssociatedValue.swift @@ -45,13 +45,14 @@ public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Ty } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "localName = \(String(describing: self.localName)), " - string += "externalName = \(String(describing: self.externalName)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations))" + string.append("localName = \(String(describing: self.localName)), ") + string.append("externalName = \(String(describing: self.externalName)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations))") return string } @@ -69,6 +70,8 @@ public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Ty return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.localName) diff --git a/SourceryRuntime/Sources/AST/ClosureParameter.swift b/SourceryRuntime/Sources/macOS/AST/ClosureParameter.swift similarity index 88% rename from SourceryRuntime/Sources/AST/ClosureParameter.swift rename to SourceryRuntime/Sources/macOS/AST/ClosureParameter.swift index 5cf19415..57e4203b 100644 --- a/SourceryRuntime/Sources/AST/ClosureParameter.swift +++ b/SourceryRuntime/Sources/macOS/AST/ClosureParameter.swift @@ -66,6 +66,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { return (labels.nilIfEmpty ?? "_") + typeSuffix } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.argumentLabel) @@ -79,16 +81,17 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "argumentLabel = \(String(describing: self.argumentLabel)), " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "`inout` = \(String(describing: self.`inout`)), " - string += "typeAttributes = \(String(describing: self.typeAttributes)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("argumentLabel = \(String(describing: self.argumentLabel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("`inout` = \(String(describing: self.`inout`)), ") + string.append("typeAttributes = \(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -118,8 +121,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { fatalError() }; self.typeName = typeName self.`inout` = aDecoder.decode(forKey: "`inout`") - self.isVariadic = aDecoder.decode(forKey: "isVariadic") self.type = aDecoder.decode(forKey: "type") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") self.defaultValue = aDecoder.decode(forKey: "defaultValue") guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in @@ -135,8 +138,8 @@ public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { aCoder.encode(self.name, forKey: "name") aCoder.encode(self.typeName, forKey: "typeName") aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.isVariadic, forKey: "isVariadic") aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.isVariadic, forKey: "isVariadic") aCoder.encode(self.defaultValue, forKey: "defaultValue") aCoder.encode(self.annotations, forKey: "annotations") } diff --git a/SourceryRuntime/Sources/AST/Enum.swift b/SourceryRuntime/Sources/macOS/AST/Enum.swift similarity index 94% rename from SourceryRuntime/Sources/AST/Enum.swift rename to SourceryRuntime/Sources/macOS/AST/Enum.swift index 10b59c0d..da43ffa1 100644 --- a/SourceryRuntime/Sources/AST/Enum.swift +++ b/SourceryRuntime/Sources/macOS/AST/Enum.swift @@ -91,12 +91,13 @@ public final class Enum: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "cases = \(String(describing: self.cases)), " - string += "rawTypeName = \(String(describing: self.rawTypeName)), " - string += "hasAssociatedValues = \(String(describing: self.hasAssociatedValues))" + string.append(", ") + string.append("cases = \(String(describing: self.cases)), ") + string.append("rawTypeName = \(String(describing: self.rawTypeName)), ") + string.append("hasAssociatedValues = \(String(describing: self.hasAssociatedValues))") return string } @@ -112,6 +113,8 @@ public final class Enum: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.cases) diff --git a/SourceryRuntime/Sources/AST/EnumCase.swift b/SourceryRuntime/Sources/macOS/AST/EnumCase.swift similarity index 90% rename from SourceryRuntime/Sources/AST/EnumCase.swift rename to SourceryRuntime/Sources/macOS/AST/EnumCase.swift index b8d4ffd9..8b522ea2 100644 --- a/SourceryRuntime/Sources/AST/EnumCase.swift +++ b/SourceryRuntime/Sources/macOS/AST/EnumCase.swift @@ -47,15 +47,16 @@ public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "rawValue = \(String(describing: self.rawValue)), " - string += "associatedValues = \(String(describing: self.associatedValues)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "indirect = \(String(describing: self.indirect)), " - string += "hasAssociatedValue = \(String(describing: self.hasAssociatedValue))" + string.append("name = \(String(describing: self.name)), ") + string.append("rawValue = \(String(describing: self.rawValue)), ") + string.append("associatedValues = \(String(describing: self.associatedValues)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("indirect = \(String(describing: self.indirect)), ") + string.append("hasAssociatedValue = \(String(describing: self.hasAssociatedValue))") return string } @@ -74,6 +75,8 @@ public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/GenericParameter.swift b/SourceryRuntime/Sources/macOS/AST/GenericParameter.swift similarity index 91% rename from SourceryRuntime/Sources/AST/GenericParameter.swift rename to SourceryRuntime/Sources/macOS/AST/GenericParameter.swift index 457fb6bd..d1a1aa73 100644 --- a/SourceryRuntime/Sources/AST/GenericParameter.swift +++ b/SourceryRuntime/Sources/macOS/AST/GenericParameter.swift @@ -18,10 +18,11 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "inheritedTypeName = \(String(describing: self.inheritedTypeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("inheritedTypeName = \(String(describing: self.inheritedTypeName))") return string } @@ -36,6 +37,8 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -55,7 +58,7 @@ public final class GenericParameter: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/GenericRequirement.swift b/SourceryRuntime/Sources/macOS/AST/GenericRequirement.swift similarity index 92% rename from SourceryRuntime/Sources/AST/GenericRequirement.swift rename to SourceryRuntime/Sources/macOS/AST/GenericRequirement.swift index 97fa99fd..9507e210 100644 --- a/SourceryRuntime/Sources/AST/GenericRequirement.swift +++ b/SourceryRuntime/Sources/macOS/AST/GenericRequirement.swift @@ -36,12 +36,13 @@ public class GenericRequirement: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "leftType = \(String(describing: self.leftType)), " - string += "rightType = \(String(describing: self.rightType)), " - string += "relationship = \(String(describing: self.relationship)), " - string += "relationshipSyntax = \(String(describing: self.relationshipSyntax))" + string.append("leftType = \(String(describing: self.leftType)), ") + string.append("rightType = \(String(describing: self.rightType)), ") + string.append("relationship = \(String(describing: self.relationship)), ") + string.append("relationshipSyntax = \(String(describing: self.relationshipSyntax))") return string } @@ -58,6 +59,8 @@ public class GenericRequirement: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.leftType) diff --git a/SourceryRuntime/Sources/AST/Method.swift b/SourceryRuntime/Sources/macOS/AST/Method.swift similarity index 92% rename from SourceryRuntime/Sources/AST/Method.swift rename to SourceryRuntime/Sources/macOS/AST/Method.swift index 28f0a9d3..068cf8c9 100644 --- a/SourceryRuntime/Sources/AST/Method.swift +++ b/SourceryRuntime/Sources/macOS/AST/Method.swift @@ -213,25 +213,26 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "selectorName = \(String(describing: self.selectorName)), " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "`rethrows` = \(String(describing: self.`rethrows`)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "isStatic = \(String(describing: self.isStatic)), " - string += "isClass = \(String(describing: self.isClass)), " - string += "isFailableInitializer = \(String(describing: self.isFailableInitializer)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers)), " - string += "genericRequirements = \(String(describing: self.genericRequirements))" + string.append("name = \(String(describing: self.name)), ") + string.append("selectorName = \(String(describing: self.selectorName)), ") + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("`rethrows` = \(String(describing: self.`rethrows`)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("isStatic = \(String(describing: self.isStatic)), ") + string.append("isClass = \(String(describing: self.isClass)), ") + string.append("isFailableInitializer = \(String(describing: self.isFailableInitializer)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers)), ") + string.append("genericRequirements = \(String(describing: self.genericRequirements))") return string } @@ -261,6 +262,8 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -373,7 +376,7 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin } fatalError() }; self.modifiers = modifiers - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/MethodParameter.swift b/SourceryRuntime/Sources/macOS/AST/MethodParameter.swift similarity index 87% rename from SourceryRuntime/Sources/AST/MethodParameter.swift rename to SourceryRuntime/Sources/macOS/AST/MethodParameter.swift index 0ddaa172..6f15b377 100644 --- a/SourceryRuntime/Sources/AST/MethodParameter.swift +++ b/SourceryRuntime/Sources/macOS/AST/MethodParameter.swift @@ -61,7 +61,10 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl } public var asSource: String { - let typeSuffix = ": \(`inout` ? "inout " : "")\(typeName.asSource)\(defaultValue.map { " = \($0)" } ?? "")" + (isVariadic ? "..." : "") + let values: String = defaultValue.map { " = \($0)" } ?? "" + let variadicity: String = isVariadic ? "..." : "" + let inoutness: String = `inout` ? "inout " : "" + let typeSuffix = ": \(inoutness)\(typeName.asSource)\(values)\(variadicity)" guard argumentLabel != name else { return name + typeSuffix } @@ -74,17 +77,18 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "argumentLabel = \(String(describing: self.argumentLabel)), " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "`inout` = \(String(describing: self.`inout`)), " - string += "isVariadic = \(String(describing: self.isVariadic)), " - string += "typeAttributes = \(String(describing: self.typeAttributes)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("argumentLabel = \(String(describing: self.argumentLabel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("`inout` = \(String(describing: self.`inout`)), ") + string.append("isVariadic = \(String(describing: self.isVariadic)), ") + string.append("typeAttributes = \(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -104,6 +108,8 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.argumentLabel) diff --git a/SourceryRuntime/Sources/AST/Subscript.swift b/SourceryRuntime/Sources/macOS/AST/Subscript.swift similarity index 87% rename from SourceryRuntime/Sources/AST/Subscript.swift rename to SourceryRuntime/Sources/macOS/AST/Subscript.swift index 3eb29ab3..658bab6e 100644 --- a/SourceryRuntime/Sources/AST/Subscript.swift +++ b/SourceryRuntime/Sources/macOS/AST/Subscript.swift @@ -131,26 +131,27 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.throws)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), " - string += "genericParameters = \(String(describing: self.genericParameters)), " - string += "genericRequirements = \(String(describing: self.genericRequirements)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers))" + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), ") + string.append("isFinal = \(String(describing: self.isFinal)), ") + string.append("readAccess = \(String(describing: self.readAccess)), ") + string.append("writeAccess = \(String(describing: self.writeAccess)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.throws)), ") + string.append("isMutable = \(String(describing: self.isMutable)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), ") + string.append("genericParameters = \(String(describing: self.genericParameters)), ") + string.append("genericRequirements = \(String(describing: self.genericRequirements)), ") + string.append("isGeneric = \(String(describing: self.isGeneric)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers))") return string } @@ -176,6 +177,8 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.parameters) @@ -217,71 +220,71 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { withVaList(["parameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { withVaList(["returnTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.returnTypeName = returnTypeName self.returnType = aDecoder.decode(forKey: "returnType") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { withVaList(["writeAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.writeAccess = writeAccess - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers - guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { + guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { withVaList(["genericParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericParameters = genericParameters - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + }; self.genericParameters = genericParameters + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericRequirements = genericRequirements + }; self.genericRequirements = genericRequirements } /// :nodoc: @@ -297,10 +300,10 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De aCoder.encode(self.documentation, forKey: "documentation") aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.genericParameters, forKey: "genericParameters") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericParameters, forKey: "genericParameters") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") } // sourcery:end diff --git a/SourceryRuntime/Sources/AST/Type.swift b/SourceryRuntime/Sources/macOS/AST/Type.swift similarity index 91% rename from SourceryRuntime/Sources/AST/Type.swift rename to SourceryRuntime/Sources/macOS/AST/Type.swift index 2ad38cee..adf292bd 100644 --- a/SourceryRuntime/Sources/AST/Type.swift +++ b/SourceryRuntime/Sources/macOS/AST/Type.swift @@ -4,7 +4,6 @@ // #if canImport(ObjectiveC) import Foundation -import Stencil /// :nodoc: public typealias AttributeList = [String: [Attribute]] @@ -426,41 +425,43 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { - var string = "\(Swift.type(of: self)): " - string += "module = \(String(describing: self.module)), " - string += "imports = \(String(describing: self.imports)), " - string += "allImports = \(String(describing: self.allImports)), " - string += "typealiases = \(String(describing: self.typealiases)), " - string += "isExtension = \(String(describing: self.isExtension)), " - string += "kind = \(String(describing: self.kind)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "name = \(String(describing: self.name)), " - string += "isUnknownExtension = \(String(describing: self.isUnknownExtension)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "localName = \(String(describing: self.localName)), " - string += "rawVariables = \(String(describing: self.rawVariables)), " - string += "rawMethods = \(String(describing: self.rawMethods)), " - string += "rawSubscripts = \(String(describing: self.rawSubscripts)), " - string += "initializers = \(String(describing: self.initializers)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "staticVariables = \(String(describing: self.staticVariables)), " - string += "staticMethods = \(String(describing: self.staticMethods)), " - string += "classMethods = \(String(describing: self.classMethods)), " - string += "instanceVariables = \(String(describing: self.instanceVariables)), " - string += "instanceMethods = \(String(describing: self.instanceMethods)), " - string += "computedVariables = \(String(describing: self.computedVariables)), " - string += "storedVariables = \(String(describing: self.storedVariables)), " - string += "inheritedTypes = \(String(describing: self.inheritedTypes)), " - string += "inherits = \(String(describing: self.inherits)), " - string += "containedTypes = \(String(describing: self.containedTypes)), " - string += "parentName = \(String(describing: self.parentName)), " - string += "parentTypes = \(String(describing: self.parentTypes)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers)), " - string += "fileName = \(String(describing: self.fileName)), " - string += "genericRequirements = \(String(describing: self.genericRequirements))" + let type: Type.Type = Swift.type(of: self) + var string = "\(type): " + string.append("module = \(String(describing: self.module)), ") + string.append("imports = \(String(describing: self.imports)), ") + string.append("allImports = \(String(describing: self.allImports)), ") + string.append("typealiases = \(String(describing: self.typealiases)), ") + string.append("isExtension = \(String(describing: self.isExtension)), ") + string.append("kind = \(String(describing: self.kind)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("name = \(String(describing: self.name)), ") + string.append("isUnknownExtension = \(String(describing: self.isUnknownExtension)), ") + string.append("isGeneric = \(String(describing: self.isGeneric)), ") + string.append("localName = \(String(describing: self.localName)), ") + string.append("rawVariables = \(String(describing: self.rawVariables)), ") + string.append("rawMethods = \(String(describing: self.rawMethods)), ") + string.append("rawSubscripts = \(String(describing: self.rawSubscripts)), ") + string.append("initializers = \(String(describing: self.initializers)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("staticVariables = \(String(describing: self.staticVariables)), ") + string.append("staticMethods = \(String(describing: self.staticMethods)), ") + string.append("classMethods = \(String(describing: self.classMethods)), ") + string.append("instanceVariables = \(String(describing: self.instanceVariables)), ") + string.append("instanceMethods = \(String(describing: self.instanceMethods)), ") + string.append("computedVariables = \(String(describing: self.computedVariables)), ") + string.append("storedVariables = \(String(describing: self.storedVariables)), ") + string.append("inheritedTypes = \(String(describing: self.inheritedTypes)), ") + string.append("inherits = \(String(describing: self.inherits)), ") + string.append("containedTypes = \(String(describing: self.containedTypes)), ") + string.append("parentName = \(String(describing: self.parentName)), ") + string.append("parentTypes = \(String(describing: self.parentTypes)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers)), ") + string.append("fileName = \(String(describing: self.fileName)), ") + string.append("genericRequirements = \(String(describing: self.genericRequirements))") return string } @@ -494,6 +495,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.module) @@ -574,13 +577,7 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { fatalError() }; self.accessLevel = accessLevel self.isGeneric = aDecoder.decode(forKey: "isGeneric") - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - guard let localName: String = aDecoder.decode(forKey: "localName") else { + guard let localName: String = aDecoder.decode(forKey: "localName") else { withVaList(["localName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -676,6 +673,12 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { fatalError() }; self.modifiers = modifiers self.path = aDecoder.decode(forKey: "path") + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements self.fileName = aDecoder.decode(forKey: "fileName") } @@ -708,8 +711,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") aCoder.encode(self.path, forKey: "path") - aCoder.encode(self.fileName, forKey: "fileName") aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + aCoder.encode(self.fileName, forKey: "fileName") } // sourcery:end diff --git a/SourceryRuntime/Sources/AST/TypeName/Closure.swift b/SourceryRuntime/Sources/macOS/AST/TypeName/Closure.swift similarity index 89% rename from SourceryRuntime/Sources/AST/TypeName/Closure.swift rename to SourceryRuntime/Sources/macOS/AST/TypeName/Closure.swift index d01e9770..af6bd0b6 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Closure.swift +++ b/SourceryRuntime/Sources/macOS/AST/TypeName/Closure.swift @@ -70,17 +70,18 @@ public final class ClosureType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "asyncKeyword = \(String(describing: self.asyncKeyword)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "throwsOrRethrowsKeyword = \(String(describing: self.throwsOrRethrowsKeyword)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("parameters = \(String(describing: self.parameters)), ") + string.append("returnTypeName = \(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("asyncKeyword = \(String(describing: self.asyncKeyword)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("throwsOrRethrowsKeyword = \(String(describing: self.throwsOrRethrowsKeyword)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -100,6 +101,8 @@ public final class ClosureType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter.swift b/SourceryRuntime/Sources/macOS/AST/TypeName/GenericTypeParameter.swift similarity index 92% rename from SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter.swift rename to SourceryRuntime/Sources/macOS/AST/TypeName/GenericTypeParameter.swift index 03839dc0..ea822a6a 100644 --- a/SourceryRuntime/Sources/AST/TypeName/GenericTypeParameter.swift +++ b/SourceryRuntime/Sources/macOS/AST/TypeName/GenericTypeParameter.swift @@ -19,9 +19,10 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "typeName = \(String(describing: self.typeName))" + string.append("typeName = \(String(describing: self.typeName))") return string } @@ -35,6 +36,8 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.typeName) @@ -52,7 +55,7 @@ public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } diff --git a/SourceryRuntime/Sources/AST/TypeName/Tuple.swift b/SourceryRuntime/Sources/macOS/AST/TypeName/Tuple.swift similarity index 92% rename from SourceryRuntime/Sources/AST/TypeName/Tuple.swift rename to SourceryRuntime/Sources/macOS/AST/TypeName/Tuple.swift index 7db544ef..996709bd 100644 --- a/SourceryRuntime/Sources/AST/TypeName/Tuple.swift +++ b/SourceryRuntime/Sources/macOS/AST/TypeName/Tuple.swift @@ -24,10 +24,11 @@ public final class TupleType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "elements = \(String(describing: self.elements))" + string.append("name = \(String(describing: self.name)), ") + string.append("elements = \(String(describing: self.elements))") return string } @@ -42,6 +43,8 @@ public final class TupleType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -110,11 +113,12 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "asSource = \(String(describing: self.asSource))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("asSource = \(String(describing: self.asSource))") return string } @@ -129,6 +133,8 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/TypeName/TypeName.swift b/SourceryRuntime/Sources/macOS/AST/TypeName/TypeName.swift similarity index 91% rename from SourceryRuntime/Sources/AST/TypeName/TypeName.swift rename to SourceryRuntime/Sources/macOS/AST/TypeName/TypeName.swift index 5a7d0f82..9f386ec6 100644 --- a/SourceryRuntime/Sources/AST/TypeName/TypeName.swift +++ b/SourceryRuntime/Sources/macOS/AST/TypeName/TypeName.swift @@ -25,7 +25,9 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless let optionalSuffix: String // TODO: TBR - if !name.hasPrefix("Optional<") && !name.contains(" where ") { + let hasPrefix: Bool = name.hasPrefix("Optional<") as Bool + let containsName: Bool = name.contains(" where ") as Bool + if !hasPrefix && !containsName { if isOptional { optionalSuffix = "?" } else if isImplicitlyUnwrappedOptional { @@ -139,24 +141,25 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless /// Prints typename as it would appear on definition public var asSource: String { // TODO: TBR special treatment - let specialTreatment = isOptional && name.hasPrefix("Optional<") + let specialTreatment: Bool = isOptional && name.hasPrefix("Optional<") - var description = ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [specialTreatment ? name : unwrappedTypeName] - ).joined(separator: " ") + let attributeValues: [Attribute] = attributes.flatMap { $0.value } + let attributeValuesUnsorted: [String] = attributeValues.map { $0.asSource } + var attributes: [String] = attributeValuesUnsorted.sorted() + attributes.append(contentsOf: modifiers.map({ $0.asSource })) + attributes.append(contentsOf: [specialTreatment ? name : unwrappedTypeName]) + var description = attributes.joined(separator: " ") - if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name +// if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name // description.append(dictionary.asSource) - } else if let _ = self.array { +// } else if let _ = self.array { // description.append(array.asSource) - } else if let _ = self.generic { +// } else if let _ = self.generic { // let arguments = generic.typeParameters // .map({ $0.typeName.asSource }) // .joined(separator: ", ") // description.append("<\(arguments)>") - } +// } if !specialTreatment { if isImplicitlyUnwrappedOptional { description.append("!") @@ -169,11 +172,10 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless } public override var description: String { - ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [name] - ).joined(separator: " ") + var description: [String] = attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + description.append(contentsOf: modifiers.map({ $0.asSource })) + description.append(contentsOf: [name]) + return description.joined(separator: " ") } public func diffAgainst(_ object: Any?) -> DiffableResult { @@ -195,6 +197,7 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless return results } + public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/AST/Variable.swift b/SourceryRuntime/Sources/macOS/AST/Variable.swift similarity index 89% rename from SourceryRuntime/Sources/AST/Variable.swift rename to SourceryRuntime/Sources/macOS/AST/Variable.swift index 5f20146f..c20333a9 100644 --- a/SourceryRuntime/Sources/AST/Variable.swift +++ b/SourceryRuntime/Sources/macOS/AST/Variable.swift @@ -4,7 +4,6 @@ // #if canImport(ObjectiveC) import Foundation -import Stencil /// :nodoc: public typealias SourceryVariable = Variable @@ -131,28 +130,29 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "name = \(String(describing: self.name)), " - string += "typeName = \(String(describing: self.typeName)), " - string += "isComputed = \(String(describing: self.isComputed)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.`throws`)), " - string += "isStatic = \(String(describing: self.isStatic)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "accessLevel = \(String(describing: self.accessLevel)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "defaultValue = \(String(describing: self.defaultValue)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "isLazy = \(String(describing: self.isLazy)), " - string += "isDynamic = \(String(describing: self.isDynamic)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName))" + string.append("name = \(String(describing: self.name)), ") + string.append("typeName = \(String(describing: self.typeName)), ") + string.append("isComputed = \(String(describing: self.isComputed)), ") + string.append("isAsync = \(String(describing: self.isAsync)), ") + string.append("`throws` = \(String(describing: self.`throws`)), ") + string.append("isStatic = \(String(describing: self.isStatic)), ") + string.append("readAccess = \(String(describing: self.readAccess)), ") + string.append("writeAccess = \(String(describing: self.writeAccess)), ") + string.append("accessLevel = \(String(describing: self.accessLevel)), ") + string.append("isMutable = \(String(describing: self.isMutable)), ") + string.append("defaultValue = \(String(describing: self.defaultValue)), ") + string.append("annotations = \(String(describing: self.annotations)), ") + string.append("documentation = \(String(describing: self.documentation)), ") + string.append("attributes = \(String(describing: self.attributes)), ") + string.append("modifiers = \(String(describing: self.modifiers)), ") + string.append("isFinal = \(String(describing: self.isFinal)), ") + string.append("isLazy = \(String(describing: self.isLazy)), ") + string.append("isDynamic = \(String(describing: self.isDynamic)), ") + string.append("definedInTypeName = \(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName))") return string } @@ -180,6 +180,8 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) diff --git a/SourceryRuntime/Sources/Types.swift b/SourceryRuntime/Sources/macOS/Types.swift similarity index 96% rename from SourceryRuntime/Sources/Types.swift rename to SourceryRuntime/Sources/macOS/Types.swift index 32bced8c..e10ccb7b 100644 --- a/SourceryRuntime/Sources/Types.swift +++ b/SourceryRuntime/Sources/macOS/Types.swift @@ -24,10 +24,11 @@ public final class Types: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\(Swift.type(of: self)): " - string += "types = \(String(describing: self.types)), " - string += "typealiases = \(String(describing: self.typealiases))" + string.append("types = \(String(describing: self.types)), ") + string.append("typealiases = \(String(describing: self.typealiases))") return string } @@ -42,6 +43,8 @@ public final class Types: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.types) diff --git a/SourceryRuntime/Sources/TypesCollection.swift b/SourceryRuntime/Sources/macOS/TypesCollection.swift similarity index 100% rename from SourceryRuntime/Sources/TypesCollection.swift rename to SourceryRuntime/Sources/macOS/TypesCollection.swift diff --git a/SourcerySwift/Sources/SourceryRuntime.content.generated.swift b/SourcerySwift/Sources/SourceryRuntime.content.generated.swift index 6bb49314..9a250ba8 100644 --- a/SourcerySwift/Sources/SourceryRuntime.content.generated.swift +++ b/SourcerySwift/Sources/SourceryRuntime.content.generated.swift @@ -11,6 +11,7 @@ import Foundation /// :nodoc: public enum AccessLevel: String { + case `package` = "package" case `internal` = "internal" case `private` = "private" case `fileprivate` = "fileprivate" @@ -19,82 +20,6 @@ public enum AccessLevel: String { case none = "" } -"""), - .init(name: "GenericParameter.swift", content: -""" -import Foundation - -/// Descibes Swift generic parameter -@objcMembers -public final class GenericParameter: NSObject, SourceryModel, Diffable { - - /// Generic parameter name - public var name: String - - /// Generic parameter inherited type - public var inheritedTypeName: TypeName? - - /// :nodoc: - public init(name: String, inheritedTypeName: TypeName? = nil) { - self.name = name - self.inheritedTypeName = inheritedTypeName - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "inheritedTypeName = \\(String(describing: self.inheritedTypeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "inheritedTypeName").trackDifference(actual: self.inheritedTypeName, expected: castObject.inheritedTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.inheritedTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericParameter else { return false } - if self.name != rhs.name { return false } - if self.inheritedTypeName != rhs.inheritedTypeName { return false } - return true - } - -// sourcery:inline:GenericParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.inheritedTypeName = aDecoder.decode(forKey: "inheritedTypeName") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.inheritedTypeName, forKey: "inheritedTypeName") - } - -// sourcery:end -} """), .init(name: "Actor.swift", content: """ @@ -102,14 +27,16 @@ import Foundation // sourcery: skipDescription /// Descibes Swift actor +#if canImport(ObjectiveC) @objc(SwiftActor) @objcMembers +#endif public final class Actor: Type { /// Returns "actor" public override var kind: String { return "actor" } /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -152,11 +79,12 @@ public final class Actor: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "isFinal = \\(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("isFinal = \\(String(describing: self.isFinal))") return string } @@ -170,6 +98,8 @@ public final class Actor: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -194,7 +124,7 @@ public final class Actor: Type { super.encode(with: aCoder) } // sourcery:end - + } """), @@ -263,112 +193,15 @@ public extension Array { } } -"""), - .init(name: "Set.swift", content: -""" -import Foundation - -/// Describes set type -public final class SetType: NSObject, SourceryModel, Diffable { - /// Type name used in declaration - public var name: String - - /// Array element type name - public var elementTypeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Array element type, if known - public var elementType: Type? - - /// :nodoc: - public init(name: String, elementTypeName: TypeName, elementType: Type? = nil) { - self.name = name - self.elementTypeName = elementTypeName - self.elementType = elementType - } - - /// Returns array as generic type - public var asGeneric: GenericType { - GenericType(name: "Set", typeParameters: [ - .init(typeName: elementTypeName) - ]) - } - - public var asSource: String { - "[\\(elementTypeName.asSource)]" - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elementTypeName = \\(String(describing: self.elementTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? SetType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "elementTypeName").trackDifference(actual: self.elementTypeName, expected: castObject.elementTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.elementTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? SetType else { return false } - if self.name != rhs.name { return false } - if self.elementTypeName != rhs.elementTypeName { return false } - return true - } - -// sourcery:inline:SetType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { - withVaList(["elementTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.elementTypeName = elementTypeName - self.elementType = aDecoder.decode(forKey: "elementType") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.elementTypeName, forKey: "elementTypeName") - aCoder.encode(self.elementType, forKey: "elementType") - } -// sourcery:end -} - """), .init(name: "Array.swift", content: """ import Foundation /// Describes array type -@objcMembers +#if canImport(ObjectiveC) +@objcMembers +#endif public final class ArrayType: NSObject, SourceryModel, Diffable { /// Type name used in declaration public var name: String @@ -399,12 +232,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elementTypeName = \\(String(describing: self.elementTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("elementTypeName = \\(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -419,6 +253,8 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -438,13 +274,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { + guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { withVaList(["elementTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -462,95 +298,15 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { // sourcery:end } -"""), - .init(name: "AssociatedType.swift", content: -""" -import Foundation - -/// Describes Swift AssociatedType -@objcMembers -public final class AssociatedType: NSObject, SourceryModel { - /// Associated type name - public let name: String - - /// Associated type type constraint name, if specified - public let typeName: TypeName? - - // sourcery: skipEquality, skipDescription - /// Associated type constrained type, if known, i.e. if the type is declared in the scanned sources. - public var type: Type? - - /// :nodoc: - public init(name: String, typeName: TypeName? = nil, type: Type? = nil) { - self.name = name - self.typeName = typeName - self.type = type - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? AssociatedType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.typeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? AssociatedType else { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - return true - } - -// sourcery:inline:AssociatedType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.typeName = aDecoder.decode(forKey: "typeName") - self.type = aDecoder.decode(forKey: "type") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - } -// sourcery:end -} - """), .init(name: "Attribute.swift", content: """ import Foundation /// Describes Swift attribute +#if canImport(ObjectiveC) @objcMembers +#endif public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJSExport, Diffable { /// Attribute name @@ -609,6 +365,7 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ case final case open case lazy + case `package` = "package" case `public` = "public" case `internal` = "internal" case `private` = "private" @@ -712,6 +469,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -733,19 +492,19 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let arguments: [String: NSObject] = aDecoder.decode(forKey: "arguments") else { + guard let arguments: [String: NSObject] = aDecoder.decode(forKey: "arguments") else { withVaList(["arguments"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.arguments = arguments - guard let _description: String = aDecoder.decode(forKey: "_description") else { + guard let _description: String = aDecoder.decode(forKey: "_description") else { withVaList(["_description"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -763,18 +522,6 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ } -"""), - .init(name: "AutoHashable.generated.swift", content: -""" -// Generated using Sourcery 1.3.1 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT -// swiftlint:disable all - - -// MARK: - AutoHashable for classes, protocols, structs - -// MARK: - AutoHashable for Enums - """), .init(name: "BytesRange.swift", content: """ @@ -786,7 +533,9 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ import Foundation /// :nodoc: +#if canImport(ObjectiveC) @objcMembers +#endif public final class BytesRange: NSObject, SourceryModel, Diffable { public let offset: Int64 @@ -802,6 +551,7 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " string += "offset = \\(String(describing: self.offset)), " @@ -820,6 +570,8 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.offset) @@ -857,14 +609,16 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { import Foundation // sourcery: skipDescription /// Descibes Swift class +#if canImport(ObjectiveC) @objc(SwiftClass) @objcMembers +#endif public final class Class: Type { /// Returns "class" public override var kind: String { return "class" } - /// Whether type is final + /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -907,11 +661,12 @@ public final class Class: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "isFinal = \\(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("isFinal = \\(String(describing: self.isFinal))") return string } @@ -925,6 +680,8 @@ public final class Class: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -952,281 +709,6 @@ public final class Class: Type { } -"""), - .init(name: "Closure.swift", content: -""" -import Foundation - -/// Describes closure type -@objcMembers -public final class ClosureType: NSObject, SourceryModel, Diffable { - - /// Type name used in declaration with stripped whitespaces and new lines - public let name: String - - /// List of closure parameters - public let parameters: [ClosureParameter] - - /// Return value type name - public let returnTypeName: TypeName - - /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` - public var actualReturnTypeName: TypeName { - return returnTypeName.actualTypeName ?? returnTypeName - } - - // sourcery: skipEquality, skipDescription - /// Actual return value type, if known - public var returnType: Type? - - // sourcery: skipEquality, skipDescription - /// Whether return value type is optional - public var isOptionalReturnType: Bool { - return returnTypeName.isOptional - } - - // sourcery: skipEquality, skipDescription - /// Whether return value type is implicitly unwrapped optional - public var isImplicitlyUnwrappedOptionalReturnType: Bool { - return returnTypeName.isImplicitlyUnwrappedOptional - } - - // sourcery: skipEquality, skipDescription - /// Return value type name without attributes and optional type information - public var unwrappedReturnTypeName: String { - return returnTypeName.unwrappedTypeName - } - - /// Whether method is async method - public let isAsync: Bool - - /// async keyword - public let asyncKeyword: String? - - /// Whether closure throws - public let `throws`: Bool - - /// throws or rethrows keyword - public let throwsOrRethrowsKeyword: String? - - /// :nodoc: - public init(name: String, parameters: [ClosureParameter], returnTypeName: TypeName, returnType: Type? = nil, asyncKeyword: String? = nil, throwsOrRethrowsKeyword: String? = nil) { - self.name = name - self.parameters = parameters - self.returnTypeName = returnTypeName - self.returnType = returnType - self.asyncKeyword = asyncKeyword - self.isAsync = asyncKeyword != nil - self.throwsOrRethrowsKeyword = throwsOrRethrowsKeyword - self.`throws` = throwsOrRethrowsKeyword != nil - } - - public var asSource: String { - "\\(parameters.asSource)\\(asyncKeyword != nil ? " \\(asyncKeyword!)" : "")\\(throwsOrRethrowsKeyword != nil ? " \\(throwsOrRethrowsKeyword!)" : "") -> \\(returnTypeName.asSource)" - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "parameters = \\(String(describing: self.parameters)), " - string += "returnTypeName = \\(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "asyncKeyword = \\(String(describing: self.asyncKeyword)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "throwsOrRethrowsKeyword = \\(String(describing: self.throwsOrRethrowsKeyword)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? ClosureType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) - results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "asyncKeyword").trackDifference(actual: self.asyncKeyword, expected: castObject.asyncKeyword)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "throwsOrRethrowsKeyword").trackDifference(actual: self.throwsOrRethrowsKeyword, expected: castObject.throwsOrRethrowsKeyword)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.parameters) - hasher.combine(self.returnTypeName) - hasher.combine(self.isAsync) - hasher.combine(self.asyncKeyword) - hasher.combine(self.`throws`) - hasher.combine(self.throwsOrRethrowsKeyword) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? ClosureType else { return false } - if self.name != rhs.name { return false } - if self.parameters != rhs.parameters { return false } - if self.returnTypeName != rhs.returnTypeName { return false } - if self.isAsync != rhs.isAsync { return false } - if self.asyncKeyword != rhs.asyncKeyword { return false } - if self.`throws` != rhs.`throws` { return false } - if self.throwsOrRethrowsKeyword != rhs.throwsOrRethrowsKeyword { return false } - return true - } - -// sourcery:inline:ClosureType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let parameters: [ClosureParameter] = aDecoder.decode(forKey: "parameters") else { - withVaList(["parameters"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { - withVaList(["returnTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.returnTypeName = returnTypeName - self.returnType = aDecoder.decode(forKey: "returnType") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.asyncKeyword = aDecoder.decode(forKey: "asyncKeyword") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.throwsOrRethrowsKeyword = aDecoder.decode(forKey: "throwsOrRethrowsKeyword") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.parameters, forKey: "parameters") - aCoder.encode(self.returnTypeName, forKey: "returnTypeName") - aCoder.encode(self.returnType, forKey: "returnType") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.asyncKeyword, forKey: "asyncKeyword") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.throwsOrRethrowsKeyword, forKey: "throwsOrRethrowsKeyword") - } -// sourcery:end - -} - -"""), - .init(name: "Coding.generated.swift", content: -""" -// Generated using Sourcery 2.0.3 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT -// swiftlint:disable vertical_whitespace trailing_newline - -import Foundation - - -extension NSCoder { - - @nonobjc func decode(forKey: String) -> String? { - return self.maybeDecode(forKey: forKey) as String? - } - - @nonobjc func decode(forKey: String) -> TypeName? { - return self.maybeDecode(forKey: forKey) as TypeName? - } - - @nonobjc func decode(forKey: String) -> AccessLevel? { - return self.maybeDecode(forKey: forKey) as AccessLevel? - } - - @nonobjc func decode(forKey: String) -> Bool { - return self.decodeBool(forKey: forKey) - } - - @nonobjc func decode(forKey: String) -> Int { - return self.decodeInteger(forKey: forKey) - } - - func decode(forKey: String) -> E? { - return maybeDecode(forKey: forKey) as E? - } - - fileprivate func maybeDecode(forKey: String) -> E? { - guard let object = self.decodeObject(forKey: forKey) else { - return nil - } - - return object as? E - } - -} - -extension ArrayType: NSCoding {} - -extension AssociatedType: NSCoding {} - -extension AssociatedValue: NSCoding {} - -extension Attribute: NSCoding {} - -extension BytesRange: NSCoding {} - - -extension ClosureParameter: NSCoding {} - -extension ClosureType: NSCoding {} - -extension DictionaryType: NSCoding {} - - -extension EnumCase: NSCoding {} - -extension FileParserResult: NSCoding {} - -extension GenericRequirement: NSCoding {} - -extension GenericType: NSCoding {} - -extension GenericTypeParameter: NSCoding {} - -extension Import: NSCoding {} - -extension Method: NSCoding {} - -extension MethodParameter: NSCoding {} - -extension Modifier: NSCoding {} - - - - -extension Subscript: NSCoding {} - -extension TupleElement: NSCoding {} - -extension TupleType: NSCoding {} - -extension Type: NSCoding {} - -extension TypeName: NSCoding {} - -extension Typealias: NSCoding {} - -extension Types: NSCoding {} - -extension Variable: NSCoding {} - - """), .init(name: "Composer.swift", content: """ @@ -1259,12 +741,16 @@ public enum Composer { return composed.resolveType(typeName: typeName, containingType: containingType) } + let methodResolveType = { (typeName: TypeName, containingType: Type?, method: Method) -> Type? in + return composed.resolveType(typeName: typeName, containingType: containingType, method: method) + } + composed.types.parallelPerform { type in type.variables.forEach { resolveVariableTypes($0, of: type, resolve: resolveType) } type.methods.forEach { - resolveMethodTypes($0, of: type, resolve: resolveType) + resolveMethodTypes($0, of: type, resolve: methodResolveType) } type.subscripts.forEach { resolveSubscriptTypes($0, of: type, resolve: resolveType) @@ -1284,7 +770,7 @@ public enum Composer { } composed.functions.parallelPerform { function in - resolveMethodTypes(function, of: nil, resolve: resolveType) + resolveMethodTypes(function, of: nil, resolve: methodResolveType) } updateTypeRelationships(types: composed.types) @@ -1297,6 +783,7 @@ public enum Composer { } typealias TypeResolver = (TypeName, Type?) -> Type? + typealias MethodArgumentTypeResolver = (TypeName, Type?, Method) -> Type? private static func resolveVariableTypes(_ variable: Variable, of type: Type, resolve: TypeResolver) { variable.type = resolve(variable.typeName, type) @@ -1320,9 +807,9 @@ public enum Composer { } } - private static func resolveMethodTypes(_ method: SourceryMethod, of type: Type?, resolve: TypeResolver) { + private static func resolveMethodTypes(_ method: SourceryMethod, of type: Type?, resolve: MethodArgumentTypeResolver) { method.parameters.forEach { parameter in - parameter.type = resolve(parameter.typeName, type) + parameter.type = resolve(parameter.typeName, type, method) } /// The actual `definedInType` is assigned in `uniqueTypes` but we still @@ -1330,7 +817,7 @@ public enum Composer { /// @see https://github.com/krzysztofzablocki/Sourcery/pull/374 var definedInType: Type? if let definedInTypeName = method.definedInTypeName { - definedInType = resolve(definedInTypeName, type) + definedInType = resolve(definedInTypeName, type, method) } guard !method.returnTypeName.isVoid else { return } @@ -1356,7 +843,7 @@ public enum Composer { } } } else { - method.returnType = resolve(method.returnTypeName, type) + method.returnType = resolve(method.returnTypeName, type, method) } } @@ -1429,6 +916,13 @@ public enum Composer { } private static func findBaseType(for type: Type, name: String, typesByName: [String: Type]) -> Type? { + // special case to check if the type is based on one of the recognized types + // and the superclass has a generic constraint in `name` part of the `TypeName` + var name = name + if name.contains("<") && name.contains(">") { + let parts = name.split(separator: "<") + name = String(parts.first!) + } if let baseType = typesByName[name] { return baseType } @@ -1504,7 +998,9 @@ public protocol Definition: AnyObject { import Foundation /// Describes dictionary type +#if canImport(ObjectiveC) @objcMembers +#endif public final class DictionaryType: NSObject, SourceryModel, Diffable { /// Type name used in declaration public var name: String @@ -1545,13 +1041,14 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "valueTypeName = \\(String(describing: self.valueTypeName)), " - string += "keyTypeName = \\(String(describing: self.keyTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("valueTypeName = \\(String(describing: self.valueTypeName)), ") + string.append("keyTypeName = \\(String(describing: self.keyTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -1567,6 +1064,8 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -1588,20 +1087,20 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let valueTypeName: TypeName = aDecoder.decode(forKey: "valueTypeName") else { + guard let valueTypeName: TypeName = aDecoder.decode(forKey: "valueTypeName") else { withVaList(["valueTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.valueTypeName = valueTypeName self.valueType = aDecoder.decode(forKey: "valueType") - guard let keyTypeName: TypeName = aDecoder.decode(forKey: "keyTypeName") else { + guard let keyTypeName: TypeName = aDecoder.decode(forKey: "keyTypeName") else { withVaList(["keyTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -1662,7 +1161,9 @@ extension NSRange: Diffable { } } +#if canImport(ObjectiveC) @objcMembers +#endif public class DiffableResult: NSObject, AutoEquatable { // sourcery: skipEquality private var results: [String] @@ -1685,9 +1186,26 @@ public class DiffableResult: NSObject, AutoEquatable { var isEmpty: Bool { return results.isEmpty } + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.identifier) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? DiffableResult else { return false } + if self.identifier != rhs.identifier { return false } + return true + } + public override var description: String { guard !results.isEmpty else { return "" } - return "\\(identifier.flatMap { "\\($0) " } ?? "")" + results.joined(separator: "\\n") + var description = "\\(identifier.flatMap { "\\($0) " } ?? "")" + description.append(results.joined(separator: "\\n")) + return description } } @@ -1708,7 +1226,9 @@ public extension DiffableResult { /// :nodoc: @discardableResult func trackDifference(actual: T?, expected: T?) -> DiffableResult { if actual != expected { - let result = DiffableResult(results: [""]) + let expected = expected.map({ "\\($0)" }) ?? "nil" + let actual = actual.map({ "\\($0)" }) ?? "nil" + let result = DiffableResult(results: [""]) append(contentsOf: result) } return self @@ -1845,429 +1365,6 @@ public protocol Documented { var documentation: Documentation { get } } -"""), - .init(name: "AssociatedValue.swift", content: -""" -import Foundation - -/// Defines enum case associated value -@objcMembers -public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable { - - /// Associated value local name. - /// This is a name to be used to construct enum case value - public let localName: String? - - /// Associated value external name. - /// This is a name to be used to access value in value-bindig - public let externalName: String? - - /// Associated value type name - public let typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Associated value type, if known - public var type: Type? - - /// Associated value default value - public let defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(localName: String?, externalName: String?, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { - self.localName = localName - self.externalName = externalName - self.typeName = typeName - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - } - - convenience init(name: String? = nil, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { - self.init(localName: name, externalName: name, typeName: typeName, type: type, defaultValue: defaultValue, annotations: annotations) - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "localName = \\(String(describing: self.localName)), " - string += "externalName = \\(String(describing: self.externalName)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? AssociatedValue else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "localName").trackDifference(actual: self.localName, expected: castObject.localName)) - results.append(contentsOf: DiffableResult(identifier: "externalName").trackDifference(actual: self.externalName, expected: castObject.externalName)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.localName) - hasher.combine(self.externalName) - hasher.combine(self.typeName) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? AssociatedValue else { return false } - if self.localName != rhs.localName { return false } - if self.externalName != rhs.externalName { return false } - if self.typeName != rhs.typeName { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - -// sourcery:inline:AssociatedValue.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.localName = aDecoder.decode(forKey: "localName") - self.externalName = aDecoder.decode(forKey: "externalName") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.localName, forKey: "localName") - aCoder.encode(self.externalName, forKey: "externalName") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } -// sourcery:end - -} -"""), - .init(name: "EnumCase.swift", content: -""" -import Foundation - -/// Defines enum case -@objcMembers -public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable { - - /// Enum case name - public let name: String - - /// Enum case raw value, if any - public let rawValue: String? - - /// Enum case associated values - public let associatedValues: [AssociatedValue] - - /// Enum case annotations - public var annotations: Annotations = [:] - - public var documentation: Documentation = [] - - /// Whether enum case is indirect - public let indirect: Bool - - /// Whether enum case has associated value - public var hasAssociatedValue: Bool { - return !associatedValues.isEmpty - } - - // Underlying parser data, never to be used by anything else - // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport - /// :nodoc: - public var __parserData: Any? - - /// :nodoc: - public init(name: String, rawValue: String? = nil, associatedValues: [AssociatedValue] = [], annotations: [String: NSObject] = [:], documentation: [String] = [], indirect: Bool = false) { - self.name = name - self.rawValue = rawValue - self.associatedValues = associatedValues - self.annotations = annotations - self.documentation = documentation - self.indirect = indirect - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "rawValue = \\(String(describing: self.rawValue)), " - string += "associatedValues = \\(String(describing: self.associatedValues)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "indirect = \\(String(describing: self.indirect)), " - string += "hasAssociatedValue = \\(String(describing: self.hasAssociatedValue))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? EnumCase else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "rawValue").trackDifference(actual: self.rawValue, expected: castObject.rawValue)) - results.append(contentsOf: DiffableResult(identifier: "associatedValues").trackDifference(actual: self.associatedValues, expected: castObject.associatedValues)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "indirect").trackDifference(actual: self.indirect, expected: castObject.indirect)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.rawValue) - hasher.combine(self.associatedValues) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.indirect) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? EnumCase else { return false } - if self.name != rhs.name { return false } - if self.rawValue != rhs.rawValue { return false } - if self.associatedValues != rhs.associatedValues { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.indirect != rhs.indirect { return false } - return true - } - -// sourcery:inline:EnumCase.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.rawValue = aDecoder.decode(forKey: "rawValue") - guard let associatedValues: [AssociatedValue] = aDecoder.decode(forKey: "associatedValues") else { - withVaList(["associatedValues"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.associatedValues = associatedValues - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - self.indirect = aDecoder.decode(forKey: "indirect") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.rawValue, forKey: "rawValue") - aCoder.encode(self.associatedValues, forKey: "associatedValues") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.indirect, forKey: "indirect") - } -// sourcery:end -} -"""), - .init(name: "Enum.swift", content: -""" -// -// Created by Krzysztof Zablocki on 13/09/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// Defines Swift enum -@objcMembers -public final class Enum: Type { - // sourcery: skipDescription - /// Returns "enum" - public override var kind: String { return "enum" } - - /// Enum cases - public var cases: [EnumCase] - - /** - Enum raw value type name, if any. This type is removed from enum's `based` and `inherited` types collections. - - - important: Unless raw type is specified explicitly via type alias RawValue it will be set to the first type in the inheritance chain. - So if your enum does not have raw value but implements protocols you'll have to specify conformance to these protocols via extension to get enum with nil raw value type and all based and inherited types. - */ - public var rawTypeName: TypeName? { - didSet { - if let rawTypeName = rawTypeName { - hasRawType = true - if let index = inheritedTypes.firstIndex(of: rawTypeName.name) { - inheritedTypes.remove(at: index) - } - if based[rawTypeName.name] != nil { - based[rawTypeName.name] = nil - } - } else { - hasRawType = false - } - } - } - - // sourcery: skipDescription, skipEquality - /// :nodoc: - public private(set) var hasRawType: Bool - - // sourcery: skipDescription, skipEquality - /// Enum raw value type, if known - public var rawType: Type? - - // sourcery: skipEquality, skipDescription, skipCoding - /// Names of types or protocols this type inherits from, including unknown (not scanned) types - public override var based: [String: String] { - didSet { - if let rawTypeName = rawTypeName, based[rawTypeName.name] != nil { - based[rawTypeName.name] = nil - } - } - } - - /// Whether enum contains any associated values - public var hasAssociatedValues: Bool { - return cases.contains(where: { $0.hasAssociatedValue }) - } - - /// :nodoc: - public init(name: String = "", - parent: Type? = nil, - accessLevel: AccessLevel = .internal, - isExtension: Bool = false, - inheritedTypes: [String] = [], - rawTypeName: TypeName? = nil, - cases: [EnumCase] = [], - variables: [Variable] = [], - methods: [Method] = [], - containedTypes: [Type] = [], - typealiases: [Typealias] = [], - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - isGeneric: Bool = false) { - - self.cases = cases - self.rawTypeName = rawTypeName - self.hasRawType = rawTypeName != nil || !inheritedTypes.isEmpty - - super.init(name: name, parent: parent, accessLevel: accessLevel, isExtension: isExtension, variables: variables, methods: methods, inheritedTypes: inheritedTypes, containedTypes: containedTypes, typealiases: typealiases, attributes: attributes, modifiers: modifiers, annotations: annotations, documentation: documentation, isGeneric: isGeneric) - - if let rawTypeName = rawTypeName?.name, let index = self.inheritedTypes.firstIndex(of: rawTypeName) { - self.inheritedTypes.remove(at: index) - } - } - - /// :nodoc: - override public var description: String { - var string = super.description - string += ", " - string += "cases = \\(String(describing: self.cases)), " - string += "rawTypeName = \\(String(describing: self.rawTypeName)), " - string += "hasAssociatedValues = \\(String(describing: self.hasAssociatedValues))" - return string - } - - override public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Enum else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "cases").trackDifference(actual: self.cases, expected: castObject.cases)) - results.append(contentsOf: DiffableResult(identifier: "rawTypeName").trackDifference(actual: self.rawTypeName, expected: castObject.rawTypeName)) - results.append(contentsOf: super.diffAgainst(castObject)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.cases) - hasher.combine(self.rawTypeName) - hasher.combine(super.hash) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Enum else { return false } - if self.cases != rhs.cases { return false } - if self.rawTypeName != rhs.rawTypeName { return false } - return super.isEqual(rhs) - } - -// sourcery:inline:Enum.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let cases: [EnumCase] = aDecoder.decode(forKey: "cases") else { - withVaList(["cases"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.cases = cases - self.rawTypeName = aDecoder.decode(forKey: "rawTypeName") - self.hasRawType = aDecoder.decode(forKey: "hasRawType") - self.rawType = aDecoder.decode(forKey: "rawType") - super.init(coder: aDecoder) - } - - /// :nodoc: - override public func encode(with aCoder: NSCoder) { - super.encode(with: aCoder) - aCoder.encode(self.cases, forKey: "cases") - aCoder.encode(self.rawTypeName, forKey: "rawTypeName") - aCoder.encode(self.hasRawType, forKey: "hasRawType") - aCoder.encode(self.rawType, forKey: "rawType") - } -// sourcery:end -} - """), .init(name: "Extensions.swift", content: """ @@ -2462,29 +1559,37 @@ public extension String { defer { i = self.index(i, offsetBy: offset) } - let currentlyScanned = self[i..<(self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) ?? self.endIndex)] - if let openString = between.open.first(where: { String(self[i...]).starts(with: $0) }) { - if !(boundingCharactersCount == 0 && String(self[i]) == delimiter) { + var currentlyScannedEnd: Index = self.endIndex + if let endIndex = self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) { + currentlyScannedEnd = endIndex + } + let currentlyScanned: String = String(self[i..` - if !(self[i] == ">" && item.last == "-") { + if !((self[i] == ">") as Bool && (item.last == "-") as Bool) { boundingCharactersCount = max(0, boundingCharactersCount - 1) } offset = closeString.count } - if self[i] == "\\"" { + if (self[i] == "\\"") as Bool { quotesCount += 1 } - if currentlyScanned == delimiter && boundingCharactersCount == 0 && quotesCount % 2 == 0 { + let currentIsDelimiter = (currentlyScanned == delimiter) as Bool + let boundingCountIsZero = (boundingCharactersCount == 0) as Bool + let hasEvenQuotes = (quotesCount % 2 == 0) as Bool + if currentIsDelimiter && boundingCountIsZero && hasEvenQuotes { items.append(item) item = "" i = self.index(i, offsetBy: delimiter.count - 1) } else { - item += self[i..` public var name: String @@ -2726,6 +1838,8 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -2739,19 +1853,19 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa if self.name != rhs.name { return false } if self.typeParameters != rhs.typeParameters { return false } return true - } + } // sourcery:inline:GenericType.AutoCoding /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let typeParameters: [GenericTypeParameter] = aDecoder.decode(forKey: "typeParameters") else { + guard let typeParameters: [GenericTypeParameter] = aDecoder.decode(forKey: "typeParameters") else { withVaList(["typeParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -2768,204 +1882,15 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa // sourcery:end } -/// Descibes Swift generic type parameter -@objcMembers -public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { - - /// Generic parameter type name - public var typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Generic parameter type, if known - public var type: Type? - - /// :nodoc: - public init(typeName: TypeName, type: Type? = nil) { - self.typeName = typeName - self.type = type - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "typeName = \\(String(describing: self.typeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericTypeParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.typeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericTypeParameter else { return false } - if self.typeName != rhs.typeName { return false } - return true - } - -// sourcery:inline:GenericTypeParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - } - -// sourcery:end -} - -"""), - .init(name: "GenericRequirement.swift", content: -""" -import Foundation - -/// modifier can be thing like `private`, `class`, `nonmutating` -/// if a declaration has modifier like `private(set)` it's name will be `private` and detail will be `set` -@objcMembers -public class GenericRequirement: NSObject, SourceryModel, Diffable { - - public enum Relationship: String { - case equals - case conformsTo - - var syntax: String { - switch self { - case .equals: - return "==" - case .conformsTo: - return ":" - } - } - } - - public var leftType: AssociatedType - public let rightType: GenericTypeParameter - - /// relationship name - public let relationship: String - - /// Syntax e.g. `==` or `:` - public let relationshipSyntax: String - - public init(leftType: AssociatedType, rightType: GenericTypeParameter, relationship: Relationship) { - self.leftType = leftType - self.rightType = rightType - self.relationship = relationship.rawValue - self.relationshipSyntax = relationship.syntax - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "leftType = \\(String(describing: self.leftType)), " - string += "rightType = \\(String(describing: self.rightType)), " - string += "relationship = \\(String(describing: self.relationship)), " - string += "relationshipSyntax = \\(String(describing: self.relationshipSyntax))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericRequirement else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "leftType").trackDifference(actual: self.leftType, expected: castObject.leftType)) - results.append(contentsOf: DiffableResult(identifier: "rightType").trackDifference(actual: self.rightType, expected: castObject.rightType)) - results.append(contentsOf: DiffableResult(identifier: "relationship").trackDifference(actual: self.relationship, expected: castObject.relationship)) - results.append(contentsOf: DiffableResult(identifier: "relationshipSyntax").trackDifference(actual: self.relationshipSyntax, expected: castObject.relationshipSyntax)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.leftType) - hasher.combine(self.rightType) - hasher.combine(self.relationship) - hasher.combine(self.relationshipSyntax) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericRequirement else { return false } - if self.leftType != rhs.leftType { return false } - if self.rightType != rhs.rightType { return false } - if self.relationship != rhs.relationship { return false } - if self.relationshipSyntax != rhs.relationshipSyntax { return false } - return true - } - - // sourcery:inline:GenericRequirement.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { - withVaList(["leftType"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.leftType = leftType - guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { - withVaList(["rightType"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.rightType = rightType - guard let relationship: String = aDecoder.decode(forKey: "relationship") else { - withVaList(["relationship"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.relationship = relationship - guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { - withVaList(["relationshipSyntax"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.relationshipSyntax = relationshipSyntax - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.leftType, forKey: "leftType") - aCoder.encode(self.rightType, forKey: "rightType") - aCoder.encode(self.relationship, forKey: "relationship") - aCoder.encode(self.relationshipSyntax, forKey: "relationshipSyntax") - } - // sourcery:end -} - """), .init(name: "Import.swift", content: """ import Foundation /// Defines import type +#if canImport(ObjectiveC) @objcMembers +#endif public class Import: NSObject, SourceryModelWithoutDescription, Diffable { /// Import kind, e.g. class, struct in `import class Module.ClassName` public var kind: String? @@ -3012,6 +1937,8 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.kind) @@ -3032,7 +1959,7 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.kind = aDecoder.decode(forKey: "kind") - guard let path: String = aDecoder.decode(forKey: "path") else { + guard let path: String = aDecoder.decode(forKey: "path") else { withVaList(["path"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -3049,638 +1976,10 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { // sourcery:end } -"""), - .init(name: "JSExport.generated.swift", content: -""" -// Generated using Sourcery 2.0.3 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT -// swiftlint:disable vertical_whitespace trailing_newline - -import JavaScriptCore - -@objc protocol ActorAutoJSExport: JSExport { - var kind: String { get } - var isFinal: Bool { get } - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var based: [String: String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Actor: ActorAutoJSExport {} - -@objc protocol ArrayTypeAutoJSExport: JSExport { - var name: String { get } - var elementTypeName: TypeName { get } - var elementType: Type? { get } - var asGeneric: GenericType { get } - var asSource: String { get } -} - -extension ArrayType: ArrayTypeAutoJSExport {} - -@objc protocol AssociatedTypeAutoJSExport: JSExport { - var name: String { get } - var typeName: TypeName? { get } - var type: Type? { get } -} - -extension AssociatedType: AssociatedTypeAutoJSExport {} - -@objc protocol AssociatedValueAutoJSExport: JSExport { - var localName: String? { get } - var externalName: String? { get } - var typeName: TypeName { get } - var type: Type? { get } - var defaultValue: String? { get } - var annotations: Annotations { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } -} - -extension AssociatedValue: AssociatedValueAutoJSExport {} - -@objc protocol AttributeAutoJSExport: JSExport { - var name: String { get } - var arguments: [String: NSObject] { get } - var asSource: String { get } - var description: String { get } -} - -extension Attribute: AttributeAutoJSExport {} - -@objc protocol BytesRangeAutoJSExport: JSExport { - var offset: Int64 { get } - var length: Int64 { get } -} - -extension BytesRange: BytesRangeAutoJSExport {} - -@objc protocol ClassAutoJSExport: JSExport { - var kind: String { get } - var isFinal: Bool { get } - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var based: [String: String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Class: ClassAutoJSExport {} - -@objc protocol ClosureParameterAutoJSExport: JSExport { - var argumentLabel: String? { get } - var name: String? { get } - var typeName: TypeName { get } - var `inout`: Bool { get } - var type: Type? { get } - var typeAttributes: AttributeList { get } - var defaultValue: String? { get } - var annotations: Annotations { get } - var asSource: String { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } -} - -extension ClosureParameter: ClosureParameterAutoJSExport {} - -@objc protocol ClosureTypeAutoJSExport: JSExport { - var name: String { get } - var parameters: [ClosureParameter] { get } - var returnTypeName: TypeName { get } - var actualReturnTypeName: TypeName { get } - var returnType: Type? { get } - var isOptionalReturnType: Bool { get } - var isImplicitlyUnwrappedOptionalReturnType: Bool { get } - var unwrappedReturnTypeName: String { get } - var isAsync: Bool { get } - var asyncKeyword: String? { get } - var `throws`: Bool { get } - var throwsOrRethrowsKeyword: String? { get } - var asSource: String { get } -} - -extension ClosureType: ClosureTypeAutoJSExport {} - -@objc protocol DictionaryTypeAutoJSExport: JSExport { - var name: String { get } - var valueTypeName: TypeName { get } - var valueType: Type? { get } - var keyTypeName: TypeName { get } - var keyType: Type? { get } - var asGeneric: GenericType { get } - var asSource: String { get } -} - -extension DictionaryType: DictionaryTypeAutoJSExport {} - -@objc protocol EnumAutoJSExport: JSExport { - var kind: String { get } - var cases: [EnumCase] { get } - var rawTypeName: TypeName? { get } - var hasRawType: Bool { get } - var rawType: Type? { get } - var based: [String: String] { get } - var hasAssociatedValues: Bool { get } - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Enum: EnumAutoJSExport {} - -@objc protocol EnumCaseAutoJSExport: JSExport { - var name: String { get } - var rawValue: String? { get } - var associatedValues: [AssociatedValue] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var indirect: Bool { get } - var hasAssociatedValue: Bool { get } -} - -extension EnumCase: EnumCaseAutoJSExport {} - - -@objc protocol GenericRequirementAutoJSExport: JSExport { - var leftType: AssociatedType { get } - var rightType: GenericTypeParameter { get } - var relationship: String { get } - var relationshipSyntax: String { get } -} - -extension GenericRequirement: GenericRequirementAutoJSExport {} - -@objc protocol GenericTypeAutoJSExport: JSExport { - var name: String { get } - var typeParameters: [GenericTypeParameter] { get } - var asSource: String { get } - var description: String { get } -} - -extension GenericType: GenericTypeAutoJSExport {} - -@objc protocol GenericTypeParameterAutoJSExport: JSExport { - var typeName: TypeName { get } - var type: Type? { get } -} - -extension GenericTypeParameter: GenericTypeParameterAutoJSExport {} - -@objc protocol ImportAutoJSExport: JSExport { - var kind: String? { get } - var path: String { get } - var description: String { get } - var moduleName: String { get } -} - -extension Import: ImportAutoJSExport {} - -@objc protocol MethodAutoJSExport: JSExport { - var name: String { get } - var selectorName: String { get } - var shortName: String { get } - var callName: String { get } - var parameters: [MethodParameter] { get } - var returnTypeName: TypeName { get } - var actualReturnTypeName: TypeName { get } - var returnType: Type? { get } - var isOptionalReturnType: Bool { get } - var isImplicitlyUnwrappedOptionalReturnType: Bool { get } - var unwrappedReturnTypeName: String { get } - var isAsync: Bool { get } - var `throws`: Bool { get } - var `rethrows`: Bool { get } - var accessLevel: String { get } - var isStatic: Bool { get } - var isClass: Bool { get } - var isInitializer: Bool { get } - var isDeinitializer: Bool { get } - var isFailableInitializer: Bool { get } - var isConvenienceInitializer: Bool { get } - var isRequired: Bool { get } - var isFinal: Bool { get } - var isMutating: Bool { get } - var isGeneric: Bool { get } - var isOptional: Bool { get } - var isNonisolated: Bool { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var definedInTypeName: TypeName? { get } - var actualDefinedInTypeName: TypeName? { get } - var definedInType: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } -} - -extension Method: MethodAutoJSExport {} - -@objc protocol MethodParameterAutoJSExport: JSExport { - var argumentLabel: String? { get } - var name: String { get } - var typeName: TypeName { get } - var `inout`: Bool { get } - var isVariadic: Bool { get } - var type: Type? { get } - var typeAttributes: AttributeList { get } - var defaultValue: String? { get } - var annotations: Annotations { get } - var asSource: String { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } -} - -extension MethodParameter: MethodParameterAutoJSExport {} - -@objc protocol ModifierAutoJSExport: JSExport { - var name: String { get } - var detail: String? { get } - var asSource: String { get } -} - -extension Modifier: ModifierAutoJSExport {} - -@objc protocol ProtocolAutoJSExport: JSExport { - var kind: String { get } - var associatedTypes: [String: AssociatedType] { get } - var genericRequirements: [GenericRequirement] { get } - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var based: [String: String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Protocol: ProtocolAutoJSExport {} - - - - -@objc protocol StructAutoJSExport: JSExport { - var kind: String { get } - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var based: [String: String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Struct: StructAutoJSExport {} - -@objc protocol SubscriptAutoJSExport: JSExport { - var parameters: [MethodParameter] { get } - var returnTypeName: TypeName { get } - var actualReturnTypeName: TypeName { get } - var returnType: Type? { get } - var isOptionalReturnType: Bool { get } - var isImplicitlyUnwrappedOptionalReturnType: Bool { get } - var unwrappedReturnTypeName: String { get } - var isFinal: Bool { get } - var readAccess: String { get } - var writeAccess: String { get } - var isMutable: Bool { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var definedInTypeName: TypeName? { get } - var actualDefinedInTypeName: TypeName? { get } - var definedInType: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } -} - -extension Subscript: SubscriptAutoJSExport {} - -@objc protocol TemplateContextAutoJSExport: JSExport { - var functions: [SourceryMethod] { get } - var types: Types { get } - var argument: [String: NSObject] { get } - var type: [String: Type] { get } - var stencilContext: [String: Any] { get } - var jsContext: [String: Any] { get } -} - -extension TemplateContext: TemplateContextAutoJSExport {} - -@objc protocol TupleElementAutoJSExport: JSExport { - var name: String? { get } - var typeName: TypeName { get } - var type: Type? { get } - var asSource: String { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } -} - -extension TupleElement: TupleElementAutoJSExport {} - -@objc protocol TupleTypeAutoJSExport: JSExport { - var name: String { get } - var elements: [TupleElement] { get } -} - -extension TupleType: TupleTypeAutoJSExport {} - -@objc protocol TypeAutoJSExport: JSExport { - var module: String? { get } - var imports: [Import] { get } - var allImports: [Import] { get } - var kind: String { get } - var accessLevel: String { get } - var name: String { get } - var isUnknownExtension: Bool { get } - var globalName: String { get } - var isGeneric: Bool { get } - var localName: String { get } - var variables: [Variable] { get } - var rawVariables: [Variable] { get } - var allVariables: [Variable] { get } - var methods: [Method] { get } - var rawMethods: [Method] { get } - var allMethods: [Method] { get } - var subscripts: [Subscript] { get } - var rawSubscripts: [Subscript] { get } - var allSubscripts: [Subscript] { get } - var initializers: [Method] { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var staticVariables: [Variable] { get } - var staticMethods: [Method] { get } - var classMethods: [Method] { get } - var instanceVariables: [Variable] { get } - var instanceMethods: [Method] { get } - var computedVariables: [Variable] { get } - var storedVariables: [Variable] { get } - var inheritedTypes: [String] { get } - var based: [String: String] { get } - var basedTypes: [String: Type] { get } - var inherits: [String: Type] { get } - var implements: [String: Type] { get } - var containedTypes: [Type] { get } - var containedType: [String: Type] { get } - var parentName: String? { get } - var parent: Type? { get } - var supertype: Type? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var fileName: String? { get } -} - -extension Type: TypeAutoJSExport {} - -@objc protocol TypeNameAutoJSExport: JSExport { - var name: String { get } - var generic: GenericType? { get } - var isGeneric: Bool { get } - var isProtocolComposition: Bool { get } - var actualTypeName: TypeName? { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } - var isVoid: Bool { get } - var isTuple: Bool { get } - var tuple: TupleType? { get } - var isArray: Bool { get } - var array: ArrayType? { get } - var isDictionary: Bool { get } - var dictionary: DictionaryType? { get } - var isClosure: Bool { get } - var closure: ClosureType? { get } - var set: SetType? { get } - var isSet: Bool { get } - var asSource: String { get } - var description: String { get } - var debugDescription: String { get } -} - -extension TypeName: TypeNameAutoJSExport {} - - - -@objc protocol TypesCollectionAutoJSExport: JSExport { -} - -extension TypesCollection: TypesCollectionAutoJSExport {} - -@objc protocol VariableAutoJSExport: JSExport { - var name: String { get } - var typeName: TypeName { get } - var type: Type? { get } - var isComputed: Bool { get } - var isAsync: Bool { get } - var `throws`: Bool { get } - var isStatic: Bool { get } - var readAccess: String { get } - var writeAccess: String { get } - var isMutable: Bool { get } - var defaultValue: String? { get } - var annotations: Annotations { get } - var documentation: Documentation { get } - var attributes: AttributeList { get } - var modifiers: [SourceryModifier] { get } - var isFinal: Bool { get } - var isLazy: Bool { get } - var definedInTypeName: TypeName? { get } - var actualDefinedInTypeName: TypeName? { get } - var definedInType: Type? { get } - var isOptional: Bool { get } - var isImplicitlyUnwrappedOptional: Bool { get } - var unwrappedTypeName: String { get } -} - -extension Variable: VariableAutoJSExport {} - - """), .init(name: "Log.swift", content: """ -import Darwin +//import Darwin import Foundation /// :nodoc: @@ -3755,742 +2054,6 @@ public enum Log { extension String: Error {} -"""), - .init(name: "MethodParameter.swift", content: -""" -import Foundation - -/// Describes method parameter -@objcMembers -public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable { - /// Parameter external name - public var argumentLabel: String? - - // Note: although method parameter can have no name, this property is not optional, - // this is so to maintain compatibility with existing templates. - /// Parameter internal name - public let name: String - - /// Parameter type name - public let typeName: TypeName - - /// Parameter flag whether it's inout or not - public let `inout`: Bool - - /// Is this variadic parameter? - public let isVariadic: Bool - - // sourcery: skipEquality, skipDescription - /// Parameter type, if known - public var type: Type? - - /// Parameter type attributes, i.e. `@escaping` - public var typeAttributes: AttributeList { - return typeName.attributes - } - - /// Method parameter default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(argumentLabel: String?, name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { - self.typeName = typeName - self.argumentLabel = argumentLabel - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - self.isVariadic = isVariadic - } - - /// :nodoc: - public init(name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { - self.typeName = typeName - self.argumentLabel = name - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - self.isVariadic = isVariadic - } - - public var asSource: String { - let typeSuffix = ": \\(`inout` ? "inout " : "")\\(typeName.asSource)\\(defaultValue.map { " = \\($0)" } ?? "")" + (isVariadic ? "..." : "") - guard argumentLabel != name else { - return name + typeSuffix - } - - let labels = [argumentLabel ?? "_", name.nilIfEmpty] - .compactMap { $0 } - .joined(separator: " ") - - return (labels.nilIfEmpty ?? "_") + typeSuffix - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "argumentLabel = \\(String(describing: self.argumentLabel)), " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "`inout` = \\(String(describing: self.`inout`)), " - string += "isVariadic = \\(String(describing: self.isVariadic)), " - string += "typeAttributes = \\(String(describing: self.typeAttributes)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? MethodParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "argumentLabel").trackDifference(actual: self.argumentLabel, expected: castObject.argumentLabel)) - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "`inout`").trackDifference(actual: self.`inout`, expected: castObject.`inout`)) - results.append(contentsOf: DiffableResult(identifier: "isVariadic").trackDifference(actual: self.isVariadic, expected: castObject.isVariadic)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.argumentLabel) - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.`inout`) - hasher.combine(self.isVariadic) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? MethodParameter else { return false } - if self.argumentLabel != rhs.argumentLabel { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.`inout` != rhs.`inout` { return false } - if self.isVariadic != rhs.isVariadic { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - -// sourcery:inline:MethodParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.`inout` = aDecoder.decode(forKey: "`inout`") - self.isVariadic = aDecoder.decode(forKey: "isVariadic") - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.argumentLabel, forKey: "argumentLabel") - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.isVariadic, forKey: "isVariadic") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } -// sourcery:end -} - -extension Array where Element == MethodParameter { - public var asSource: String { - "(\\(map { $0.asSource }.joined(separator: ", ")))" - } -} - -"""), - .init(name: "ClosureParameter.swift", content: -""" -import Foundation - -// sourcery: skipDiffing -@objcMembers -public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { - /// Parameter external name - public var argumentLabel: String? - - /// Parameter internal name - public let name: String? - - /// Parameter type name - public let typeName: TypeName - - /// Parameter flag whether it's inout or not - public let `inout`: Bool - - // sourcery: skipEquality, skipDescription - /// Parameter type, if known - public var type: Type? - - /// Parameter type attributes, i.e. `@escaping` - public var typeAttributes: AttributeList { - return typeName.attributes - } - - /// Method parameter default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(argumentLabel: String? = nil, name: String? = nil, typeName: TypeName, type: Type? = nil, - defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false) { - self.typeName = typeName - self.argumentLabel = argumentLabel - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - } - - public var asSource: String { - let typeInfo = "\\(`inout` ? "inout " : "")\\(typeName.asSource)" - if argumentLabel?.nilIfNotValidParameterName == nil, name?.nilIfNotValidParameterName == nil { - return typeInfo - } - - let typeSuffix = ": \\(typeInfo)" - guard argumentLabel != name else { - return name ?? "" + typeSuffix - } - - let labels = [argumentLabel ?? "_", name?.nilIfEmpty] - .compactMap { $0 } - .joined(separator: " ") - - return (labels.nilIfEmpty ?? "_") + typeSuffix - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.argumentLabel) - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.`inout`) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "argumentLabel = \\(String(describing: self.argumentLabel)), " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "`inout` = \\(String(describing: self.`inout`)), " - string += "typeAttributes = \\(String(describing: self.typeAttributes)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? ClosureParameter else { return false } - if self.argumentLabel != rhs.argumentLabel { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.`inout` != rhs.`inout` { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - - // sourcery:inline:ClosureParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") - self.name = aDecoder.decode(forKey: "name") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.`inout` = aDecoder.decode(forKey: "`inout`") - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.argumentLabel, forKey: "argumentLabel") - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } - - // sourcery:end -} - -extension Array where Element == ClosureParameter { - public var asSource: String { - "(\\(map { $0.asSource }.joined(separator: ", ")))" - } -} -"""), - .init(name: "Method.swift", content: -""" -import Foundation - -/// :nodoc: -public typealias SourceryMethod = Method - -/// Describes method -@objc(SwiftMethod) @objcMembers -public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable { - - /// Full method name, including generic constraints, i.e. `foo(bar: T)` - public let name: String - - /// Method name including arguments names, i.e. `foo(bar:)` - public var selectorName: String - - // sourcery: skipEquality, skipDescription - /// Method name without arguments names and parenthesis, i.e. `foo` - public var shortName: String { - return name.range(of: "(").map({ String(name[..<$0.lowerBound]) }) ?? name - } - - // sourcery: skipEquality, skipDescription - /// Method name without arguments names, parenthesis and generic types, i.e. `foo` (can be used to generate code for method call) - public var callName: String { - return shortName.range(of: "<").map({ String(shortName[..<$0.lowerBound]) }) ?? shortName - } - - /// Method parameters - public var parameters: [MethodParameter] - - /// Return value type name used in declaration, including generic constraints, i.e. `where T: Equatable` - public var returnTypeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` - public var actualReturnTypeName: TypeName { - return returnTypeName.actualTypeName ?? returnTypeName - } - - // sourcery: skipEquality, skipDescription - /// Actual return value type, if known - public var returnType: Type? - - // sourcery: skipEquality, skipDescription - /// Whether return value type is optional - public var isOptionalReturnType: Bool { - return returnTypeName.isOptional || isFailableInitializer - } - - // sourcery: skipEquality, skipDescription - /// Whether return value type is implicitly unwrapped optional - public var isImplicitlyUnwrappedOptionalReturnType: Bool { - return returnTypeName.isImplicitlyUnwrappedOptional - } - - // sourcery: skipEquality, skipDescription - /// Return value type name without attributes and optional type information - public var unwrappedReturnTypeName: String { - return returnTypeName.unwrappedTypeName - } - - /// Whether method is async method - public let isAsync: Bool - - /// Whether method throws - public let `throws`: Bool - - /// Whether method rethrows - public let `rethrows`: Bool - - /// Method access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let accessLevel: String - - /// Whether method is a static method - public let isStatic: Bool - - /// Whether method is a class method - public let isClass: Bool - - // sourcery: skipEquality, skipDescription - /// Whether method is an initializer - public var isInitializer: Bool { - return selectorName.hasPrefix("init(") || selectorName == "init" - } - - // sourcery: skipEquality, skipDescription - /// Whether method is an deinitializer - public var isDeinitializer: Bool { - return selectorName == "deinit" - } - - /// Whether method is a failable initializer - public let isFailableInitializer: Bool - - // sourcery: skipEquality, skipDescription - /// Whether method is a convenience initializer - public var isConvenienceInitializer: Bool { - modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is required - public var isRequired: Bool { - modifiers.contains { $0.name == Attribute.Identifier.required.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is final - public var isFinal: Bool { - modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is mutating - public var isMutating: Bool { - modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is generic - public var isGeneric: Bool { - shortName.hasSuffix(">") - } - - // sourcery: skipEquality, skipDescription - /// Whether method is optional (in an Objective-C protocol) - public var isOptional: Bool { - modifiers.contains { $0.name == Attribute.Identifier.optional.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is nonisolated (this modifier only applies to actor methods) - public var isNonisolated: Bool { - modifiers.contains { $0.name == Attribute.Identifier.nonisolated.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is dynamic - public var isDynamic: Bool { - modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } - } - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public let annotations: Annotations - - public let documentation: Documentation - - /// Reference to type name where the method is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc - public let definedInTypeName: TypeName? - - // sourcery: skipEquality, skipDescription - /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` - public var actualDefinedInTypeName: TypeName? { - return definedInTypeName?.actualTypeName ?? definedInTypeName - } - - // sourcery: skipEquality, skipDescription - /// Reference to actual type where the object is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown - public var definedInType: Type? - - /// Method attributes, i.e. `@discardableResult` - public let attributes: AttributeList - - /// Method modifiers, i.e. `private` - public let modifiers: [SourceryModifier] - - // Underlying parser data, never to be used by anything else - // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport - /// :nodoc: - public var __parserData: Any? - - /// list of generic requirements - public var genericRequirements: [GenericRequirement] - - /// :nodoc: - public init(name: String, - selectorName: String? = nil, - parameters: [MethodParameter] = [], - returnTypeName: TypeName = TypeName(name: "Void"), - isAsync: Bool = false, - throws: Bool = false, - rethrows: Bool = false, - accessLevel: AccessLevel = .internal, - isStatic: Bool = false, - isClass: Bool = false, - isFailableInitializer: Bool = false, - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - definedInTypeName: TypeName? = nil, - genericRequirements: [GenericRequirement] = []) { - self.name = name - self.selectorName = selectorName ?? name - self.parameters = parameters - self.returnTypeName = returnTypeName - self.isAsync = isAsync - self.throws = `throws` - self.rethrows = `rethrows` - self.accessLevel = accessLevel.rawValue - self.isStatic = isStatic - self.isClass = isClass - self.isFailableInitializer = isFailableInitializer - self.attributes = attributes - self.modifiers = modifiers - self.annotations = annotations - self.documentation = documentation - self.definedInTypeName = definedInTypeName - self.genericRequirements = genericRequirements - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "selectorName = \\(String(describing: self.selectorName)), " - string += "parameters = \\(String(describing: self.parameters)), " - string += "returnTypeName = \\(String(describing: self.returnTypeName)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "`rethrows` = \\(String(describing: self.`rethrows`)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "isStatic = \\(String(describing: self.isStatic)), " - string += "isClass = \\(String(describing: self.isClass)), " - string += "isFailableInitializer = \\(String(describing: self.isFailableInitializer)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "definedInTypeName = \\(String(describing: self.definedInTypeName)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers)), " - string += "genericRequirements = \\(String(describing: self.genericRequirements))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Method else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "selectorName").trackDifference(actual: self.selectorName, expected: castObject.selectorName)) - results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) - results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "`rethrows`").trackDifference(actual: self.`rethrows`, expected: castObject.`rethrows`)) - results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) - results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) - results.append(contentsOf: DiffableResult(identifier: "isClass").trackDifference(actual: self.isClass, expected: castObject.isClass)) - results.append(contentsOf: DiffableResult(identifier: "isFailableInitializer").trackDifference(actual: self.isFailableInitializer, expected: castObject.isFailableInitializer)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) - results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) - results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) - results.append(contentsOf: DiffableResult(identifier: "genericRequirements").trackDifference(actual: self.genericRequirements, expected: castObject.genericRequirements)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.selectorName) - hasher.combine(self.parameters) - hasher.combine(self.returnTypeName) - hasher.combine(self.isAsync) - hasher.combine(self.`throws`) - hasher.combine(self.`rethrows`) - hasher.combine(self.accessLevel) - hasher.combine(self.isStatic) - hasher.combine(self.isClass) - hasher.combine(self.isFailableInitializer) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.definedInTypeName) - hasher.combine(self.attributes) - hasher.combine(self.modifiers) - hasher.combine(self.genericRequirements) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Method else { return false } - if self.name != rhs.name { return false } - if self.selectorName != rhs.selectorName { return false } - if self.parameters != rhs.parameters { return false } - if self.returnTypeName != rhs.returnTypeName { return false } - if self.isAsync != rhs.isAsync { return false } - if self.`throws` != rhs.`throws` { return false } - if self.`rethrows` != rhs.`rethrows` { return false } - if self.accessLevel != rhs.accessLevel { return false } - if self.isStatic != rhs.isStatic { return false } - if self.isClass != rhs.isClass { return false } - if self.isFailableInitializer != rhs.isFailableInitializer { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.definedInTypeName != rhs.definedInTypeName { return false } - if self.attributes != rhs.attributes { return false } - if self.modifiers != rhs.modifiers { return false } - if self.genericRequirements != rhs.genericRequirements { return false } - return true - } - -// sourcery:inline:Method.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let selectorName: String = aDecoder.decode(forKey: "selectorName") else { - withVaList(["selectorName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.selectorName = selectorName - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { - withVaList(["parameters"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { - withVaList(["returnTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.returnTypeName = returnTypeName - self.returnType = aDecoder.decode(forKey: "returnType") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.`rethrows` = aDecoder.decode(forKey: "`rethrows`") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { - withVaList(["accessLevel"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.accessLevel = accessLevel - self.isStatic = aDecoder.decode(forKey: "isStatic") - self.isClass = aDecoder.decode(forKey: "isClass") - self.isFailableInitializer = aDecoder.decode(forKey: "isFailableInitializer") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") - self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { - withVaList(["attributes"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { - withVaList(["modifiers"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.modifiers = modifiers - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.selectorName, forKey: "selectorName") - aCoder.encode(self.parameters, forKey: "parameters") - aCoder.encode(self.returnTypeName, forKey: "returnTypeName") - aCoder.encode(self.returnType, forKey: "returnType") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.`rethrows`, forKey: "`rethrows`") - aCoder.encode(self.accessLevel, forKey: "accessLevel") - aCoder.encode(self.isStatic, forKey: "isStatic") - aCoder.encode(self.isClass, forKey: "isClass") - aCoder.encode(self.isFailableInitializer, forKey: "isFailableInitializer") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") - aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.attributes, forKey: "attributes") - aCoder.encode(self.modifiers, forKey: "modifiers") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") - } -// sourcery:end -} - """), .init(name: "Modifier.swift", content: """ @@ -4499,7 +2062,9 @@ import Foundation public typealias SourceryModifier = Modifier /// modifier can be thing like `private`, `class`, `nonmutating` /// if a declaration has modifier like `private(set)` it's name will be `private` and detail will be `set` +#if canImport(ObjectiveC) @objcMembers +#endif public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJSExport, Diffable { /// The declaration modifier name. @@ -4532,6 +2097,8 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -4551,12 +2118,12 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name self.detail = aDecoder.decode(forKey: "detail") } @@ -4568,7 +2135,6 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS // sourcery:end } - """), .init(name: "ParserResultsComposed.swift", content: """ @@ -4649,37 +2215,42 @@ internal struct ParserResultsComposed { } } + // if it had contained types, they might have been fully defined and so their name has to be noted in uniques + private mutating func rewriteChildren(of type: Type) { + // child is never an extension so no need to check + for child in type.containedTypes { + typeMap[child.globalName] = child + rewriteChildren(of: child) + } + } + private mutating func unifyTypes() -> [Type] { /// Resolve actual names of extensions, as they could have been done on typealias and note updated child names in uniques if needed parsedTypes .filter { $0.isExtension } - .forEach { - let oldName = $0.globalName + .forEach { (type: Type) in + let oldName = type.globalName - if $0.parent == nil, $0.localName.contains(".") { - resolveExtensionOfNestedType($0) + let hasDotInLocalName = type.localName.contains(".") as Bool + if let _ = type.parent, hasDotInLocalName { + resolveExtensionOfNestedType(type) } - if let resolved = resolveGlobalName(for: oldName, containingType: $0.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { - $0.localName = resolved.replacingOccurrences(of: "\\($0.module != nil ? "\\($0.module!)." : "")", with: "") + if let resolved = resolveGlobalName(for: oldName, containingType: type.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { + var moduleName: String = "" + if let module = type.module { + moduleName = "\\(module)." + } + type.localName = resolved.replacingOccurrences(of: moduleName, with: "") } else { return } // nothing left to do - guard oldName != $0.globalName else { + guard oldName != type.globalName else { return } - - // if it had contained types, they might have been fully defined and so their name has to be noted in uniques - func rewriteChildren(of type: Type) { - // child is never an extension so no need to check - for child in type.containedTypes { - typeMap[child.globalName] = child - rewriteChildren(of: child) - } - } - rewriteChildren(of: $0) + rewriteChildren(of: type) } // extend all types with their extensions @@ -5194,7 +2765,9 @@ import Foundation public typealias SourceryProtocol = Protocol /// Describes Swift protocol +#if canImport(ObjectiveC) @objcMembers +#endif public final class Protocol: Type { /// Returns "protocol" @@ -5207,6 +2780,7 @@ public final class Protocol: Type { } } + // sourcery: skipCoding /// list of generic requirements public override var genericRequirements: [GenericRequirement] { didSet { @@ -5255,11 +2829,12 @@ public final class Protocol: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "associatedTypes = \\(String(describing: self.associatedTypes)), " + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("associatedTypes = \\(String(describing: self.associatedTypes)), ") return string } @@ -5274,6 +2849,8 @@ public final class Protocol: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.associatedTypes) @@ -5292,7 +2869,7 @@ public final class Protocol: Type { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let associatedTypes: [String: AssociatedType] = aDecoder.decode(forKey: "associatedTypes") else { + guard let associatedTypes: [String: AssociatedType] = aDecoder.decode(forKey: "associatedTypes") else { withVaList(["associatedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -5317,9 +2894,10 @@ public final class Protocol: Type { import Foundation -// sourcery: skipJSExport /// Describes a Swift [protocol composition](https://docs.swift.org/swift-book/ReferenceManual/Types.html#ID454). +#if canImport(ObjectiveC) @objcMembers +#endif public final class ProtocolComposition: Type { /// Returns "protocolComposition" @@ -5369,6 +2947,7 @@ public final class ProtocolComposition: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -5388,6 +2967,8 @@ public final class ProtocolComposition: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.composedTypeNames) @@ -5406,7 +2987,7 @@ public final class ProtocolComposition: Type { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let composedTypeNames: [TypeName] = aDecoder.decode(forKey: "composedTypeNames") else { + guard let composedTypeNames: [TypeName] = aDecoder.decode(forKey: "composedTypeNames") else { withVaList(["composedTypeNames"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -5426,6 +3007,111 @@ public final class ProtocolComposition: Type { } +"""), + .init(name: "Set.swift", content: +""" +import Foundation + +/// Describes set type +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class SetType: NSObject, SourceryModel, Diffable { + /// Type name used in declaration + public var name: String + + /// Array element type name + public var elementTypeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Array element type, if known + public var elementType: Type? + + /// :nodoc: + public init(name: String, elementTypeName: TypeName, elementType: Type? = nil) { + self.name = name + self.elementTypeName = elementTypeName + self.elementType = elementType + } + + /// Returns array as generic type + public var asGeneric: GenericType { + GenericType(name: "Set", typeParameters: [ + .init(typeName: elementTypeName) + ]) + } + + public var asSource: String { + "[\\(elementTypeName.asSource)]" + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("elementTypeName = \\(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? SetType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "elementTypeName").trackDifference(actual: self.elementTypeName, expected: castObject.elementTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.elementTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? SetType else { return false } + if self.name != rhs.name { return false } + if self.elementTypeName != rhs.elementTypeName { return false } + return true + } + +// sourcery:inline:SetType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { + withVaList(["elementTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.elementTypeName = elementTypeName + self.elementType = aDecoder.decode(forKey: "elementType") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.elementTypeName, forKey: "elementTypeName") + aCoder.encode(self.elementType, forKey: "elementType") + } +// sourcery:end +} + """), .init(name: "Struct.swift", content: """ @@ -5441,7 +3127,9 @@ import Foundation // sourcery: skipDescription /// Describes Swift struct +#if canImport(ObjectiveC) @objcMembers +#endif public final class Struct: Type { /// Returns "struct" @@ -5487,6 +3175,7 @@ public final class Struct: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -5504,6 +3193,8 @@ public final class Struct: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -5530,15 +3221,2133 @@ public final class Struct: Type { // sourcery:end } +"""), + .init(name: "TemplateContext.swift", content: +""" +// +// Created by Krzysztof Zablocki on 31/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// + +import Foundation + +/// :nodoc: +// sourcery: skipCoding +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class TemplateContext: NSObject, SourceryModel, NSCoding, Diffable { + // sourcery: skipJSExport + public let parserResult: FileParserResult? + public let functions: [SourceryMethod] + public let types: Types + public let argument: [String: NSObject] + + // sourcery: skipDescription + public var type: [String: Type] { + return types.typesByName + } + + public init(parserResult: FileParserResult?, types: Types, functions: [SourceryMethod], arguments: [String: NSObject]) { + self.parserResult = parserResult + self.types = types + self.functions = functions + self.argument = arguments + } + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let parserResult: FileParserResult = aDecoder.decode(forKey: "parserResult") else { + withVaList(["parserResult"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found. FileParserResults are required for template context that needs persisting.", arguments: arguments) + } + fatalError() + } + guard let argument: [String: NSObject] = aDecoder.decode(forKey: "argument") else { + withVaList(["argument"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + } + + // if we want to support multiple cycles of encode / decode we need deep copy because composer changes reference types + let fileParserResultCopy: FileParserResult? = nil +// fileParserResultCopy = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(NSKeyedArchiver.archivedData(withRootObject: parserResult)) as? FileParserResult + + let composed = Composer.uniqueTypesAndFunctions(parserResult) + self.types = .init(types: composed.types, typealiases: composed.typealiases) + self.functions = composed.functions + + self.parserResult = fileParserResultCopy + self.argument = argument + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.parserResult, forKey: "parserResult") + aCoder.encode(self.argument, forKey: "argument") + } + + public var stencilContext: [String: Any] { + return [ + "types": types, + "functions": functions, + "type": types.typesByName, + "argument": argument + ] + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("parserResult = \\(String(describing: self.parserResult)), ") + string.append("functions = \\(String(describing: self.functions)), ") + string.append("types = \\(String(describing: self.types)), ") + string.append("argument = \\(String(describing: self.argument)), ") + string.append("stencilContext = \\(String(describing: self.stencilContext))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? TemplateContext else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "parserResult").trackDifference(actual: self.parserResult, expected: castObject.parserResult)) + results.append(contentsOf: DiffableResult(identifier: "functions").trackDifference(actual: self.functions, expected: castObject.functions)) + results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) + results.append(contentsOf: DiffableResult(identifier: "argument").trackDifference(actual: self.argument, expected: castObject.argument)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.parserResult) + hasher.combine(self.functions) + hasher.combine(self.types) + hasher.combine(self.argument) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? TemplateContext else { return false } + if self.parserResult != rhs.parserResult { return false } + if self.functions != rhs.functions { return false } + if self.types != rhs.types { return false } + if self.argument != rhs.argument { return false } + return true + } + + // sourcery: skipDescription, skipEquality + public var jsContext: [String: Any] { + return [ + "types": [ + "all": types.all, + "protocols": types.protocols, + "classes": types.classes, + "structs": types.structs, + "enums": types.enums, + "extensions": types.extensions, + "based": types.based, + "inheriting": types.inheriting, + "implementing": types.implementing, + "protocolCompositions": types.protocolCompositions + ] as [String : Any], + "functions": functions, + "type": types.typesByName, + "argument": argument + ] + } + +} + +extension ProcessInfo { + /// :nodoc: + public var context: TemplateContext! { + return NSKeyedUnarchiver.unarchiveObject(withFile: arguments[1]) as? TemplateContext + } +} + +"""), + .init(name: "Typealias.swift", content: +""" +import Foundation + +/// :nodoc: +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class Typealias: NSObject, Typed, SourceryModel, Diffable { + // New typealias name + public let aliasName: String + + // Target name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + public var type: Type? + + /// module in which this typealias was declared + public var module: String? + + /// typealias annotations + public var annotations: Annotations = [:] + + /// typealias documentation + public var documentation: Documentation = [] + + // sourcery: skipEquality, skipDescription + public var parent: Type? { + didSet { + parentName = parent?.name + } + } + + /// Type access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let accessLevel: String + + var parentName: String? + + public var name: String { + if let parentName = parent?.name { + return "\\(module != nil ? "\\(module!)." : "")\\(parentName).\\(aliasName)" + } else { + return "\\(module != nil ? "\\(module!)." : "")\\(aliasName)" + } + } + + public init(aliasName: String = "", typeName: TypeName, accessLevel: AccessLevel = .internal, parent: Type? = nil, module: String? = nil, annotations: [String: NSObject] = [:], documentation: [String] = []) { + self.aliasName = aliasName + self.typeName = typeName + self.accessLevel = accessLevel.rawValue + self.parent = parent + self.parentName = parent?.name + self.module = module + self.annotations = annotations + self.documentation = documentation + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("aliasName = \\(String(describing: self.aliasName)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("module = \\(String(describing: self.module)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("parentName = \\(String(describing: self.parentName)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Typealias else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "aliasName").trackDifference(actual: self.aliasName, expected: castObject.aliasName)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: castObject.module)) + results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) + results.append(contentsOf: DiffableResult(identifier: "parentName").trackDifference(actual: self.parentName, expected: castObject.parentName)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.aliasName) + hasher.combine(self.typeName) + hasher.combine(self.module) + hasher.combine(self.accessLevel) + hasher.combine(self.parentName) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Typealias else { return false } + if self.aliasName != rhs.aliasName { return false } + if self.typeName != rhs.typeName { return false } + if self.module != rhs.module { return false } + if self.accessLevel != rhs.accessLevel { return false } + if self.parentName != rhs.parentName { return false } + if self.documentation != rhs.documentation { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:Typealias.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let aliasName: String = aDecoder.decode(forKey: "aliasName") else { + withVaList(["aliasName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.aliasName = aliasName + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + self.module = aDecoder.decode(forKey: "module") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.parent = aDecoder.decode(forKey: "parent") + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + withVaList(["accessLevel"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.accessLevel = accessLevel + self.parentName = aDecoder.decode(forKey: "parentName") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.aliasName, forKey: "aliasName") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.module, forKey: "module") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.parent, forKey: "parent") + aCoder.encode(self.accessLevel, forKey: "accessLevel") + aCoder.encode(self.parentName, forKey: "parentName") + } +// sourcery:end +} + +"""), + .init(name: "Typed.swift", content: +""" +import Foundation + +/// Descibes typed declaration, i.e. variable, method parameter, tuple element, enum case associated value +public protocol Typed { + + // sourcery: skipEquality, skipDescription + /// Type, if known + var type: Type? { get } + + // sourcery: skipEquality, skipDescription + /// Type name + var typeName: TypeName { get } + + // sourcery: skipEquality, skipDescription + /// Whether type is optional + var isOptional: Bool { get } + + // sourcery: skipEquality, skipDescription + /// Whether type is implicitly unwrapped optional + var isImplicitlyUnwrappedOptional: Bool { get } + + // sourcery: skipEquality, skipDescription + /// Type name without attributes and optional type information + var unwrappedTypeName: String { get } +} + +"""), + .init(name: "AssociatedType.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Describes Swift AssociatedType +@objcMembers +public final class AssociatedType: NSObject, SourceryModel { + /// Associated type name + public let name: String + + /// Associated type type constraint name, if specified + public let typeName: TypeName? + + // sourcery: skipEquality, skipDescription + /// Associated type constrained type, if known, i.e. if the type is declared in the scanned sources. + public var type: Type? + + /// :nodoc: + public init(name: String, typeName: TypeName? = nil, type: Type? = nil) { + self.name = name + self.typeName = typeName + self.type = type + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? AssociatedType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.typeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? AssociatedType else { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + return true + } + +// sourcery:inline:AssociatedType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.typeName = aDecoder.decode(forKey: "typeName") + self.type = aDecoder.decode(forKey: "type") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + } +// sourcery:end +} +#endif + +"""), + .init(name: "AssociatedValue.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if canImport(ObjectiveC) +import Foundation + +/// Defines enum case associated value +@objcMembers +public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable { + + /// Associated value local name. + /// This is a name to be used to construct enum case value + public let localName: String? + + /// Associated value external name. + /// This is a name to be used to access value in value-bindig + public let externalName: String? + + /// Associated value type name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Associated value type, if known + public var type: Type? + + /// Associated value default value + public let defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(localName: String?, externalName: String?, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { + self.localName = localName + self.externalName = externalName + self.typeName = typeName + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + } + + convenience init(name: String? = nil, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { + self.init(localName: name, externalName: name, typeName: typeName, type: type, defaultValue: defaultValue, annotations: annotations) + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("localName = \\(String(describing: self.localName)), ") + string.append("externalName = \\(String(describing: self.externalName)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? AssociatedValue else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "localName").trackDifference(actual: self.localName, expected: castObject.localName)) + results.append(contentsOf: DiffableResult(identifier: "externalName").trackDifference(actual: self.externalName, expected: castObject.externalName)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.localName) + hasher.combine(self.externalName) + hasher.combine(self.typeName) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? AssociatedValue else { return false } + if self.localName != rhs.localName { return false } + if self.externalName != rhs.externalName { return false } + if self.typeName != rhs.typeName { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:AssociatedValue.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.localName = aDecoder.decode(forKey: "localName") + self.externalName = aDecoder.decode(forKey: "externalName") + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.localName, forKey: "localName") + aCoder.encode(self.externalName, forKey: "externalName") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } +// sourcery:end + +} +#endif + +"""), + .init(name: "Closure.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Describes closure type +@objcMembers +public final class ClosureType: NSObject, SourceryModel, Diffable { + + /// Type name used in declaration with stripped whitespaces and new lines + public let name: String + + /// List of closure parameters + public let parameters: [ClosureParameter] + + /// Return value type name + public let returnTypeName: TypeName + + /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` + public var actualReturnTypeName: TypeName { + return returnTypeName.actualTypeName ?? returnTypeName + } + + // sourcery: skipEquality, skipDescription + /// Actual return value type, if known + public var returnType: Type? + + // sourcery: skipEquality, skipDescription + /// Whether return value type is optional + public var isOptionalReturnType: Bool { + return returnTypeName.isOptional + } + + // sourcery: skipEquality, skipDescription + /// Whether return value type is implicitly unwrapped optional + public var isImplicitlyUnwrappedOptionalReturnType: Bool { + return returnTypeName.isImplicitlyUnwrappedOptional + } + + // sourcery: skipEquality, skipDescription + /// Return value type name without attributes and optional type information + public var unwrappedReturnTypeName: String { + return returnTypeName.unwrappedTypeName + } + + /// Whether method is async method + public let isAsync: Bool + + /// async keyword + public let asyncKeyword: String? + + /// Whether closure throws + public let `throws`: Bool + + /// throws or rethrows keyword + public let throwsOrRethrowsKeyword: String? + + /// :nodoc: + public init(name: String, parameters: [ClosureParameter], returnTypeName: TypeName, returnType: Type? = nil, asyncKeyword: String? = nil, throwsOrRethrowsKeyword: String? = nil) { + self.name = name + self.parameters = parameters + self.returnTypeName = returnTypeName + self.returnType = returnType + self.asyncKeyword = asyncKeyword + self.isAsync = asyncKeyword != nil + self.throwsOrRethrowsKeyword = throwsOrRethrowsKeyword + self.`throws` = throwsOrRethrowsKeyword != nil + } + + public var asSource: String { + "\\(parameters.asSource)\\(asyncKeyword != nil ? " \\(asyncKeyword!)" : "")\\(throwsOrRethrowsKeyword != nil ? " \\(throwsOrRethrowsKeyword!)" : "") -> \\(returnTypeName.asSource)" + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("asyncKeyword = \\(String(describing: self.asyncKeyword)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("throwsOrRethrowsKeyword = \\(String(describing: self.throwsOrRethrowsKeyword)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? ClosureType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) + results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "asyncKeyword").trackDifference(actual: self.asyncKeyword, expected: castObject.asyncKeyword)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "throwsOrRethrowsKeyword").trackDifference(actual: self.throwsOrRethrowsKeyword, expected: castObject.throwsOrRethrowsKeyword)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.parameters) + hasher.combine(self.returnTypeName) + hasher.combine(self.isAsync) + hasher.combine(self.asyncKeyword) + hasher.combine(self.`throws`) + hasher.combine(self.throwsOrRethrowsKeyword) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? ClosureType else { return false } + if self.name != rhs.name { return false } + if self.parameters != rhs.parameters { return false } + if self.returnTypeName != rhs.returnTypeName { return false } + if self.isAsync != rhs.isAsync { return false } + if self.asyncKeyword != rhs.asyncKeyword { return false } + if self.`throws` != rhs.`throws` { return false } + if self.throwsOrRethrowsKeyword != rhs.throwsOrRethrowsKeyword { return false } + return true + } + +// sourcery:inline:ClosureType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let parameters: [ClosureParameter] = aDecoder.decode(forKey: "parameters") else { + withVaList(["parameters"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.parameters = parameters + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + withVaList(["returnTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.returnTypeName = returnTypeName + self.returnType = aDecoder.decode(forKey: "returnType") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.asyncKeyword = aDecoder.decode(forKey: "asyncKeyword") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.throwsOrRethrowsKeyword = aDecoder.decode(forKey: "throwsOrRethrowsKeyword") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.parameters, forKey: "parameters") + aCoder.encode(self.returnTypeName, forKey: "returnTypeName") + aCoder.encode(self.returnType, forKey: "returnType") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.asyncKeyword, forKey: "asyncKeyword") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.throwsOrRethrowsKeyword, forKey: "throwsOrRethrowsKeyword") + } +// sourcery:end + +} +#endif + +"""), + .init(name: "ClosureParameter.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +// sourcery: skipDiffing +@objcMembers +public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { + /// Parameter external name + public var argumentLabel: String? + + /// Parameter internal name + public let name: String? + + /// Parameter type name + public let typeName: TypeName + + /// Parameter flag whether it's inout or not + public let `inout`: Bool + + // sourcery: skipEquality, skipDescription + /// Parameter type, if known + public var type: Type? + + /// Parameter if the argument has a variadic type or not + public let isVariadic: Bool + + /// Parameter type attributes, i.e. `@escaping` + public var typeAttributes: AttributeList { + return typeName.attributes + } + + /// Method parameter default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(argumentLabel: String? = nil, name: String? = nil, typeName: TypeName, type: Type? = nil, + defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, + isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = argumentLabel + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + public var asSource: String { + let typeInfo = "\\(`inout` ? "inout " : "")\\(typeName.asSource)\\(isVariadic ? "..." : "")" + if argumentLabel?.nilIfNotValidParameterName == nil, name?.nilIfNotValidParameterName == nil { + return typeInfo + } + + let typeSuffix = ": \\(typeInfo)" + guard argumentLabel != name else { + return name ?? "" + typeSuffix + } + + let labels = [argumentLabel ?? "_", name?.nilIfEmpty] + .compactMap { $0 } + .joined(separator: " ") + + return (labels.nilIfEmpty ?? "_") + typeSuffix + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.argumentLabel) + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.`inout`) + hasher.combine(self.isVariadic) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("argumentLabel = \\(String(describing: self.argumentLabel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("`inout` = \\(String(describing: self.`inout`)), ") + string.append("typeAttributes = \\(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? ClosureParameter else { return false } + if self.argumentLabel != rhs.argumentLabel { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.`inout` != rhs.`inout` { return false } + if self.isVariadic != rhs.isVariadic { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + + // sourcery:inline:ClosureParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") + self.name = aDecoder.decode(forKey: "name") + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.`inout` = aDecoder.decode(forKey: "`inout`") + self.type = aDecoder.decode(forKey: "type") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.argumentLabel, forKey: "argumentLabel") + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.`inout`, forKey: "`inout`") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.isVariadic, forKey: "isVariadic") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } + + // sourcery:end +} + +extension Array where Element == ClosureParameter { + public var asSource: String { + "(\\(map { $0.asSource }.joined(separator: ", ")))" + } +} +#endif + +"""), + .init(name: "Enum.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// + +#if canImport(ObjectiveC) +import Foundation + +/// Defines Swift enum +@objcMembers +public final class Enum: Type { + // sourcery: skipDescription + /// Returns "enum" + public override var kind: String { return "enum" } + + /// Enum cases + public var cases: [EnumCase] + + /** + Enum raw value type name, if any. This type is removed from enum's `based` and `inherited` types collections. + + - important: Unless raw type is specified explicitly via type alias RawValue it will be set to the first type in the inheritance chain. + So if your enum does not have raw value but implements protocols you'll have to specify conformance to these protocols via extension to get enum with nil raw value type and all based and inherited types. + */ + public var rawTypeName: TypeName? { + didSet { + if let rawTypeName = rawTypeName { + hasRawType = true + if let index = inheritedTypes.firstIndex(of: rawTypeName.name) { + inheritedTypes.remove(at: index) + } + if based[rawTypeName.name] != nil { + based[rawTypeName.name] = nil + } + } else { + hasRawType = false + } + } + } + + // sourcery: skipDescription, skipEquality + /// :nodoc: + public private(set) var hasRawType: Bool + + // sourcery: skipDescription, skipEquality + /// Enum raw value type, if known + public var rawType: Type? + + // sourcery: skipEquality, skipDescription, skipCoding + /// Names of types or protocols this type inherits from, including unknown (not scanned) types + public override var based: [String: String] { + didSet { + if let rawTypeName = rawTypeName, based[rawTypeName.name] != nil { + based[rawTypeName.name] = nil + } + } + } + + /// Whether enum contains any associated values + public var hasAssociatedValues: Bool { + return cases.contains(where: { $0.hasAssociatedValue }) + } + + /// :nodoc: + public init(name: String = "", + parent: Type? = nil, + accessLevel: AccessLevel = .internal, + isExtension: Bool = false, + inheritedTypes: [String] = [], + rawTypeName: TypeName? = nil, + cases: [EnumCase] = [], + variables: [Variable] = [], + methods: [Method] = [], + containedTypes: [Type] = [], + typealiases: [Typealias] = [], + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + isGeneric: Bool = false) { + + self.cases = cases + self.rawTypeName = rawTypeName + self.hasRawType = rawTypeName != nil || !inheritedTypes.isEmpty + + super.init(name: name, parent: parent, accessLevel: accessLevel, isExtension: isExtension, variables: variables, methods: methods, inheritedTypes: inheritedTypes, containedTypes: containedTypes, typealiases: typealiases, attributes: attributes, modifiers: modifiers, annotations: annotations, documentation: documentation, isGeneric: isGeneric) + + if let rawTypeName = rawTypeName?.name, let index = self.inheritedTypes.firstIndex(of: rawTypeName) { + self.inheritedTypes.remove(at: index) + } + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = super.description + string.append(", ") + string.append("cases = \\(String(describing: self.cases)), ") + string.append("rawTypeName = \\(String(describing: self.rawTypeName)), ") + string.append("hasAssociatedValues = \\(String(describing: self.hasAssociatedValues))") + return string + } + + override public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Enum else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "cases").trackDifference(actual: self.cases, expected: castObject.cases)) + results.append(contentsOf: DiffableResult(identifier: "rawTypeName").trackDifference(actual: self.rawTypeName, expected: castObject.rawTypeName)) + results.append(contentsOf: super.diffAgainst(castObject)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.cases) + hasher.combine(self.rawTypeName) + hasher.combine(super.hash) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Enum else { return false } + if self.cases != rhs.cases { return false } + if self.rawTypeName != rhs.rawTypeName { return false } + return super.isEqual(rhs) + } + +// sourcery:inline:Enum.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let cases: [EnumCase] = aDecoder.decode(forKey: "cases") else { + withVaList(["cases"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.cases = cases + self.rawTypeName = aDecoder.decode(forKey: "rawTypeName") + self.hasRawType = aDecoder.decode(forKey: "hasRawType") + self.rawType = aDecoder.decode(forKey: "rawType") + super.init(coder: aDecoder) + } + + /// :nodoc: + override public func encode(with aCoder: NSCoder) { + super.encode(with: aCoder) + aCoder.encode(self.cases, forKey: "cases") + aCoder.encode(self.rawTypeName, forKey: "rawTypeName") + aCoder.encode(self.hasRawType, forKey: "hasRawType") + aCoder.encode(self.rawType, forKey: "rawType") + } +// sourcery:end +} +#endif + +"""), + .init(name: "EnumCase.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if canImport(ObjectiveC) +import Foundation + +/// Defines enum case +@objcMembers +public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable { + + /// Enum case name + public let name: String + + /// Enum case raw value, if any + public let rawValue: String? + + /// Enum case associated values + public let associatedValues: [AssociatedValue] + + /// Enum case annotations + public var annotations: Annotations = [:] + + public var documentation: Documentation = [] + + /// Whether enum case is indirect + public let indirect: Bool + + /// Whether enum case has associated value + public var hasAssociatedValue: Bool { + return !associatedValues.isEmpty + } + + // Underlying parser data, never to be used by anything else + // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport + /// :nodoc: + public var __parserData: Any? + + /// :nodoc: + public init(name: String, rawValue: String? = nil, associatedValues: [AssociatedValue] = [], annotations: [String: NSObject] = [:], documentation: [String] = [], indirect: Bool = false) { + self.name = name + self.rawValue = rawValue + self.associatedValues = associatedValues + self.annotations = annotations + self.documentation = documentation + self.indirect = indirect + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("rawValue = \\(String(describing: self.rawValue)), ") + string.append("associatedValues = \\(String(describing: self.associatedValues)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("indirect = \\(String(describing: self.indirect)), ") + string.append("hasAssociatedValue = \\(String(describing: self.hasAssociatedValue))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? EnumCase else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "rawValue").trackDifference(actual: self.rawValue, expected: castObject.rawValue)) + results.append(contentsOf: DiffableResult(identifier: "associatedValues").trackDifference(actual: self.associatedValues, expected: castObject.associatedValues)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "indirect").trackDifference(actual: self.indirect, expected: castObject.indirect)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.rawValue) + hasher.combine(self.associatedValues) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.indirect) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? EnumCase else { return false } + if self.name != rhs.name { return false } + if self.rawValue != rhs.rawValue { return false } + if self.associatedValues != rhs.associatedValues { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.indirect != rhs.indirect { return false } + return true + } + +// sourcery:inline:EnumCase.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.rawValue = aDecoder.decode(forKey: "rawValue") + guard let associatedValues: [AssociatedValue] = aDecoder.decode(forKey: "associatedValues") else { + withVaList(["associatedValues"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.associatedValues = associatedValues + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.indirect = aDecoder.decode(forKey: "indirect") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.rawValue, forKey: "rawValue") + aCoder.encode(self.associatedValues, forKey: "associatedValues") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.indirect, forKey: "indirect") + } +// sourcery:end +} +#endif + +"""), + .init(name: "GenericParameter.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic parameter +@objcMembers +public final class GenericParameter: NSObject, SourceryModel, Diffable { + + /// Generic parameter name + public var name: String + + /// Generic parameter inherited type + public var inheritedTypeName: TypeName? + + /// :nodoc: + public init(name: String, inheritedTypeName: TypeName? = nil) { + self.name = name + self.inheritedTypeName = inheritedTypeName + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("inheritedTypeName = \\(String(describing: self.inheritedTypeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "inheritedTypeName").trackDifference(actual: self.inheritedTypeName, expected: castObject.inheritedTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.inheritedTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericParameter else { return false } + if self.name != rhs.name { return false } + if self.inheritedTypeName != rhs.inheritedTypeName { return false } + return true + } + +// sourcery:inline:GenericParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.inheritedTypeName = aDecoder.decode(forKey: "inheritedTypeName") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.inheritedTypeName, forKey: "inheritedTypeName") + } + +// sourcery:end +} +#endif + +"""), + .init(name: "GenericRequirement.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic requirement +@objcMembers +public class GenericRequirement: NSObject, SourceryModel, Diffable { + + public enum Relationship: String { + case equals + case conformsTo + + var syntax: String { + switch self { + case .equals: + return "==" + case .conformsTo: + return ":" + } + } + } + + public var leftType: AssociatedType + public let rightType: GenericTypeParameter + + /// relationship name + public let relationship: String + + /// Syntax e.g. `==` or `:` + public let relationshipSyntax: String + + public init(leftType: AssociatedType, rightType: GenericTypeParameter, relationship: Relationship) { + self.leftType = leftType + self.rightType = rightType + self.relationship = relationship.rawValue + self.relationshipSyntax = relationship.syntax + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("leftType = \\(String(describing: self.leftType)), ") + string.append("rightType = \\(String(describing: self.rightType)), ") + string.append("relationship = \\(String(describing: self.relationship)), ") + string.append("relationshipSyntax = \\(String(describing: self.relationshipSyntax))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericRequirement else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "leftType").trackDifference(actual: self.leftType, expected: castObject.leftType)) + results.append(contentsOf: DiffableResult(identifier: "rightType").trackDifference(actual: self.rightType, expected: castObject.rightType)) + results.append(contentsOf: DiffableResult(identifier: "relationship").trackDifference(actual: self.relationship, expected: castObject.relationship)) + results.append(contentsOf: DiffableResult(identifier: "relationshipSyntax").trackDifference(actual: self.relationshipSyntax, expected: castObject.relationshipSyntax)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.leftType) + hasher.combine(self.rightType) + hasher.combine(self.relationship) + hasher.combine(self.relationshipSyntax) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericRequirement else { return false } + if self.leftType != rhs.leftType { return false } + if self.rightType != rhs.rightType { return false } + if self.relationship != rhs.relationship { return false } + if self.relationshipSyntax != rhs.relationshipSyntax { return false } + return true + } + + // sourcery:inline:GenericRequirement.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { + withVaList(["leftType"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.leftType = leftType + guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { + withVaList(["rightType"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.rightType = rightType + guard let relationship: String = aDecoder.decode(forKey: "relationship") else { + withVaList(["relationship"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.relationship = relationship + guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { + withVaList(["relationshipSyntax"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.relationshipSyntax = relationshipSyntax + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.leftType, forKey: "leftType") + aCoder.encode(self.rightType, forKey: "rightType") + aCoder.encode(self.relationship, forKey: "relationship") + aCoder.encode(self.relationshipSyntax, forKey: "relationshipSyntax") + } + // sourcery:end +} +#endif + +"""), + .init(name: "GenericTypeParameter.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic type parameter +@objcMembers +public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { + + /// Generic parameter type name + public var typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Generic parameter type, if known + public var type: Type? + + /// :nodoc: + public init(typeName: TypeName, type: Type? = nil) { + self.typeName = typeName + self.type = type + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("typeName = \\(String(describing: self.typeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericTypeParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.typeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericTypeParameter else { return false } + if self.typeName != rhs.typeName { return false } + return true + } + +// sourcery:inline:GenericTypeParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + } + +// sourcery:end +} +#endif + +"""), + .init(name: "Method.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// :nodoc: +public typealias SourceryMethod = Method + +/// Describes method +@objc(SwiftMethod) @objcMembers +public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable { + + /// Full method name, including generic constraints, i.e. `foo(bar: T)` + public let name: String + + /// Method name including arguments names, i.e. `foo(bar:)` + public var selectorName: String + + // sourcery: skipEquality, skipDescription + /// Method name without arguments names and parenthesis, i.e. `foo` + public var shortName: String { + return name.range(of: "(").map({ String(name[..<$0.lowerBound]) }) ?? name + } + + // sourcery: skipEquality, skipDescription + /// Method name without arguments names, parenthesis and generic types, i.e. `foo` (can be used to generate code for method call) + public var callName: String { + return shortName.range(of: "<").map({ String(shortName[..<$0.lowerBound]) }) ?? shortName + } + + /// Method parameters + public var parameters: [MethodParameter] + + /// Return value type name used in declaration, including generic constraints, i.e. `where T: Equatable` + public var returnTypeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` + public var actualReturnTypeName: TypeName { + return returnTypeName.actualTypeName ?? returnTypeName + } + + // sourcery: skipEquality, skipDescription + /// Actual return value type, if known + public var returnType: Type? + + // sourcery: skipEquality, skipDescription + /// Whether return value type is optional + public var isOptionalReturnType: Bool { + return returnTypeName.isOptional || isFailableInitializer + } + + // sourcery: skipEquality, skipDescription + /// Whether return value type is implicitly unwrapped optional + public var isImplicitlyUnwrappedOptionalReturnType: Bool { + return returnTypeName.isImplicitlyUnwrappedOptional + } + + // sourcery: skipEquality, skipDescription + /// Return value type name without attributes and optional type information + public var unwrappedReturnTypeName: String { + return returnTypeName.unwrappedTypeName + } + + /// Whether method is async method + public let isAsync: Bool + + /// Whether method throws + public let `throws`: Bool + + /// Whether method rethrows + public let `rethrows`: Bool + + /// Method access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let accessLevel: String + + /// Whether method is a static method + public let isStatic: Bool + + /// Whether method is a class method + public let isClass: Bool + + // sourcery: skipEquality, skipDescription + /// Whether method is an initializer + public var isInitializer: Bool { + return selectorName.hasPrefix("init(") || selectorName == "init" + } + + // sourcery: skipEquality, skipDescription + /// Whether method is an deinitializer + public var isDeinitializer: Bool { + return selectorName == "deinit" + } + + /// Whether method is a failable initializer + public let isFailableInitializer: Bool + + // sourcery: skipEquality, skipDescription + /// Whether method is a convenience initializer + public var isConvenienceInitializer: Bool { + modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is required + public var isRequired: Bool { + modifiers.contains { $0.name == Attribute.Identifier.required.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is final + public var isFinal: Bool { + modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is mutating + public var isMutating: Bool { + modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is generic + public var isGeneric: Bool { + shortName.hasSuffix(">") + } + + // sourcery: skipEquality, skipDescription + /// Whether method is optional (in an Objective-C protocol) + public var isOptional: Bool { + modifiers.contains { $0.name == Attribute.Identifier.optional.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is nonisolated (this modifier only applies to actor methods) + public var isNonisolated: Bool { + modifiers.contains { $0.name == Attribute.Identifier.nonisolated.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is dynamic + public var isDynamic: Bool { + modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } + } + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public let annotations: Annotations + + public let documentation: Documentation + + /// Reference to type name where the method is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc + public let definedInTypeName: TypeName? + + // sourcery: skipEquality, skipDescription + /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` + public var actualDefinedInTypeName: TypeName? { + return definedInTypeName?.actualTypeName ?? definedInTypeName + } + + // sourcery: skipEquality, skipDescription + /// Reference to actual type where the object is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown + public var definedInType: Type? + + /// Method attributes, i.e. `@discardableResult` + public let attributes: AttributeList + + /// Method modifiers, i.e. `private` + public let modifiers: [SourceryModifier] + + // Underlying parser data, never to be used by anything else + // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport + /// :nodoc: + public var __parserData: Any? + + /// list of generic requirements + public var genericRequirements: [GenericRequirement] + + /// :nodoc: + public init(name: String, + selectorName: String? = nil, + parameters: [MethodParameter] = [], + returnTypeName: TypeName = TypeName(name: "Void"), + isAsync: Bool = false, + throws: Bool = false, + rethrows: Bool = false, + accessLevel: AccessLevel = .internal, + isStatic: Bool = false, + isClass: Bool = false, + isFailableInitializer: Bool = false, + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + definedInTypeName: TypeName? = nil, + genericRequirements: [GenericRequirement] = []) { + self.name = name + self.selectorName = selectorName ?? name + self.parameters = parameters + self.returnTypeName = returnTypeName + self.isAsync = isAsync + self.throws = `throws` + self.rethrows = `rethrows` + self.accessLevel = accessLevel.rawValue + self.isStatic = isStatic + self.isClass = isClass + self.isFailableInitializer = isFailableInitializer + self.attributes = attributes + self.modifiers = modifiers + self.annotations = annotations + self.documentation = documentation + self.definedInTypeName = definedInTypeName + self.genericRequirements = genericRequirements + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("selectorName = \\(String(describing: self.selectorName)), ") + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("`rethrows` = \\(String(describing: self.`rethrows`)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("isStatic = \\(String(describing: self.isStatic)), ") + string.append("isClass = \\(String(describing: self.isClass)), ") + string.append("isFailableInitializer = \\(String(describing: self.isFailableInitializer)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers)), ") + string.append("genericRequirements = \\(String(describing: self.genericRequirements))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Method else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "selectorName").trackDifference(actual: self.selectorName, expected: castObject.selectorName)) + results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) + results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "`rethrows`").trackDifference(actual: self.`rethrows`, expected: castObject.`rethrows`)) + results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) + results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) + results.append(contentsOf: DiffableResult(identifier: "isClass").trackDifference(actual: self.isClass, expected: castObject.isClass)) + results.append(contentsOf: DiffableResult(identifier: "isFailableInitializer").trackDifference(actual: self.isFailableInitializer, expected: castObject.isFailableInitializer)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) + results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) + results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) + results.append(contentsOf: DiffableResult(identifier: "genericRequirements").trackDifference(actual: self.genericRequirements, expected: castObject.genericRequirements)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.selectorName) + hasher.combine(self.parameters) + hasher.combine(self.returnTypeName) + hasher.combine(self.isAsync) + hasher.combine(self.`throws`) + hasher.combine(self.`rethrows`) + hasher.combine(self.accessLevel) + hasher.combine(self.isStatic) + hasher.combine(self.isClass) + hasher.combine(self.isFailableInitializer) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.definedInTypeName) + hasher.combine(self.attributes) + hasher.combine(self.modifiers) + hasher.combine(self.genericRequirements) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Method else { return false } + if self.name != rhs.name { return false } + if self.selectorName != rhs.selectorName { return false } + if self.parameters != rhs.parameters { return false } + if self.returnTypeName != rhs.returnTypeName { return false } + if self.isAsync != rhs.isAsync { return false } + if self.`throws` != rhs.`throws` { return false } + if self.`rethrows` != rhs.`rethrows` { return false } + if self.accessLevel != rhs.accessLevel { return false } + if self.isStatic != rhs.isStatic { return false } + if self.isClass != rhs.isClass { return false } + if self.isFailableInitializer != rhs.isFailableInitializer { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.definedInTypeName != rhs.definedInTypeName { return false } + if self.attributes != rhs.attributes { return false } + if self.modifiers != rhs.modifiers { return false } + if self.genericRequirements != rhs.genericRequirements { return false } + return true + } + +// sourcery:inline:Method.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let selectorName: String = aDecoder.decode(forKey: "selectorName") else { + withVaList(["selectorName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.selectorName = selectorName + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + withVaList(["parameters"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.parameters = parameters + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + withVaList(["returnTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.returnTypeName = returnTypeName + self.returnType = aDecoder.decode(forKey: "returnType") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.`rethrows` = aDecoder.decode(forKey: "`rethrows`") + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + withVaList(["accessLevel"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.accessLevel = accessLevel + self.isStatic = aDecoder.decode(forKey: "isStatic") + self.isClass = aDecoder.decode(forKey: "isClass") + self.isFailableInitializer = aDecoder.decode(forKey: "isFailableInitializer") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") + self.definedInType = aDecoder.decode(forKey: "definedInType") + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + withVaList(["attributes"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.attributes = attributes + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + withVaList(["modifiers"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.modifiers = modifiers + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.selectorName, forKey: "selectorName") + aCoder.encode(self.parameters, forKey: "parameters") + aCoder.encode(self.returnTypeName, forKey: "returnTypeName") + aCoder.encode(self.returnType, forKey: "returnType") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.`rethrows`, forKey: "`rethrows`") + aCoder.encode(self.accessLevel, forKey: "accessLevel") + aCoder.encode(self.isStatic, forKey: "isStatic") + aCoder.encode(self.isClass, forKey: "isClass") + aCoder.encode(self.isFailableInitializer, forKey: "isFailableInitializer") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") + aCoder.encode(self.definedInType, forKey: "definedInType") + aCoder.encode(self.attributes, forKey: "attributes") + aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + } +// sourcery:end +} +#endif + +"""), + .init(name: "MethodParameter.swift", content: +""" +#if canImport(ObjectiveC) +import Foundation + +/// Describes method parameter +@objcMembers +public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable { + /// Parameter external name + public var argumentLabel: String? + + // Note: although method parameter can have no name, this property is not optional, + // this is so to maintain compatibility with existing templates. + /// Parameter internal name + public let name: String + + /// Parameter type name + public let typeName: TypeName + + /// Parameter flag whether it's inout or not + public let `inout`: Bool + + /// Is this variadic parameter? + public let isVariadic: Bool + + // sourcery: skipEquality, skipDescription + /// Parameter type, if known + public var type: Type? + + /// Parameter type attributes, i.e. `@escaping` + public var typeAttributes: AttributeList { + return typeName.attributes + } + + /// Method parameter default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(argumentLabel: String?, name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = argumentLabel + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + /// :nodoc: + public init(name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = name + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + public var asSource: String { + let values: String = defaultValue.map { " = \\($0)" } ?? "" + let variadicity: String = isVariadic ? "..." : "" + let inoutness: String = `inout` ? "inout " : "" + let typeSuffix = ": \\(inoutness)\\(typeName.asSource)\\(values)\\(variadicity)" + guard argumentLabel != name else { + return name + typeSuffix + } + + let labels = [argumentLabel ?? "_", name.nilIfEmpty] + .compactMap { $0 } + .joined(separator: " ") + + return (labels.nilIfEmpty ?? "_") + typeSuffix + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("argumentLabel = \\(String(describing: self.argumentLabel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("`inout` = \\(String(describing: self.`inout`)), ") + string.append("isVariadic = \\(String(describing: self.isVariadic)), ") + string.append("typeAttributes = \\(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? MethodParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "argumentLabel").trackDifference(actual: self.argumentLabel, expected: castObject.argumentLabel)) + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "`inout`").trackDifference(actual: self.`inout`, expected: castObject.`inout`)) + results.append(contentsOf: DiffableResult(identifier: "isVariadic").trackDifference(actual: self.isVariadic, expected: castObject.isVariadic)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.argumentLabel) + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.`inout`) + hasher.combine(self.isVariadic) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? MethodParameter else { return false } + if self.argumentLabel != rhs.argumentLabel { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.`inout` != rhs.`inout` { return false } + if self.isVariadic != rhs.isVariadic { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:MethodParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.`inout` = aDecoder.decode(forKey: "`inout`") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") + self.type = aDecoder.decode(forKey: "type") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.argumentLabel, forKey: "argumentLabel") + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.`inout`, forKey: "`inout`") + aCoder.encode(self.isVariadic, forKey: "isVariadic") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } +// sourcery:end +} + +extension Array where Element == MethodParameter { + public var asSource: String { + "(\\(map { $0.asSource }.joined(separator: ", ")))" + } +} +#endif + """), .init(name: "Subscript.swift", content: -#""" +""" +#if canImport(ObjectiveC) import Foundation /// Describes subscript @objcMembers public final class Subscript: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable { - + /// Method parameters public var parameters: [MethodParameter] @@ -5636,7 +5445,6 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De /// :nodoc: public var __parserData: Any? - /// :nodoc: public init(parameters: [MethodParameter] = [], returnTypeName: TypeName, accessLevel: (read: AccessLevel, write: AccessLevel) = (.internal, .internal), @@ -5666,33 +5474,34 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De } /// :nodoc: + // sourcery: skipJSExport override public var description: String { - var string = "\(Swift.type(of: self)): " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.throws)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), " - string += "genericParameters = \(String(describing: self.genericParameters)), " - string += "genericRequirements = \(String(describing: self.genericRequirements)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers))" + var string = "\\(Swift.type(of: self)): " + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), ") + string.append("isFinal = \\(String(describing: self.isFinal)), ") + string.append("readAccess = \\(String(describing: self.readAccess)), ") + string.append("writeAccess = \\(String(describing: self.writeAccess)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.throws)), ") + string.append("isMutable = \\(String(describing: self.isMutable)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName)), ") + string.append("genericParameters = \\(String(describing: self.genericParameters)), ") + string.append("genericRequirements = \\(String(describing: self.genericRequirements)), ") + string.append("isGeneric = \\(String(describing: self.isGeneric)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers))") return string } public func diffAgainst(_ object: Any?) -> DiffableResult { let results = DiffableResult() guard let castObject = object as? Subscript else { - results.append("Incorrect type ") + results.append("Incorrect type ") return results } results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) @@ -5711,6 +5520,8 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.parameters) @@ -5752,71 +5563,71 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { withVaList(["parameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { withVaList(["returnTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.returnTypeName = returnTypeName self.returnType = aDecoder.decode(forKey: "returnType") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { withVaList(["writeAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.writeAccess = writeAccess - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers - guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { + guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { withVaList(["genericParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericParameters = genericParameters - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + }; self.genericParameters = genericParameters + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericRequirements = genericRequirements + }; self.genericRequirements = genericRequirements } /// :nodoc: @@ -5832,424 +5643,20 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De aCoder.encode(self.documentation, forKey: "documentation") aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.genericParameters, forKey: "genericParameters") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericParameters, forKey: "genericParameters") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") } // sourcery:end } - -"""#), - .init(name: "TemplateContext.swift", content: -""" -// -// Created by Krzysztof Zablocki on 31/12/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// :nodoc: -// sourcery: skipCoding -@objcMembers -public final class TemplateContext: NSObject, SourceryModel, NSCoding, Diffable { - // sourcery: skipJSExport - public let parserResult: FileParserResult? - public let functions: [SourceryMethod] - public let types: Types - public let argument: [String: NSObject] - - // sourcery: skipDescription - public var type: [String: Type] { - return types.typesByName - } - - public init(parserResult: FileParserResult?, types: Types, functions: [SourceryMethod], arguments: [String: NSObject]) { - self.parserResult = parserResult - self.types = types - self.functions = functions - self.argument = arguments - } - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let parserResult: FileParserResult = aDecoder.decode(forKey: "parserResult") else { - withVaList(["parserResult"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found. FileParserResults are required for template context that needs persisting.", arguments: arguments) - } - fatalError() - } - guard let argument: [String: NSObject] = aDecoder.decode(forKey: "argument") else { - withVaList(["argument"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - } - - // if we want to support multiple cycles of encode / decode we need deep copy because composer changes reference types - let fileParserResultCopy: FileParserResult? = nil -// fileParserResultCopy = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(NSKeyedArchiver.archivedData(withRootObject: parserResult)) as? FileParserResult - - let composed = Composer.uniqueTypesAndFunctions(parserResult) - self.types = .init(types: composed.types, typealiases: composed.typealiases) - self.functions = composed.functions - - self.parserResult = fileParserResultCopy - self.argument = argument - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.parserResult, forKey: "parserResult") - aCoder.encode(self.argument, forKey: "argument") - } - - public var stencilContext: [String: Any] { - return [ - "types": types, - "functions": functions, - "type": types.typesByName, - "argument": argument - ] - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "parserResult = \\(String(describing: self.parserResult)), " - string += "functions = \\(String(describing: self.functions)), " - string += "types = \\(String(describing: self.types)), " - string += "argument = \\(String(describing: self.argument)), " - string += "stencilContext = \\(String(describing: self.stencilContext))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? TemplateContext else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "parserResult").trackDifference(actual: self.parserResult, expected: castObject.parserResult)) - results.append(contentsOf: DiffableResult(identifier: "functions").trackDifference(actual: self.functions, expected: castObject.functions)) - results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) - results.append(contentsOf: DiffableResult(identifier: "argument").trackDifference(actual: self.argument, expected: castObject.argument)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.parserResult) - hasher.combine(self.functions) - hasher.combine(self.types) - hasher.combine(self.argument) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? TemplateContext else { return false } - if self.parserResult != rhs.parserResult { return false } - if self.functions != rhs.functions { return false } - if self.types != rhs.types { return false } - if self.argument != rhs.argument { return false } - return true - } - - // sourcery: skipDescription, skipEquality - public var jsContext: [String: Any] { - return [ - "types": [ - "all": types.all, - "protocols": types.protocols, - "classes": types.classes, - "structs": types.structs, - "enums": types.enums, - "extensions": types.extensions, - "based": types.based, - "inheriting": types.inheriting, - "implementing": types.implementing - ] as [String : Any], - "functions": functions, - "type": types.typesByName, - "argument": argument - ] - } - -} - -extension ProcessInfo { - /// :nodoc: - public var context: TemplateContext! { - return NSKeyedUnarchiver.unarchiveObject(withFile: arguments[1]) as? TemplateContext - } -} - -"""), - .init(name: "Types.swift", content: -""" -import Foundation - -// sourcery: skipJSExport -/// Collection of scanned types for accessing in templates -@objcMembers -public final class Types: NSObject, SourceryModel, Diffable { - - /// :nodoc: - public let types: [Type] - - /// All known typealiases - public let typealiases: [Typealias] - - /// :nodoc: - public init(types: [Type], typealiases: [Typealias] = []) { - self.types = types - self.typealiases = typealiases - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "types = \\(String(describing: self.types)), " - string += "typealiases = \\(String(describing: self.typealiases))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Types else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) - results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: castObject.typealiases)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.types) - hasher.combine(self.typealiases) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Types else { return false } - if self.types != rhs.types { return false } - if self.typealiases != rhs.typealiases { return false } - return true - } - -// sourcery:inline:Types.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let types: [Type] = aDecoder.decode(forKey: "types") else { - withVaList(["types"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.types = types - guard let typealiases: [Typealias] = aDecoder.decode(forKey: "typealiases") else { - withVaList(["typealiases"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typealiases = typealiases - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.types, forKey: "types") - aCoder.encode(self.typealiases, forKey: "typealiases") - } -// sourcery:end - - // sourcery: skipDescription, skipEquality, skipCoding - /// :nodoc: - public lazy internal(set) var typesByName: [String: Type] = { - var typesByName = [String: Type]() - self.types.forEach { typesByName[$0.globalName] = $0 } - return typesByName - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// :nodoc: - public lazy internal(set) var typesaliasesByName: [String: Typealias] = { - var typesaliasesByName = [String: Typealias]() - self.typealiases.forEach { typesaliasesByName[$0.name] = $0 } - return typesaliasesByName - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known types, excluding protocols or protocol compositions. - public lazy internal(set) var all: [Type] = { - return self.types.filter { !($0 is Protocol || $0 is ProtocolComposition) } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known protocols - public lazy internal(set) var protocols: [Protocol] = { - return self.types.compactMap { $0 as? Protocol } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known protocol compositions - public lazy internal(set) var protocolCompositions: [ProtocolComposition] = { - return self.types.compactMap { $0 as? ProtocolComposition } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known classes - public lazy internal(set) var classes: [Class] = { - return self.all.compactMap { $0 as? Class } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known structs - public lazy internal(set) var structs: [Struct] = { - return self.all.compactMap { $0 as? Struct } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known enums - public lazy internal(set) var enums: [Enum] = { - return self.all.compactMap { $0 as? Enum } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known extensions - public lazy internal(set) var extensions: [Type] = { - return self.all.compactMap { $0.isExtension ? $0 : nil } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Types based on any other type, grouped by its name, even if they are not known. - /// `types.based.MyType` returns list of types based on `MyType` - public lazy internal(set) var based: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.based.keys) } - ) - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Classes inheriting from any known class, grouped by its name. - /// `types.inheriting.MyClass` returns list of types inheriting from `MyClass` - public lazy internal(set) var inheriting: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.inherits.keys) }, - validate: { type in - guard type is Class else { - throw "\\(type.name) is not a class and should be used with `implementing` or `based`" - } - }) - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Types implementing known protocol, grouped by its name. - /// `types.implementing.MyProtocol` returns list of types implementing `MyProtocol` - public lazy internal(set) var implementing: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.implements.keys) }, - validate: { type in - guard type is Protocol else { - throw "\\(type.name) is a class and should be used with `inheriting` or `based`" - } - }) - }() -} - -"""), - .init(name: "TypesCollection.swift", content: -""" -import Foundation - -/// :nodoc: -@objcMembers -public class TypesCollection: NSObject, AutoJSExport { - // sourcery:begin: skipJSExport - let all: [Type] - let types: [String: [Type]] - let validate: ((Type) throws -> Void)? - // sourcery:end - - init(types: [Type], collection: (Type) -> [String], validate: ((Type) throws -> Void)? = nil) { - self.all = types - var content = [String: [Type]]() - self.all.forEach { type in - collection(type).forEach { name in - var list = content[name] ?? [Type]() - list.append(type) - content[name] = list - } - } - self.types = content - self.validate = validate - } - - public func types(forKey key: String) throws -> [Type] { - // In some configurations, the types are keyed by "ModuleName.TypeName" - var longKey: String? - - if let validate = validate { - guard let type = all.first(where: { $0.name == key }) else { - throw "Unknown type \\(key), should be used with `based`" - } - - try validate(type) - - if let module = type.module { - longKey = [module, type.name].joined(separator: ".") - } - } - - // If we find the types directly, return them - if let types = types[key] { - return types - } - - // if we find a types for the longKey, return them - if let longKey = longKey, let types = types[longKey] { - return types - } - - return [] - } - - /// :nodoc: - override public func value(forKey key: String) -> Any? { - do { - return try types(forKey: key) - } catch { - Log.error(error) - return nil - } - } - - /// :nodoc: - public subscript(_ key: String) -> [Type] { - do { - return try types(forKey: key) - } catch { - Log.error(error) - return [] - } - } - - override public func responds(to aSelector: Selector!) -> Bool { - return true - } -} +#endif """), .init(name: "Tuple.swift", content: """ +#if canImport(ObjectiveC) import Foundation /// Describes tuple type @@ -6275,10 +5682,11 @@ public final class TupleType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elements = \\(String(describing: self.elements))" + string.append("name = \\(String(describing: self.name)), ") + string.append("elements = \\(String(describing: self.elements))") return string } @@ -6293,6 +5701,8 @@ public final class TupleType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -6312,13 +5722,13 @@ public final class TupleType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let elements: [TupleElement] = aDecoder.decode(forKey: "elements") else { + guard let elements: [TupleElement] = aDecoder.decode(forKey: "elements") else { withVaList(["elements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -6361,11 +5771,12 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -6380,6 +5791,8 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -6400,7 +5813,7 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.name = aDecoder.decode(forKey: "name") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -6427,6 +5840,7 @@ extension Array where Element == TupleElement { "(\\(map { $0.typeName.asSource }.joined(separator: ", ")))" } } +#endif """), .init(name: "Type.swift", content: @@ -6435,13 +5849,14 @@ extension Array where Element == TupleElement { // Created by Krzysztof Zablocki on 11/09/2016. // Copyright (c) 2016 Pixle. All rights reserved. // - +#if canImport(ObjectiveC) import Foundation /// :nodoc: public typealias AttributeList = [String: [Attribute]] /// Defines Swift type + @objcMembers public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { @@ -6857,41 +6272,43 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "module = \\(String(describing: self.module)), " - string += "imports = \\(String(describing: self.imports)), " - string += "allImports = \\(String(describing: self.allImports)), " - string += "typealiases = \\(String(describing: self.typealiases)), " - string += "isExtension = \\(String(describing: self.isExtension)), " - string += "kind = \\(String(describing: self.kind)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "name = \\(String(describing: self.name)), " - string += "isUnknownExtension = \\(String(describing: self.isUnknownExtension)), " - string += "isGeneric = \\(String(describing: self.isGeneric)), " - string += "localName = \\(String(describing: self.localName)), " - string += "rawVariables = \\(String(describing: self.rawVariables)), " - string += "rawMethods = \\(String(describing: self.rawMethods)), " - string += "rawSubscripts = \\(String(describing: self.rawSubscripts)), " - string += "initializers = \\(String(describing: self.initializers)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "staticVariables = \\(String(describing: self.staticVariables)), " - string += "staticMethods = \\(String(describing: self.staticMethods)), " - string += "classMethods = \\(String(describing: self.classMethods)), " - string += "instanceVariables = \\(String(describing: self.instanceVariables)), " - string += "instanceMethods = \\(String(describing: self.instanceMethods)), " - string += "computedVariables = \\(String(describing: self.computedVariables)), " - string += "storedVariables = \\(String(describing: self.storedVariables)), " - string += "inheritedTypes = \\(String(describing: self.inheritedTypes)), " - string += "inherits = \\(String(describing: self.inherits)), " - string += "containedTypes = \\(String(describing: self.containedTypes)), " - string += "parentName = \\(String(describing: self.parentName)), " - string += "parentTypes = \\(String(describing: self.parentTypes)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers)), " - string += "fileName = \\(String(describing: self.fileName)), " - string += "genericRequirements = \\(String(describing: self.genericRequirements))" + let type: Type.Type = Swift.type(of: self) + var string = "\\(type): " + string.append("module = \\(String(describing: self.module)), ") + string.append("imports = \\(String(describing: self.imports)), ") + string.append("allImports = \\(String(describing: self.allImports)), ") + string.append("typealiases = \\(String(describing: self.typealiases)), ") + string.append("isExtension = \\(String(describing: self.isExtension)), ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("isUnknownExtension = \\(String(describing: self.isUnknownExtension)), ") + string.append("isGeneric = \\(String(describing: self.isGeneric)), ") + string.append("localName = \\(String(describing: self.localName)), ") + string.append("rawVariables = \\(String(describing: self.rawVariables)), ") + string.append("rawMethods = \\(String(describing: self.rawMethods)), ") + string.append("rawSubscripts = \\(String(describing: self.rawSubscripts)), ") + string.append("initializers = \\(String(describing: self.initializers)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("staticVariables = \\(String(describing: self.staticVariables)), ") + string.append("staticMethods = \\(String(describing: self.staticMethods)), ") + string.append("classMethods = \\(String(describing: self.classMethods)), ") + string.append("instanceVariables = \\(String(describing: self.instanceVariables)), ") + string.append("instanceMethods = \\(String(describing: self.instanceMethods)), ") + string.append("computedVariables = \\(String(describing: self.computedVariables)), ") + string.append("storedVariables = \\(String(describing: self.storedVariables)), ") + string.append("inheritedTypes = \\(String(describing: self.inheritedTypes)), ") + string.append("inherits = \\(String(describing: self.inherits)), ") + string.append("containedTypes = \\(String(describing: self.containedTypes)), ") + string.append("parentName = \\(String(describing: self.parentName)), ") + string.append("parentTypes = \\(String(describing: self.parentTypes)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers)), ") + string.append("fileName = \\(String(describing: self.fileName)), ") + string.append("genericRequirements = \\(String(describing: self.genericRequirements))") return string } @@ -6925,6 +6342,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.module) @@ -6985,51 +6404,45 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.module = aDecoder.decode(forKey: "module") - guard let imports: [Import] = aDecoder.decode(forKey: "imports") else { + guard let imports: [Import] = aDecoder.decode(forKey: "imports") else { withVaList(["imports"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.imports = imports - guard let typealiases: [String: Typealias] = aDecoder.decode(forKey: "typealiases") else { + guard let typealiases: [String: Typealias] = aDecoder.decode(forKey: "typealiases") else { withVaList(["typealiases"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.typealiases = typealiases self.isExtension = aDecoder.decode(forKey: "isExtension") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { withVaList(["accessLevel"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.accessLevel = accessLevel self.isGeneric = aDecoder.decode(forKey: "isGeneric") - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - guard let localName: String = aDecoder.decode(forKey: "localName") else { + guard let localName: String = aDecoder.decode(forKey: "localName") else { withVaList(["localName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.localName = localName - guard let rawVariables: [Variable] = aDecoder.decode(forKey: "rawVariables") else { + guard let rawVariables: [Variable] = aDecoder.decode(forKey: "rawVariables") else { withVaList(["rawVariables"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.rawVariables = rawVariables - guard let rawMethods: [Method] = aDecoder.decode(forKey: "rawMethods") else { + guard let rawMethods: [Method] = aDecoder.decode(forKey: "rawMethods") else { withVaList(["rawMethods"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.rawMethods = rawMethods - guard let rawSubscripts: [Subscript] = aDecoder.decode(forKey: "rawSubscripts") else { + guard let rawSubscripts: [Subscript] = aDecoder.decode(forKey: "rawSubscripts") else { withVaList(["rawSubscripts"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -7037,55 +6450,55 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { }; self.rawSubscripts = rawSubscripts self.bodyBytesRange = aDecoder.decode(forKey: "bodyBytesRange") self.completeDeclarationRange = aDecoder.decode(forKey: "completeDeclarationRange") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - guard let inheritedTypes: [String] = aDecoder.decode(forKey: "inheritedTypes") else { + guard let inheritedTypes: [String] = aDecoder.decode(forKey: "inheritedTypes") else { withVaList(["inheritedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.inheritedTypes = inheritedTypes - guard let based: [String: String] = aDecoder.decode(forKey: "based") else { + guard let based: [String: String] = aDecoder.decode(forKey: "based") else { withVaList(["based"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.based = based - guard let basedTypes: [String: Type] = aDecoder.decode(forKey: "basedTypes") else { + guard let basedTypes: [String: Type] = aDecoder.decode(forKey: "basedTypes") else { withVaList(["basedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.basedTypes = basedTypes - guard let inherits: [String: Type] = aDecoder.decode(forKey: "inherits") else { + guard let inherits: [String: Type] = aDecoder.decode(forKey: "inherits") else { withVaList(["inherits"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.inherits = inherits - guard let implements: [String: Type] = aDecoder.decode(forKey: "implements") else { + guard let implements: [String: Type] = aDecoder.decode(forKey: "implements") else { withVaList(["implements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.implements = implements - guard let containedTypes: [Type] = aDecoder.decode(forKey: "containedTypes") else { + guard let containedTypes: [Type] = aDecoder.decode(forKey: "containedTypes") else { withVaList(["containedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.containedTypes = containedTypes - guard let containedType: [String: Type] = aDecoder.decode(forKey: "containedType") else { + guard let containedType: [String: Type] = aDecoder.decode(forKey: "containedType") else { withVaList(["containedType"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -7094,19 +6507,25 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { self.parentName = aDecoder.decode(forKey: "parentName") self.parent = aDecoder.decode(forKey: "parent") self.supertype = aDecoder.decode(forKey: "supertype") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers self.path = aDecoder.decode(forKey: "path") + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements self.fileName = aDecoder.decode(forKey: "fileName") } @@ -7139,8 +6558,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") aCoder.encode(self.path, forKey: "path") - aCoder.encode(self.fileName, forKey: "fileName") aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + aCoder.encode(self.fileName, forKey: "fileName") } // sourcery:end @@ -7167,6 +6586,7 @@ extension Type { return super.value(forUndefinedKey: key) } } +#endif """), .init(name: "TypeName.swift", content: @@ -7175,7 +6595,7 @@ extension Type { // Created by Krzysztof Zabłocki on 25/12/2016. // Copyright (c) 2016 Pixle. All rights reserved. // - +#if canImport(ObjectiveC) import Foundation /// Describes name of the type used in typed declaration (variable, method parameter or return value etc.) @@ -7198,7 +6618,9 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless let optionalSuffix: String // TODO: TBR - if !name.hasPrefix("Optional<") && !name.contains(" where ") { + let hasPrefix: Bool = name.hasPrefix("Optional<") as Bool + let containsName: Bool = name.contains(" where ") as Bool + if !hasPrefix && !containsName { if isOptional { optionalSuffix = "?" } else if isImplicitlyUnwrappedOptional { @@ -7312,24 +6734,25 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless /// Prints typename as it would appear on definition public var asSource: String { // TODO: TBR special treatment - let specialTreatment = isOptional && name.hasPrefix("Optional<") + let specialTreatment: Bool = isOptional && name.hasPrefix("Optional<") - var description = ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [specialTreatment ? name : unwrappedTypeName] - ).joined(separator: " ") + let attributeValues: [Attribute] = attributes.flatMap { $0.value } + let attributeValuesUnsorted: [String] = attributeValues.map { $0.asSource } + var attributes: [String] = attributeValuesUnsorted.sorted() + attributes.append(contentsOf: modifiers.map({ $0.asSource })) + attributes.append(contentsOf: [specialTreatment ? name : unwrappedTypeName]) + var description = attributes.joined(separator: " ") - if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name +// if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name // description.append(dictionary.asSource) - } else if let _ = self.array { +// } else if let _ = self.array { // description.append(array.asSource) - } else if let _ = self.generic { +// } else if let _ = self.generic { // let arguments = generic.typeParameters // .map({ $0.typeName.asSource }) // .joined(separator: ", ") // description.append("<\\(arguments)>") - } +// } if !specialTreatment { if isImplicitlyUnwrappedOptional { description.append("!") @@ -7342,11 +6765,10 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless } public override var description: String { - ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [name] - ).joined(separator: " ") + var description: [String] = attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + description.append(contentsOf: modifiers.map({ $0.asSource })) + description.append(contentsOf: [name]) + return description.joined(separator: " ") } public func diffAgainst(_ object: Any?) -> DiffableResult { @@ -7368,6 +6790,7 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless return results } + public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -7403,7 +6826,7 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -7412,13 +6835,13 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless self.generic = aDecoder.decode(forKey: "generic") self.isProtocolComposition = aDecoder.decode(forKey: "isProtocolComposition") self.actualTypeName = aDecoder.decode(forKey: "actualTypeName") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -7426,7 +6849,7 @@ public final class TypeName: NSObject, SourceryModelWithoutDescription, Lossless }; self.modifiers = modifiers self.isOptional = aDecoder.decode(forKey: "isOptional") self.isImplicitlyUnwrappedOptional = aDecoder.decode(forKey: "isImplicitlyUnwrappedOptional") - guard let unwrappedTypeName: String = aDecoder.decode(forKey: "unwrappedTypeName") else { + guard let unwrappedTypeName: String = aDecoder.decode(forKey: "unwrappedTypeName") else { withVaList(["unwrappedTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -7479,149 +6902,1451 @@ extension TypeName { return TypeName(name: "UnknownTypeSoAddTypeAttributionToVariable", attributes: attributes) } } +#endif """), - .init(name: "Typealias.swift", content: + .init(name: "Types.swift", content: """ +// +// Created by Krzysztof Zablocki on 31/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// + +#if canImport(ObjectiveC) import Foundation // sourcery: skipJSExport -/// :nodoc: +/// Collection of scanned types for accessing in templates @objcMembers -public final class Typealias: NSObject, Typed, SourceryModel, Diffable { - // New typealias name - public let aliasName: String +public final class Types: NSObject, SourceryModel, Diffable { - // Target name - public let typeName: TypeName + /// :nodoc: + public let types: [Type] - // sourcery: skipEquality, skipDescription - public var type: Type? + /// All known typealiases + public let typealiases: [Typealias] - /// module in which this typealias was declared - public var module: String? - - // sourcery: skipEquality, skipDescription - public var parent: Type? { - didSet { - parentName = parent?.name - } - } - - /// Type access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let accessLevel: String - - var parentName: String? - - public var name: String { - if let parentName = parent?.name { - return "\\(module != nil ? "\\(module!)." : "")\\(parentName).\\(aliasName)" - } else { - return "\\(module != nil ? "\\(module!)." : "")\\(aliasName)" - } - } - - public init(aliasName: String = "", typeName: TypeName, accessLevel: AccessLevel = .internal, parent: Type? = nil, module: String? = nil) { - self.aliasName = aliasName - self.typeName = typeName - self.accessLevel = accessLevel.rawValue - self.parent = parent - self.parentName = parent?.name - self.module = module + /// :nodoc: + public init(types: [Type], typealiases: [Typealias] = []) { + self.types = types + self.typealiases = typealiases } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "aliasName = \\(String(describing: self.aliasName)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "module = \\(String(describing: self.module)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "parentName = \\(String(describing: self.parentName)), " - string += "name = \\(String(describing: self.name))" + string.append("types = \\(String(describing: self.types)), ") + string.append("typealiases = \\(String(describing: self.typealiases))") return string } public func diffAgainst(_ object: Any?) -> DiffableResult { let results = DiffableResult() - guard let castObject = object as? Typealias else { - results.append("Incorrect type ") + guard let castObject = object as? Types else { + results.append("Incorrect type ") return results } - results.append(contentsOf: DiffableResult(identifier: "aliasName").trackDifference(actual: self.aliasName, expected: castObject.aliasName)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: castObject.module)) - results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) - results.append(contentsOf: DiffableResult(identifier: "parentName").trackDifference(actual: self.parentName, expected: castObject.parentName)) + results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) + results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: castObject.typealiases)) return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() - hasher.combine(self.aliasName) - hasher.combine(self.typeName) - hasher.combine(self.module) - hasher.combine(self.accessLevel) - hasher.combine(self.parentName) + hasher.combine(self.types) + hasher.combine(self.typealiases) return hasher.finalize() } /// :nodoc: public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Typealias else { return false } - if self.aliasName != rhs.aliasName { return false } - if self.typeName != rhs.typeName { return false } - if self.module != rhs.module { return false } - if self.accessLevel != rhs.accessLevel { return false } - if self.parentName != rhs.parentName { return false } + guard let rhs = object as? Types else { return false } + if self.types != rhs.types { return false } + if self.typealiases != rhs.typealiases { return false } return true } -// sourcery:inline:Typealias.AutoCoding +// sourcery:inline:Types.AutoCoding /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let aliasName: String = aDecoder.decode(forKey: "aliasName") else { - withVaList(["aliasName"]) { arguments in + guard let types: [Type] = aDecoder.decode(forKey: "types") else { + withVaList(["types"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.aliasName = aliasName - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + }; self.types = types + guard let typealiases: [Typealias] = aDecoder.decode(forKey: "typealiases") else { + withVaList(["typealiases"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typealiases = typealiases + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.types, forKey: "types") + aCoder.encode(self.typealiases, forKey: "typealiases") + } +// sourcery:end + + // sourcery: skipDescription, skipEquality, skipCoding + /// :nodoc: + public lazy internal(set) var typesByName: [String: Type] = { + var typesByName = [String: Type]() + self.types.forEach { typesByName[$0.globalName] = $0 } + return typesByName + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// :nodoc: + public lazy internal(set) var typesaliasesByName: [String: Typealias] = { + var typesaliasesByName = [String: Typealias]() + self.typealiases.forEach { typesaliasesByName[$0.name] = $0 } + return typesaliasesByName + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known types, excluding protocols or protocol compositions. + public lazy internal(set) var all: [Type] = { + return self.types.filter { !($0 is Protocol || $0 is ProtocolComposition) } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known protocols + public lazy internal(set) var protocols: [Protocol] = { + return self.types.compactMap { $0 as? Protocol } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known protocol compositions + public lazy internal(set) var protocolCompositions: [ProtocolComposition] = { + return self.types.compactMap { $0 as? ProtocolComposition } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known classes + public lazy internal(set) var classes: [Class] = { + return self.all.compactMap { $0 as? Class } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known structs + public lazy internal(set) var structs: [Struct] = { + return self.all.compactMap { $0 as? Struct } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known enums + public lazy internal(set) var enums: [Enum] = { + return self.all.compactMap { $0 as? Enum } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known extensions + public lazy internal(set) var extensions: [Type] = { + return self.all.compactMap { $0.isExtension ? $0 : nil } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Types based on any other type, grouped by its name, even if they are not known. + /// `types.based.MyType` returns list of types based on `MyType` + public lazy internal(set) var based: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.based.keys) } + ) + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Classes inheriting from any known class, grouped by its name. + /// `types.inheriting.MyClass` returns list of types inheriting from `MyClass` + public lazy internal(set) var inheriting: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.inherits.keys) }, + validate: { type in + guard type is Class else { + throw "\\(type.name) is not a class and should be used with `implementing` or `based`" + } + }) + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Types implementing known protocol, grouped by its name. + /// `types.implementing.MyProtocol` returns list of types implementing `MyProtocol` + public lazy internal(set) var implementing: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.implements.keys) }, + validate: { type in + guard type is Protocol else { + throw "\\(type.name) is a class and should be used with `inheriting` or `based`" + } + }) + }() +} +#endif + +"""), + .init(name: "TypesCollection.swift", content: +""" +// +// Created by Krzysztof Zablocki on 31/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if canImport(ObjectiveC) +import Foundation + +/// :nodoc: +@objcMembers +public class TypesCollection: NSObject, AutoJSExport { + // sourcery:begin: skipJSExport + let all: [Type] + let types: [String: [Type]] + let validate: ((Type) throws -> Void)? + // sourcery:end + + init(types: [Type], collection: (Type) -> [String], validate: ((Type) throws -> Void)? = nil) { + self.all = types + var content = [String: [Type]]() + self.all.forEach { type in + collection(type).forEach { name in + var list = content[name] ?? [Type]() + list.append(type) + content[name] = list + } + } + self.types = content + self.validate = validate + } + + public func types(forKey key: String) throws -> [Type] { + // In some configurations, the types are keyed by "ModuleName.TypeName" + var longKey: String? + + if let validate = validate { + guard let type = all.first(where: { $0.name == key }) else { + throw "Unknown type \\(key), should be used with `based`" + } + + try validate(type) + + if let module = type.module { + longKey = [module, type.name].joined(separator: ".") + } + } + + // If we find the types directly, return them + if let types = types[key] { + return types + } + + // if we find a types for the longKey, return them + if let longKey = longKey, let types = types[longKey] { + return types + } + + return [] + } + + /// :nodoc: + override public func value(forKey key: String) -> Any? { + do { + return try types(forKey: key) + } catch { + Log.error(error) + return nil + } + } + + /// :nodoc: + public subscript(_ key: String) -> [Type] { + do { + return try types(forKey: key) + } catch { + Log.error(error) + return [] + } + } + + override public func responds(to aSelector: Selector!) -> Bool { + return true + } +} +#endif + +"""), + .init(name: "Variable.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if canImport(ObjectiveC) +import Foundation + +/// :nodoc: +public typealias SourceryVariable = Variable + +/// Defines variable +@objcMembers +public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable { + + /// Variable name + public let name: String + + /// Variable type name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Variable type, if known, i.e. if the type is declared in the scanned sources. + /// For explanation, see + public var type: Type? + + /// Whether variable is computed and not stored + public let isComputed: Bool + + /// Whether variable is async + public let isAsync: Bool + + /// Whether variable throws + public let `throws`: Bool + + /// Whether variable is static + public let isStatic: Bool + + /// Variable read access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let readAccess: String + + /// Variable write access, i.e. `internal`, `private`, `fileprivate`, `public`, `open`. + /// For immutable variables this value is empty string + public let writeAccess: String + + /// composed access level + /// sourcery: skipJSExport + public var accessLevel: (read: AccessLevel, write: AccessLevel) { + (read: AccessLevel(rawValue: readAccess) ?? .none, AccessLevel(rawValue: writeAccess) ?? .none) + } + + /// Whether variable is mutable or not + public var isMutable: Bool { + return writeAccess != AccessLevel.none.rawValue + } + + /// Variable default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + public var documentation: Documentation = [] + + /// Variable attributes, i.e. `@IBOutlet`, `@IBInspectable` + public var attributes: AttributeList + + /// Modifiers, i.e. `private` + public var modifiers: [SourceryModifier] + + /// Whether variable is final or not + public var isFinal: Bool { + return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } + } + + /// Whether variable is lazy or not + public var isLazy: Bool { + return modifiers.contains { $0.name == Attribute.Identifier.lazy.rawValue } + } + + /// Whether variable is dynamic or not + public var isDynamic: Bool { + modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } + } + + /// Reference to type name where the variable is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc + public internal(set) var definedInTypeName: TypeName? + + /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` + public var actualDefinedInTypeName: TypeName? { + return definedInTypeName?.actualTypeName ?? definedInTypeName + } + + // sourcery: skipEquality, skipDescription + /// Reference to actual type where the object is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown + public var definedInType: Type? + + /// :nodoc: + public init(name: String = "", + typeName: TypeName, + type: Type? = nil, + accessLevel: (read: AccessLevel, write: AccessLevel) = (.internal, .internal), + isComputed: Bool = false, + isAsync: Bool = false, + `throws`: Bool = false, + isStatic: Bool = false, + defaultValue: String? = nil, + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + definedInTypeName: TypeName? = nil) { + + self.name = name + self.typeName = typeName + self.type = type + self.isComputed = isComputed + self.isAsync = isAsync + self.`throws` = `throws` + self.isStatic = isStatic + self.defaultValue = defaultValue + self.readAccess = accessLevel.read.rawValue + self.writeAccess = accessLevel.write.rawValue + self.attributes = attributes + self.modifiers = modifiers + self.annotations = annotations + self.documentation = documentation + self.definedInTypeName = definedInTypeName + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("isComputed = \\(String(describing: self.isComputed)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("isStatic = \\(String(describing: self.isStatic)), ") + string.append("readAccess = \\(String(describing: self.readAccess)), ") + string.append("writeAccess = \\(String(describing: self.writeAccess)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("isMutable = \\(String(describing: self.isMutable)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers)), ") + string.append("isFinal = \\(String(describing: self.isFinal)), ") + string.append("isLazy = \\(String(describing: self.isLazy)), ") + string.append("isDynamic = \\(String(describing: self.isDynamic)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Variable else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "type").trackDifference(actual: self.type, expected: castObject.type)) + results.append(contentsOf: DiffableResult(identifier: "isComputed").trackDifference(actual: self.isComputed, expected: castObject.isComputed)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) + results.append(contentsOf: DiffableResult(identifier: "readAccess").trackDifference(actual: self.readAccess, expected: castObject.readAccess)) + results.append(contentsOf: DiffableResult(identifier: "writeAccess").trackDifference(actual: self.writeAccess, expected: castObject.writeAccess)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) + results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) + results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.isComputed) + hasher.combine(self.isAsync) + hasher.combine(self.`throws`) + hasher.combine(self.isStatic) + hasher.combine(self.readAccess) + hasher.combine(self.writeAccess) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.attributes) + hasher.combine(self.modifiers) + hasher.combine(self.definedInTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Variable else { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.isComputed != rhs.isComputed { return false } + if self.isAsync != rhs.isAsync { return false } + if self.`throws` != rhs.`throws` { return false } + if self.isStatic != rhs.isStatic { return false } + if self.readAccess != rhs.readAccess { return false } + if self.writeAccess != rhs.writeAccess { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.attributes != rhs.attributes { return false } + if self.modifiers != rhs.modifiers { return false } + if self.definedInTypeName != rhs.definedInTypeName { return false } + return true + } + +// sourcery:inline:Variable.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.typeName = typeName self.type = aDecoder.decode(forKey: "type") - self.module = aDecoder.decode(forKey: "module") - self.parent = aDecoder.decode(forKey: "parent") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { - withVaList(["accessLevel"]) { arguments in + self.isComputed = aDecoder.decode(forKey: "isComputed") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.isStatic = aDecoder.decode(forKey: "isStatic") + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.accessLevel = accessLevel - self.parentName = aDecoder.decode(forKey: "parentName") + }; self.readAccess = readAccess + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + withVaList(["writeAccess"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.writeAccess = writeAccess + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + withVaList(["attributes"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.attributes = attributes + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + withVaList(["modifiers"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.modifiers = modifiers + self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") + self.definedInType = aDecoder.decode(forKey: "definedInType") } /// :nodoc: public func encode(with aCoder: NSCoder) { - aCoder.encode(self.aliasName, forKey: "aliasName") + aCoder.encode(self.name, forKey: "name") aCoder.encode(self.typeName, forKey: "typeName") aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.module, forKey: "module") - aCoder.encode(self.parent, forKey: "parent") - aCoder.encode(self.accessLevel, forKey: "accessLevel") - aCoder.encode(self.parentName, forKey: "parentName") + aCoder.encode(self.isComputed, forKey: "isComputed") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.isStatic, forKey: "isStatic") + aCoder.encode(self.readAccess, forKey: "readAccess") + aCoder.encode(self.writeAccess, forKey: "writeAccess") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.attributes, forKey: "attributes") + aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") + aCoder.encode(self.definedInType, forKey: "definedInType") } // sourcery:end } +#endif +"""), + .init(name: "AutoHashable.generated.swift", content: +""" +// Generated using Sourcery 1.3.1 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable all + + +// MARK: - AutoHashable for classes, protocols, structs + +// MARK: - AutoHashable for Enums + +"""), + .init(name: "Coding.generated.swift", content: +""" +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable vertical_whitespace trailing_newline + +import Foundation + + +extension NSCoder { + + @nonobjc func decode(forKey: String) -> String? { + return self.maybeDecode(forKey: forKey) as String? + } + + @nonobjc func decode(forKey: String) -> TypeName? { + return self.maybeDecode(forKey: forKey) as TypeName? + } + + @nonobjc func decode(forKey: String) -> AccessLevel? { + return self.maybeDecode(forKey: forKey) as AccessLevel? + } + + @nonobjc func decode(forKey: String) -> Bool { + return self.decodeBool(forKey: forKey) + } + + @nonobjc func decode(forKey: String) -> Int { + return self.decodeInteger(forKey: forKey) + } + + func decode(forKey: String) -> E? { + return maybeDecode(forKey: forKey) as E? + } + + fileprivate func maybeDecode(forKey: String) -> E? { + guard let object = self.decodeObject(forKey: forKey) else { + return nil + } + + return object as? E + } + +} + +extension ArrayType: NSCoding {} + +extension AssociatedType: NSCoding {} + +extension AssociatedValue: NSCoding {} + +extension Attribute: NSCoding {} + +extension BytesRange: NSCoding {} + + +extension ClosureParameter: NSCoding {} + +extension ClosureType: NSCoding {} + +extension DictionaryType: NSCoding {} + + +extension EnumCase: NSCoding {} + +extension FileParserResult: NSCoding {} + +extension GenericParameter: NSCoding {} + +extension GenericRequirement: NSCoding {} + +extension GenericType: NSCoding {} + +extension GenericTypeParameter: NSCoding {} + +extension Import: NSCoding {} + +extension Method: NSCoding {} + +extension MethodParameter: NSCoding {} + +extension Modifier: NSCoding {} + + + +extension SetType: NSCoding {} + + +extension Subscript: NSCoding {} + +extension TupleElement: NSCoding {} + +extension TupleType: NSCoding {} + +extension Type: NSCoding {} + +extension TypeName: NSCoding {} + +extension Typealias: NSCoding {} + +extension Types: NSCoding {} + +extension Variable: NSCoding {} + + +"""), + .init(name: "JSExport.generated.swift", content: +""" +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable vertical_whitespace trailing_newline + +#if canImport(JavaScriptCore) +import JavaScriptCore + +@objc protocol ActorAutoJSExport: JSExport { + var kind: String { get } + var isFinal: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Actor: ActorAutoJSExport {} + +@objc protocol ArrayTypeAutoJSExport: JSExport { + var name: String { get } + var elementTypeName: TypeName { get } + var elementType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension ArrayType: ArrayTypeAutoJSExport {} + +@objc protocol AssociatedTypeAutoJSExport: JSExport { + var name: String { get } + var typeName: TypeName? { get } + var type: Type? { get } +} + +extension AssociatedType: AssociatedTypeAutoJSExport {} + +@objc protocol AssociatedValueAutoJSExport: JSExport { + var localName: String? { get } + var externalName: String? { get } + var typeName: TypeName { get } + var type: Type? { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension AssociatedValue: AssociatedValueAutoJSExport {} + +@objc protocol AttributeAutoJSExport: JSExport { + var name: String { get } + var arguments: [String: NSObject] { get } + var asSource: String { get } + var description: String { get } +} + +extension Attribute: AttributeAutoJSExport {} + +@objc protocol BytesRangeAutoJSExport: JSExport { + var offset: Int64 { get } + var length: Int64 { get } +} + +extension BytesRange: BytesRangeAutoJSExport {} + +@objc protocol ClassAutoJSExport: JSExport { + var kind: String { get } + var isFinal: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Class: ClassAutoJSExport {} + +@objc protocol ClosureParameterAutoJSExport: JSExport { + var argumentLabel: String? { get } + var name: String? { get } + var typeName: TypeName { get } + var `inout`: Bool { get } + var type: Type? { get } + var isVariadic: Bool { get } + var typeAttributes: AttributeList { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension ClosureParameter: ClosureParameterAutoJSExport {} + +@objc protocol ClosureTypeAutoJSExport: JSExport { + var name: String { get } + var parameters: [ClosureParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isAsync: Bool { get } + var asyncKeyword: String? { get } + var `throws`: Bool { get } + var throwsOrRethrowsKeyword: String? { get } + var asSource: String { get } +} + +extension ClosureType: ClosureTypeAutoJSExport {} + +@objc protocol DictionaryTypeAutoJSExport: JSExport { + var name: String { get } + var valueTypeName: TypeName { get } + var valueType: Type? { get } + var keyTypeName: TypeName { get } + var keyType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension DictionaryType: DictionaryTypeAutoJSExport {} + +@objc protocol EnumAutoJSExport: JSExport { + var kind: String { get } + var cases: [EnumCase] { get } + var rawTypeName: TypeName? { get } + var hasRawType: Bool { get } + var rawType: Type? { get } + var based: [String: String] { get } + var hasAssociatedValues: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Enum: EnumAutoJSExport {} + +@objc protocol EnumCaseAutoJSExport: JSExport { + var name: String { get } + var rawValue: String? { get } + var associatedValues: [AssociatedValue] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var indirect: Bool { get } + var hasAssociatedValue: Bool { get } +} + +extension EnumCase: EnumCaseAutoJSExport {} + + +@objc protocol GenericParameterAutoJSExport: JSExport { + var name: String { get } + var inheritedTypeName: TypeName? { get } +} + +extension GenericParameter: GenericParameterAutoJSExport {} + +@objc protocol GenericRequirementAutoJSExport: JSExport { + var leftType: AssociatedType { get } + var rightType: GenericTypeParameter { get } + var relationship: String { get } + var relationshipSyntax: String { get } +} + +extension GenericRequirement: GenericRequirementAutoJSExport {} + +@objc protocol GenericTypeAutoJSExport: JSExport { + var name: String { get } + var typeParameters: [GenericTypeParameter] { get } + var asSource: String { get } + var description: String { get } +} + +extension GenericType: GenericTypeAutoJSExport {} + +@objc protocol GenericTypeParameterAutoJSExport: JSExport { + var typeName: TypeName { get } + var type: Type? { get } +} + +extension GenericTypeParameter: GenericTypeParameterAutoJSExport {} + +@objc protocol ImportAutoJSExport: JSExport { + var kind: String? { get } + var path: String { get } + var description: String { get } + var moduleName: String { get } +} + +extension Import: ImportAutoJSExport {} + +@objc protocol MethodAutoJSExport: JSExport { + var name: String { get } + var selectorName: String { get } + var shortName: String { get } + var callName: String { get } + var parameters: [MethodParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var `rethrows`: Bool { get } + var accessLevel: String { get } + var isStatic: Bool { get } + var isClass: Bool { get } + var isInitializer: Bool { get } + var isDeinitializer: Bool { get } + var isFailableInitializer: Bool { get } + var isConvenienceInitializer: Bool { get } + var isRequired: Bool { get } + var isFinal: Bool { get } + var isMutating: Bool { get } + var isGeneric: Bool { get } + var isOptional: Bool { get } + var isNonisolated: Bool { get } + var isDynamic: Bool { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } +} + +extension Method: MethodAutoJSExport {} + +@objc protocol MethodParameterAutoJSExport: JSExport { + var argumentLabel: String? { get } + var name: String { get } + var typeName: TypeName { get } + var `inout`: Bool { get } + var isVariadic: Bool { get } + var type: Type? { get } + var typeAttributes: AttributeList { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension MethodParameter: MethodParameterAutoJSExport {} + +@objc protocol ModifierAutoJSExport: JSExport { + var name: String { get } + var detail: String? { get } + var asSource: String { get } +} + +extension Modifier: ModifierAutoJSExport {} + +@objc protocol ProtocolAutoJSExport: JSExport { + var kind: String { get } + var associatedTypes: [String: AssociatedType] { get } + var genericRequirements: [GenericRequirement] { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var fileName: String? { get } +} + +extension Protocol: ProtocolAutoJSExport {} + +@objc protocol ProtocolCompositionAutoJSExport: JSExport { + var kind: String { get } + var composedTypeNames: [TypeName] { get } + var composedTypes: [Type]? { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension ProtocolComposition: ProtocolCompositionAutoJSExport {} + +@objc protocol SetTypeAutoJSExport: JSExport { + var name: String { get } + var elementTypeName: TypeName { get } + var elementType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension SetType: SetTypeAutoJSExport {} + + + +@objc protocol StructAutoJSExport: JSExport { + var kind: String { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Struct: StructAutoJSExport {} + +@objc protocol SubscriptAutoJSExport: JSExport { + var parameters: [MethodParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isFinal: Bool { get } + var readAccess: String { get } + var writeAccess: String { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var isMutable: Bool { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericParameters: [GenericParameter] { get } + var genericRequirements: [GenericRequirement] { get } + var isGeneric: Bool { get } +} + +extension Subscript: SubscriptAutoJSExport {} + +@objc protocol TemplateContextAutoJSExport: JSExport { + var functions: [SourceryMethod] { get } + var types: Types { get } + var argument: [String: NSObject] { get } + var type: [String: Type] { get } + var stencilContext: [String: Any] { get } + var jsContext: [String: Any] { get } +} + +extension TemplateContext: TemplateContextAutoJSExport {} + +@objc protocol TupleElementAutoJSExport: JSExport { + var name: String? { get } + var typeName: TypeName { get } + var type: Type? { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension TupleElement: TupleElementAutoJSExport {} + +@objc protocol TupleTypeAutoJSExport: JSExport { + var name: String { get } + var elements: [TupleElement] { get } +} + +extension TupleType: TupleTypeAutoJSExport {} + +@objc protocol TypeAutoJSExport: JSExport { + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var kind: String { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Type: TypeAutoJSExport {} + +@objc protocol TypeNameAutoJSExport: JSExport { + var name: String { get } + var generic: GenericType? { get } + var isGeneric: Bool { get } + var isProtocolComposition: Bool { get } + var actualTypeName: TypeName? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } + var isVoid: Bool { get } + var isTuple: Bool { get } + var tuple: TupleType? { get } + var isArray: Bool { get } + var array: ArrayType? { get } + var isDictionary: Bool { get } + var dictionary: DictionaryType? { get } + var isClosure: Bool { get } + var closure: ClosureType? { get } + var isSet: Bool { get } + var set: SetType? { get } + var asSource: String { get } + var description: String { get } + var debugDescription: String { get } +} + +extension TypeName: TypeNameAutoJSExport {} + +@objc protocol TypealiasAutoJSExport: JSExport { + var aliasName: String { get } + var typeName: TypeName { get } + var type: Type? { get } + var module: String? { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var parent: Type? { get } + var accessLevel: String { get } + var parentName: String? { get } + var name: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension Typealias: TypealiasAutoJSExport {} + + +@objc protocol TypesCollectionAutoJSExport: JSExport { +} + +extension TypesCollection: TypesCollectionAutoJSExport {} + +@objc protocol VariableAutoJSExport: JSExport { + var name: String { get } + var typeName: TypeName { get } + var type: Type? { get } + var isComputed: Bool { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var isStatic: Bool { get } + var readAccess: String { get } + var writeAccess: String { get } + var isMutable: Bool { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var isFinal: Bool { get } + var isLazy: Bool { get } + var isDynamic: Bool { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension Variable: VariableAutoJSExport {} + + +#endif """), .init(name: "Typed.generated.swift", content: """ -// Generated using Sourcery 2.0.3 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT // swiftlint:disable vertical_whitespace @@ -7747,341 +8472,6 @@ extension Variable { public var isDictionary: Bool { return typeName.isDictionary } } -"""), - .init(name: "Typed.swift", content: -""" -import Foundation - -/// Descibes typed declaration, i.e. variable, method parameter, tuple element, enum case associated value -public protocol Typed { - - // sourcery: skipEquality, skipDescription - /// Type, if known - var type: Type? { get } - - // sourcery: skipEquality, skipDescription - /// Type name - var typeName: TypeName { get } - - // sourcery: skipEquality, skipDescription - /// Whether type is optional - var isOptional: Bool { get } - - // sourcery: skipEquality, skipDescription - /// Whether type is implicitly unwrapped optional - var isImplicitlyUnwrappedOptional: Bool { get } - - // sourcery: skipEquality, skipDescription - /// Type name without attributes and optional type information - var unwrappedTypeName: String { get } -} - -"""), - .init(name: "Variable.swift", content: -""" -// -// Created by Krzysztof Zablocki on 13/09/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// :nodoc: -public typealias SourceryVariable = Variable - -/// Defines variable -@objcMembers -public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable { - - /// Variable name - public let name: String - - /// Variable type name - public let typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Variable type, if known, i.e. if the type is declared in the scanned sources. - /// For explanation, see - public var type: Type? - - /// Whether variable is computed and not stored - public let isComputed: Bool - - /// Whether variable is async - public let isAsync: Bool - - /// Whether variable throws - public let `throws`: Bool - - /// Whether variable is static - public let isStatic: Bool - - /// Variable read access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let readAccess: String - - /// Variable write access, i.e. `internal`, `private`, `fileprivate`, `public`, `open`. - /// For immutable variables this value is empty string - public let writeAccess: String - - /// composed access level - /// sourcery: skipJSExport - public var accessLevel: (read: AccessLevel, write: AccessLevel) { - (read: AccessLevel(rawValue: readAccess) ?? .none, AccessLevel(rawValue: writeAccess) ?? .none) - } - - /// Whether variable is mutable or not - public var isMutable: Bool { - return writeAccess != AccessLevel.none.rawValue - } - - /// Variable default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - public var documentation: Documentation = [] - - /// Variable attributes, i.e. `@IBOutlet`, `@IBInspectable` - public var attributes: AttributeList - - /// Modifiers, i.e. `private` - public var modifiers: [SourceryModifier] - - /// Whether variable is final or not - public var isFinal: Bool { - return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } - } - - /// Whether variable is lazy or not - public var isLazy: Bool { - return modifiers.contains { $0.name == Attribute.Identifier.lazy.rawValue } - } - - /// Whether variable is dynamic or not - public var isDynamic: Bool { - modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } - } - - /// Reference to type name where the variable is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc - public internal(set) var definedInTypeName: TypeName? - - /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` - public var actualDefinedInTypeName: TypeName? { - return definedInTypeName?.actualTypeName ?? definedInTypeName - } - - // sourcery: skipEquality, skipDescription - /// Reference to actual type where the object is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown - public var definedInType: Type? - - /// :nodoc: - public init(name: String = "", - typeName: TypeName, - type: Type? = nil, - accessLevel: (read: AccessLevel, write: AccessLevel) = (.internal, .internal), - isComputed: Bool = false, - isAsync: Bool = false, - `throws`: Bool = false, - isStatic: Bool = false, - defaultValue: String? = nil, - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - definedInTypeName: TypeName? = nil) { - - self.name = name - self.typeName = typeName - self.type = type - self.isComputed = isComputed - self.isAsync = isAsync - self.`throws` = `throws` - self.isStatic = isStatic - self.defaultValue = defaultValue - self.readAccess = accessLevel.read.rawValue - self.writeAccess = accessLevel.write.rawValue - self.attributes = attributes - self.modifiers = modifiers - self.annotations = annotations - self.documentation = documentation - self.definedInTypeName = definedInTypeName - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "isComputed = \\(String(describing: self.isComputed)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "isStatic = \\(String(describing: self.isStatic)), " - string += "readAccess = \\(String(describing: self.readAccess)), " - string += "writeAccess = \\(String(describing: self.writeAccess)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "isMutable = \\(String(describing: self.isMutable)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers)), " - string += "isFinal = \\(String(describing: self.isFinal)), " - string += "isLazy = \\(String(describing: self.isLazy)), " - string += "isDynamic = \\(String(describing: self.isDynamic)), " - string += "definedInTypeName = \\(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Variable else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "isComputed").trackDifference(actual: self.isComputed, expected: castObject.isComputed)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) - results.append(contentsOf: DiffableResult(identifier: "readAccess").trackDifference(actual: self.readAccess, expected: castObject.readAccess)) - results.append(contentsOf: DiffableResult(identifier: "writeAccess").trackDifference(actual: self.writeAccess, expected: castObject.writeAccess)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) - results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) - results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.isComputed) - hasher.combine(self.isAsync) - hasher.combine(self.`throws`) - hasher.combine(self.isStatic) - hasher.combine(self.readAccess) - hasher.combine(self.writeAccess) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.attributes) - hasher.combine(self.modifiers) - hasher.combine(self.definedInTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Variable else { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.isComputed != rhs.isComputed { return false } - if self.isAsync != rhs.isAsync { return false } - if self.`throws` != rhs.`throws` { return false } - if self.isStatic != rhs.isStatic { return false } - if self.readAccess != rhs.readAccess { return false } - if self.writeAccess != rhs.writeAccess { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.attributes != rhs.attributes { return false } - if self.modifiers != rhs.modifiers { return false } - if self.definedInTypeName != rhs.definedInTypeName { return false } - return true - } - -// sourcery:inline:Variable.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - self.isComputed = aDecoder.decode(forKey: "isComputed") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.isStatic = aDecoder.decode(forKey: "isStatic") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { - withVaList(["readAccess"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { - withVaList(["writeAccess"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.writeAccess = writeAccess - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { - withVaList(["attributes"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { - withVaList(["modifiers"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.modifiers = modifiers - self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") - self.definedInType = aDecoder.decode(forKey: "definedInType") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.isComputed, forKey: "isComputed") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.isStatic, forKey: "isStatic") - aCoder.encode(self.readAccess, forKey: "readAccess") - aCoder.encode(self.writeAccess, forKey: "writeAccess") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.attributes, forKey: "attributes") - aCoder.encode(self.modifiers, forKey: "modifiers") - aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") - aCoder.encode(self.definedInType, forKey: "definedInType") - } -// sourcery:end -} - """), ] #endif diff --git a/SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift b/SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift index 4f5215a8..decd40a0 100644 --- a/SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift +++ b/SourcerySwift/Sources/SourceryRuntime_Linux.content.generated.swift @@ -11,6 +11,7 @@ import Foundation /// :nodoc: public enum AccessLevel: String { + case `package` = "package" case `internal` = "internal" case `private` = "private" case `fileprivate` = "fileprivate" @@ -19,81 +20,6 @@ public enum AccessLevel: String { case none = "" } -"""), - .init(name: "GenericParameter.swift", content: -""" -import Foundation - -/// Descibes Swift generic parameter -public final class GenericParameter: NSObject, SourceryModel, Diffable { - - /// Generic parameter name - public var name: String - - /// Generic parameter inherited type - public var inheritedTypeName: TypeName? - - /// :nodoc: - public init(name: String, inheritedTypeName: TypeName? = nil) { - self.name = name - self.inheritedTypeName = inheritedTypeName - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "inheritedTypeName = \\(String(describing: self.inheritedTypeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "inheritedTypeName").trackDifference(actual: self.inheritedTypeName, expected: castObject.inheritedTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.inheritedTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericParameter else { return false } - if self.name != rhs.name { return false } - if self.inheritedTypeName != rhs.inheritedTypeName { return false } - return true - } - -// sourcery:inline:GenericParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.inheritedTypeName = aDecoder.decode(forKey: "inheritedTypeName") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.inheritedTypeName, forKey: "inheritedTypeName") - } - -// sourcery:end -} """), .init(name: "Actor.swift", content: """ @@ -101,13 +27,16 @@ import Foundation // sourcery: skipDescription /// Descibes Swift actor +#if canImport(ObjectiveC) +@objc(SwiftActor) @objcMembers +#endif public final class Actor: Type { /// Returns "actor" public override var kind: String { return "actor" } /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -150,11 +79,12 @@ public final class Actor: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "isFinal = \\(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("isFinal = \\(String(describing: self.isFinal))") return string } @@ -168,6 +98,8 @@ public final class Actor: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -192,7 +124,7 @@ public final class Actor: Type { super.encode(with: aCoder) } // sourcery:end - + } """), @@ -261,111 +193,15 @@ public extension Array { } } -"""), - .init(name: "Set.swift", content: -""" -import Foundation - -/// Describes set type -public final class SetType: NSObject, SourceryModel, Diffable { - /// Type name used in declaration - public var name: String - - /// Array element type name - public var elementTypeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Array element type, if known - public var elementType: Type? - - /// :nodoc: - public init(name: String, elementTypeName: TypeName, elementType: Type? = nil) { - self.name = name - self.elementTypeName = elementTypeName - self.elementType = elementType - } - - /// Returns array as generic type - public var asGeneric: GenericType { - GenericType(name: "Set", typeParameters: [ - .init(typeName: elementTypeName) - ]) - } - - public var asSource: String { - "[\\(elementTypeName.asSource)]" - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elementTypeName = \\(String(describing: self.elementTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? SetType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "elementTypeName").trackDifference(actual: self.elementTypeName, expected: castObject.elementTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.elementTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? SetType else { return false } - if self.name != rhs.name { return false } - if self.elementTypeName != rhs.elementTypeName { return false } - return true - } - -// sourcery:inline:SetType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { - withVaList(["elementTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.elementTypeName = elementTypeName - self.elementType = aDecoder.decode(forKey: "elementType") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.elementTypeName, forKey: "elementTypeName") - aCoder.encode(self.elementType, forKey: "elementType") - } -// sourcery:end -} - """), .init(name: "Array.swift", content: """ import Foundation /// Describes array type +#if canImport(ObjectiveC) +@objcMembers +#endif public final class ArrayType: NSObject, SourceryModel, Diffable { /// Type name used in declaration public var name: String @@ -396,12 +232,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elementTypeName = \\(String(describing: self.elementTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("elementTypeName = \\(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -416,6 +253,8 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -435,13 +274,13 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { + guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { withVaList(["elementTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -459,112 +298,15 @@ public final class ArrayType: NSObject, SourceryModel, Diffable { // sourcery:end } -"""), - .init(name: "NSException_Linux.swift", content: -""" -import Foundation - -public class NSException { - static func raise(_ name: String, format: String, arguments: CVaListPointer) { - fatalError ("\\(name) exception: \\(NSString(format: format, arguments: arguments))") - } - - static func raise(_ name: String) { - fatalError("\\(name) exception") - } -} - -public extension NSExceptionName { - static var parseErrorException = "parseErrorException" -} - -"""), - .init(name: "AssociatedType.swift", content: -""" -import Foundation - -/// Describes Swift AssociatedType -public final class AssociatedType: NSObject, SourceryModel { - /// Associated type name - public let name: String - - /// Associated type type constraint name, if specified - public let typeName: TypeName? - - // sourcery: skipEquality, skipDescription - /// Associated type constrained type, if known, i.e. if the type is declared in the scanned sources. - public var type: Type? - - /// :nodoc: - public init(name: String, typeName: TypeName? = nil, type: Type? = nil) { - self.name = name - self.typeName = typeName - self.type = type - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? AssociatedType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.typeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? AssociatedType else { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - return true - } - -// sourcery:inline:AssociatedType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.typeName = aDecoder.decode(forKey: "typeName") - self.type = aDecoder.decode(forKey: "type") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - } -// sourcery:end -} - """), .init(name: "Attribute.swift", content: """ import Foundation /// Describes Swift attribute +#if canImport(ObjectiveC) +@objcMembers +#endif public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJSExport, Diffable { /// Attribute name @@ -623,6 +365,7 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ case final case open case lazy + case `package` = "package" case `public` = "public" case `internal` = "internal" case `private` = "private" @@ -726,6 +469,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -747,19 +492,19 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let arguments: [String: NSObject] = aDecoder.decode(forKey: "arguments") else { + guard let arguments: [String: NSObject] = aDecoder.decode(forKey: "arguments") else { withVaList(["arguments"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.arguments = arguments - guard let _description: String = aDecoder.decode(forKey: "_description") else { + guard let _description: String = aDecoder.decode(forKey: "_description") else { withVaList(["_description"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -777,18 +522,6 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ } -"""), - .init(name: "AutoHashable.generated.swift", content: -""" -// Generated using Sourcery 1.3.1 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT -// swiftlint:disable all - - -// MARK: - AutoHashable for classes, protocols, structs - -// MARK: - AutoHashable for Enums - """), .init(name: "BytesRange.swift", content: """ @@ -800,6 +533,9 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ import Foundation /// :nodoc: +#if canImport(ObjectiveC) +@objcMembers +#endif public final class BytesRange: NSObject, SourceryModel, Diffable { public let offset: Int64 @@ -815,6 +551,7 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " string += "offset = \\(String(describing: self.offset)), " @@ -833,6 +570,8 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.offset) @@ -870,13 +609,16 @@ public final class BytesRange: NSObject, SourceryModel, Diffable { import Foundation // sourcery: skipDescription /// Descibes Swift class +#if canImport(ObjectiveC) +@objc(SwiftClass) @objcMembers +#endif public final class Class: Type { /// Returns "class" public override var kind: String { return "class" } - /// Whether type is final + /// Whether type is final public var isFinal: Bool { - return modifiers.contains { $0.name == "final" } + modifiers.contains { $0.name == "final" } } /// :nodoc: @@ -919,11 +661,12 @@ public final class Class: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "isFinal = \\(String(describing: self.isFinal))" + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("isFinal = \\(String(describing: self.isFinal))") return string } @@ -937,6 +680,8 @@ public final class Class: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -964,282 +709,6 @@ public final class Class: Type { } -"""), - .init(name: "Closure.swift", content: -""" -import Foundation - -/// Describes closure type -public final class ClosureType: NSObject, SourceryModel, Diffable { - - /// Type name used in declaration with stripped whitespaces and new lines - public let name: String - - /// List of closure parameters - public let parameters: [ClosureParameter] - - /// Return value type name - public let returnTypeName: TypeName - - /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` - public var actualReturnTypeName: TypeName { - return returnTypeName.actualTypeName ?? returnTypeName - } - - // sourcery: skipEquality, skipDescription - /// Actual return value type, if known - public var returnType: Type? - - // sourcery: skipEquality, skipDescription - /// Whether return value type is optional - public var isOptionalReturnType: Bool { - return returnTypeName.isOptional - } - - // sourcery: skipEquality, skipDescription - /// Whether return value type is implicitly unwrapped optional - public var isImplicitlyUnwrappedOptionalReturnType: Bool { - return returnTypeName.isImplicitlyUnwrappedOptional - } - - // sourcery: skipEquality, skipDescription - /// Return value type name without attributes and optional type information - public var unwrappedReturnTypeName: String { - return returnTypeName.unwrappedTypeName - } - - /// Whether method is async method - public let isAsync: Bool - - /// async keyword - public let asyncKeyword: String? - - /// Whether closure throws - public let `throws`: Bool - - /// throws or rethrows keyword - public let throwsOrRethrowsKeyword: String? - - /// :nodoc: - public init(name: String, parameters: [ClosureParameter], returnTypeName: TypeName, returnType: Type? = nil, asyncKeyword: String? = nil, throwsOrRethrowsKeyword: String? = nil) { - self.name = name - self.parameters = parameters - self.returnTypeName = returnTypeName - self.returnType = returnType - self.asyncKeyword = asyncKeyword - self.isAsync = asyncKeyword != nil - self.throwsOrRethrowsKeyword = throwsOrRethrowsKeyword - self.`throws` = throwsOrRethrowsKeyword != nil - } - - public var asSource: String { - "\\(parameters.asSource)\\(asyncKeyword != nil ? " \\(asyncKeyword!)" : "")\\(throwsOrRethrowsKeyword != nil ? " \\(throwsOrRethrowsKeyword!)" : "") -> \\(returnTypeName.asSource)" - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "parameters = \\(String(describing: self.parameters)), " - string += "returnTypeName = \\(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "asyncKeyword = \\(String(describing: self.asyncKeyword)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "throwsOrRethrowsKeyword = \\(String(describing: self.throwsOrRethrowsKeyword)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? ClosureType else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) - results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "asyncKeyword").trackDifference(actual: self.asyncKeyword, expected: castObject.asyncKeyword)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "throwsOrRethrowsKeyword").trackDifference(actual: self.throwsOrRethrowsKeyword, expected: castObject.throwsOrRethrowsKeyword)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.parameters) - hasher.combine(self.returnTypeName) - hasher.combine(self.isAsync) - hasher.combine(self.asyncKeyword) - hasher.combine(self.`throws`) - hasher.combine(self.throwsOrRethrowsKeyword) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? ClosureType else { return false } - if self.name != rhs.name { return false } - if self.parameters != rhs.parameters { return false } - if self.returnTypeName != rhs.returnTypeName { return false } - if self.isAsync != rhs.isAsync { return false } - if self.asyncKeyword != rhs.asyncKeyword { return false } - if self.`throws` != rhs.`throws` { return false } - if self.throwsOrRethrowsKeyword != rhs.throwsOrRethrowsKeyword { return false } - return true - } - -// sourcery:inline:ClosureType.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let parameters: [ClosureParameter] = aDecoder.decode(forKey: "parameters") else { - withVaList(["parameters"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { - withVaList(["returnTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.returnTypeName = returnTypeName - self.returnType = aDecoder.decode(forKey: "returnType") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.asyncKeyword = aDecoder.decode(forKey: "asyncKeyword") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.throwsOrRethrowsKeyword = aDecoder.decode(forKey: "throwsOrRethrowsKeyword") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.parameters, forKey: "parameters") - aCoder.encode(self.returnTypeName, forKey: "returnTypeName") - aCoder.encode(self.returnType, forKey: "returnType") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.asyncKeyword, forKey: "asyncKeyword") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.throwsOrRethrowsKeyword, forKey: "throwsOrRethrowsKeyword") - } -// sourcery:end - -} - -"""), - .init(name: "Coding.generated.swift", content: -""" -// Generated using Sourcery 2.0.3 — https://github.com/krzysztofzablocki/Sourcery -// DO NOT EDIT -// swiftlint:disable vertical_whitespace trailing_newline - -import Foundation - - -extension NSCoder { - - @nonobjc func decode(forKey: String) -> String? { - return self.maybeDecode(forKey: forKey) as String? - } - - @nonobjc func decode(forKey: String) -> TypeName? { - return self.maybeDecode(forKey: forKey) as TypeName? - } - - @nonobjc func decode(forKey: String) -> AccessLevel? { - return self.maybeDecode(forKey: forKey) as AccessLevel? - } - - @nonobjc func decode(forKey: String) -> Bool { - return self.decodeBool(forKey: forKey) - } - - @nonobjc func decode(forKey: String) -> Int { - return self.decodeInteger(forKey: forKey) - } - - func decode(forKey: String) -> E? { - return maybeDecode(forKey: forKey) as E? - } - - fileprivate func maybeDecode(forKey: String) -> E? { - guard let object = self.decodeObject(forKey: forKey) else { - return nil - } - - return object as? E - } - -} - -extension ArrayType: NSCoding {} - -extension AssociatedType: NSCoding {} - -extension AssociatedValue: NSCoding {} - -extension Attribute: NSCoding {} - -extension BytesRange: NSCoding {} - - -extension ClosureParameter: NSCoding {} - -extension ClosureType: NSCoding {} - -extension DictionaryType: NSCoding {} - - -extension EnumCase: NSCoding {} - -extension FileParserResult: NSCoding {} - -extension GenericRequirement: NSCoding {} - -extension GenericType: NSCoding {} - -extension GenericTypeParameter: NSCoding {} - -extension GenericParameter: NSCoding {} - -extension Import: NSCoding {} - -extension Method: NSCoding {} - -extension MethodParameter: NSCoding {} - -extension Modifier: NSCoding {} - - - - -extension Subscript: NSCoding {} - -extension TupleElement: NSCoding {} - -extension TupleType: NSCoding {} - -extension Type: NSCoding {} - -extension TypeName: NSCoding {} - -extension Typealias: NSCoding {} - -extension Types: NSCoding {} - -extension Variable: NSCoding {} - - """), .init(name: "Composer.swift", content: """ @@ -1272,12 +741,16 @@ public enum Composer { return composed.resolveType(typeName: typeName, containingType: containingType) } + let methodResolveType = { (typeName: TypeName, containingType: Type?, method: Method) -> Type? in + return composed.resolveType(typeName: typeName, containingType: containingType, method: method) + } + composed.types.parallelPerform { type in type.variables.forEach { resolveVariableTypes($0, of: type, resolve: resolveType) } type.methods.forEach { - resolveMethodTypes($0, of: type, resolve: resolveType) + resolveMethodTypes($0, of: type, resolve: methodResolveType) } type.subscripts.forEach { resolveSubscriptTypes($0, of: type, resolve: resolveType) @@ -1297,7 +770,7 @@ public enum Composer { } composed.functions.parallelPerform { function in - resolveMethodTypes(function, of: nil, resolve: resolveType) + resolveMethodTypes(function, of: nil, resolve: methodResolveType) } updateTypeRelationships(types: composed.types) @@ -1310,6 +783,7 @@ public enum Composer { } typealias TypeResolver = (TypeName, Type?) -> Type? + typealias MethodArgumentTypeResolver = (TypeName, Type?, Method) -> Type? private static func resolveVariableTypes(_ variable: Variable, of type: Type, resolve: TypeResolver) { variable.type = resolve(variable.typeName, type) @@ -1333,9 +807,9 @@ public enum Composer { } } - private static func resolveMethodTypes(_ method: SourceryMethod, of type: Type?, resolve: TypeResolver) { + private static func resolveMethodTypes(_ method: SourceryMethod, of type: Type?, resolve: MethodArgumentTypeResolver) { method.parameters.forEach { parameter in - parameter.type = resolve(parameter.typeName, type) + parameter.type = resolve(parameter.typeName, type, method) } /// The actual `definedInType` is assigned in `uniqueTypes` but we still @@ -1343,7 +817,7 @@ public enum Composer { /// @see https://github.com/krzysztofzablocki/Sourcery/pull/374 var definedInType: Type? if let definedInTypeName = method.definedInTypeName { - definedInType = resolve(definedInTypeName, type) + definedInType = resolve(definedInTypeName, type, method) } guard !method.returnTypeName.isVoid else { return } @@ -1369,7 +843,7 @@ public enum Composer { } } } else { - method.returnType = resolve(method.returnTypeName, type) + method.returnType = resolve(method.returnTypeName, type, method) } } @@ -1442,6 +916,13 @@ public enum Composer { } private static func findBaseType(for type: Type, name: String, typesByName: [String: Type]) -> Type? { + // special case to check if the type is based on one of the recognized types + // and the superclass has a generic constraint in `name` part of the `TypeName` + var name = name + if name.contains("<") && name.contains(">") { + let parts = name.split(separator: "<") + name = String(parts.first!) + } if let baseType = typesByName[name] { return baseType } @@ -1517,6 +998,9 @@ public protocol Definition: AnyObject { import Foundation /// Describes dictionary type +#if canImport(ObjectiveC) +@objcMembers +#endif public final class DictionaryType: NSObject, SourceryModel, Diffable { /// Type name used in declaration public var name: String @@ -1557,13 +1041,14 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "valueTypeName = \\(String(describing: self.valueTypeName)), " - string += "keyTypeName = \\(String(describing: self.keyTypeName)), " - string += "asGeneric = \\(String(describing: self.asGeneric)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("valueTypeName = \\(String(describing: self.valueTypeName)), ") + string.append("keyTypeName = \\(String(describing: self.keyTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -1579,6 +1064,8 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -1600,20 +1087,20 @@ public final class DictionaryType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let valueTypeName: TypeName = aDecoder.decode(forKey: "valueTypeName") else { + guard let valueTypeName: TypeName = aDecoder.decode(forKey: "valueTypeName") else { withVaList(["valueTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.valueTypeName = valueTypeName self.valueType = aDecoder.decode(forKey: "valueType") - guard let keyTypeName: TypeName = aDecoder.decode(forKey: "keyTypeName") else { + guard let keyTypeName: TypeName = aDecoder.decode(forKey: "keyTypeName") else { withVaList(["keyTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -1674,6 +1161,9 @@ extension NSRange: Diffable { } } +#if canImport(ObjectiveC) +@objcMembers +#endif public class DiffableResult: NSObject, AutoEquatable { // sourcery: skipEquality private var results: [String] @@ -1696,9 +1186,26 @@ public class DiffableResult: NSObject, AutoEquatable { var isEmpty: Bool { return results.isEmpty } + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.identifier) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? DiffableResult else { return false } + if self.identifier != rhs.identifier { return false } + return true + } + public override var description: String { guard !results.isEmpty else { return "" } - return "\\(identifier.flatMap { "\\($0) " } ?? "")" + results.joined(separator: "\\n") + var description = "\\(identifier.flatMap { "\\($0) " } ?? "")" + description.append(results.joined(separator: "\\n")) + return description } } @@ -1719,7 +1226,9 @@ public extension DiffableResult { /// :nodoc: @discardableResult func trackDifference(actual: T?, expected: T?) -> DiffableResult { if actual != expected { - let result = DiffableResult(results: [""]) + let expected = expected.map({ "\\($0)" }) ?? "nil" + let actual = actual.map({ "\\($0)" }) ?? "nil" + let result = DiffableResult(results: [""]) append(contentsOf: result) } return self @@ -1856,429 +1365,6 @@ public protocol Documented { var documentation: Documentation { get } } -"""), - .init(name: "EnumCase.swift", content: -""" -import Foundation - -/// Defines enum case -public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable { - - /// Enum case name - public let name: String - - /// Enum case raw value, if any - public let rawValue: String? - - /// Enum case associated values - public let associatedValues: [AssociatedValue] - - /// Enum case annotations - public var annotations: Annotations = [:] - - public var documentation: Documentation = [] - - /// Whether enum case is indirect - public let indirect: Bool - - /// Whether enum case has associated value - public var hasAssociatedValue: Bool { - return !associatedValues.isEmpty - } - - // Underlying parser data, never to be used by anything else - // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport - /// :nodoc: - public var __parserData: Any? - - /// :nodoc: - public init(name: String, rawValue: String? = nil, associatedValues: [AssociatedValue] = [], annotations: [String: NSObject] = [:], documentation: [String] = [], indirect: Bool = false) { - self.name = name - self.rawValue = rawValue - self.associatedValues = associatedValues - self.annotations = annotations - self.documentation = documentation - self.indirect = indirect - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "rawValue = \\(String(describing: self.rawValue)), " - string += "associatedValues = \\(String(describing: self.associatedValues)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "indirect = \\(String(describing: self.indirect)), " - string += "hasAssociatedValue = \\(String(describing: self.hasAssociatedValue))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? EnumCase else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "rawValue").trackDifference(actual: self.rawValue, expected: castObject.rawValue)) - results.append(contentsOf: DiffableResult(identifier: "associatedValues").trackDifference(actual: self.associatedValues, expected: castObject.associatedValues)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "indirect").trackDifference(actual: self.indirect, expected: castObject.indirect)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.rawValue) - hasher.combine(self.associatedValues) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.indirect) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? EnumCase else { return false } - if self.name != rhs.name { return false } - if self.rawValue != rhs.rawValue { return false } - if self.associatedValues != rhs.associatedValues { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.indirect != rhs.indirect { return false } - return true - } - -// sourcery:inline:EnumCase.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.rawValue = aDecoder.decode(forKey: "rawValue") - guard let associatedValues: [AssociatedValue] = aDecoder.decode(forKey: "associatedValues") else { - withVaList(["associatedValues"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.associatedValues = associatedValues - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - self.indirect = aDecoder.decode(forKey: "indirect") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.rawValue, forKey: "rawValue") - aCoder.encode(self.associatedValues, forKey: "associatedValues") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.indirect, forKey: "indirect") - } -// sourcery:end -} - -"""), - .init(name: "AssociatedValue.swift", content: -""" -// -// Created by Krzysztof Zablocki on 13/09/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// Defines enum case associated value -public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable { - - /// Associated value local name. - /// This is a name to be used to construct enum case value - public let localName: String? - - /// Associated value external name. - /// This is a name to be used to access value in value-bindig - public let externalName: String? - - /// Associated value type name - public let typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Associated value type, if known - public var type: Type? - - /// Associated value default value - public let defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(localName: String?, externalName: String?, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { - self.localName = localName - self.externalName = externalName - self.typeName = typeName - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - } - - convenience init(name: String? = nil, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { - self.init(localName: name, externalName: name, typeName: typeName, type: type, defaultValue: defaultValue, annotations: annotations) - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "localName = \\(String(describing: self.localName)), " - string += "externalName = \\(String(describing: self.externalName)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? AssociatedValue else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "localName").trackDifference(actual: self.localName, expected: castObject.localName)) - results.append(contentsOf: DiffableResult(identifier: "externalName").trackDifference(actual: self.externalName, expected: castObject.externalName)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.localName) - hasher.combine(self.externalName) - hasher.combine(self.typeName) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? AssociatedValue else { return false } - if self.localName != rhs.localName { return false } - if self.externalName != rhs.externalName { return false } - if self.typeName != rhs.typeName { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - -// sourcery:inline:AssociatedValue.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.localName = aDecoder.decode(forKey: "localName") - self.externalName = aDecoder.decode(forKey: "externalName") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.localName, forKey: "localName") - aCoder.encode(self.externalName, forKey: "externalName") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } -// sourcery:end - -} - -"""), - .init(name: "Enum.swift", content: -""" -import Foundation - -/// Defines Swift enum -public final class Enum: Type { - - // sourcery: skipDescription - /// Returns "enum" - public override var kind: String { return "enum" } - - /// Enum cases - public var cases: [EnumCase] - - /** - Enum raw value type name, if any. This type is removed from enum's `based` and `inherited` types collections. - - - important: Unless raw type is specified explicitly via type alias RawValue it will be set to the first type in the inheritance chain. - So if your enum does not have raw value but implements protocols you'll have to specify conformance to these protocols via extension to get enum with nil raw value type and all based and inherited types. - */ - public var rawTypeName: TypeName? { - didSet { - if let rawTypeName = rawTypeName { - hasRawType = true - if let index = inheritedTypes.firstIndex(of: rawTypeName.name) { - inheritedTypes.remove(at: index) - } - if based[rawTypeName.name] != nil { - based[rawTypeName.name] = nil - } - } else { - hasRawType = false - } - } - } - - // sourcery: skipDescription, skipEquality - /// :nodoc: - public private(set) var hasRawType: Bool - - // sourcery: skipDescription, skipEquality - /// Enum raw value type, if known - public var rawType: Type? - - // sourcery: skipEquality, skipDescription, skipCoding - /// Names of types or protocols this type inherits from, including unknown (not scanned) types - public override var based: [String: String] { - didSet { - if let rawTypeName = rawTypeName, based[rawTypeName.name] != nil { - based[rawTypeName.name] = nil - } - } - } - - /// Whether enum contains any associated values - public var hasAssociatedValues: Bool { - return cases.contains(where: { $0.hasAssociatedValue }) - } - - /// :nodoc: - public init(name: String = "", - parent: Type? = nil, - accessLevel: AccessLevel = .internal, - isExtension: Bool = false, - inheritedTypes: [String] = [], - rawTypeName: TypeName? = nil, - cases: [EnumCase] = [], - variables: [Variable] = [], - methods: [Method] = [], - containedTypes: [Type] = [], - typealiases: [Typealias] = [], - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - isGeneric: Bool = false) { - - self.cases = cases - self.rawTypeName = rawTypeName - self.hasRawType = rawTypeName != nil || !inheritedTypes.isEmpty - - super.init(name: name, parent: parent, accessLevel: accessLevel, isExtension: isExtension, variables: variables, methods: methods, inheritedTypes: inheritedTypes, containedTypes: containedTypes, typealiases: typealiases, attributes: attributes, modifiers: modifiers, annotations: annotations, documentation: documentation, isGeneric: isGeneric) - - if let rawTypeName = rawTypeName?.name, let index = self.inheritedTypes.firstIndex(of: rawTypeName) { - self.inheritedTypes.remove(at: index) - } - } - - /// :nodoc: - override public var description: String { - var string = super.description - string += ", " - string += "cases = \\(String(describing: self.cases)), " - string += "rawTypeName = \\(String(describing: self.rawTypeName)), " - string += "hasAssociatedValues = \\(String(describing: self.hasAssociatedValues))" - return string - } - - override public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Enum else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "cases").trackDifference(actual: self.cases, expected: castObject.cases)) - results.append(contentsOf: DiffableResult(identifier: "rawTypeName").trackDifference(actual: self.rawTypeName, expected: castObject.rawTypeName)) - results.append(contentsOf: super.diffAgainst(castObject)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.cases) - hasher.combine(self.rawTypeName) - hasher.combine(super.hash) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Enum else { return false } - if self.cases != rhs.cases { return false } - if self.rawTypeName != rhs.rawTypeName { return false } - return super.isEqual(rhs) - } - -// sourcery:inline:Enum.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let cases: [EnumCase] = aDecoder.decode(forKey: "cases") else { - withVaList(["cases"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.cases = cases - self.rawTypeName = aDecoder.decode(forKey: "rawTypeName") - self.hasRawType = aDecoder.decode(forKey: "hasRawType") - self.rawType = aDecoder.decode(forKey: "rawType") - super.init(coder: aDecoder) - } - - /// :nodoc: - override public func encode(with aCoder: NSCoder) { - super.encode(with: aCoder) - aCoder.encode(self.cases, forKey: "cases") - aCoder.encode(self.rawTypeName, forKey: "rawTypeName") - aCoder.encode(self.hasRawType, forKey: "hasRawType") - aCoder.encode(self.rawType, forKey: "rawType") - } -// sourcery:end -} - """), .init(name: "Extensions.swift", content: """ @@ -2473,29 +1559,37 @@ public extension String { defer { i = self.index(i, offsetBy: offset) } - let currentlyScanned = self[i..<(self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) ?? self.endIndex)] - if let openString = between.open.first(where: { String(self[i...]).starts(with: $0) }) { - if !(boundingCharactersCount == 0 && String(self[i]) == delimiter) { + var currentlyScannedEnd: Index = self.endIndex + if let endIndex = self.index(i, offsetBy: delimiter.count, limitedBy: self.endIndex) { + currentlyScannedEnd = endIndex + } + let currentlyScanned: String = String(self[i..` - if !(self[i] == ">" && item.last == "-") { + if !((self[i] == ">") as Bool && (item.last == "-") as Bool) { boundingCharactersCount = max(0, boundingCharactersCount - 1) } offset = closeString.count } - if self[i] == "\\"" { + if (self[i] == "\\"") as Bool { quotesCount += 1 } - if currentlyScanned == delimiter && boundingCharactersCount == 0 && quotesCount % 2 == 0 { + let currentIsDelimiter = (currentlyScanned == delimiter) as Bool + let boundingCountIsZero = (boundingCharactersCount == 0) as Bool + let hasEvenQuotes = (quotesCount % 2 == 0) as Bool + if currentIsDelimiter && boundingCountIsZero && hasEvenQuotes { items.append(item) item = "" i = self.index(i, offsetBy: delimiter.count - 1) } else { - item += self[i..` public var name: String @@ -2735,6 +1838,8 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -2748,19 +1853,19 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa if self.name != rhs.name { return false } if self.typeParameters != rhs.typeParameters { return false } return true - } + } // sourcery:inline:GenericType.AutoCoding /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let typeParameters: [GenericTypeParameter] = aDecoder.decode(forKey: "typeParameters") else { + guard let typeParameters: [GenericTypeParameter] = aDecoder.decode(forKey: "typeParameters") else { withVaList(["typeParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -2777,201 +1882,15 @@ public final class GenericType: NSObject, SourceryModelWithoutDescription, Diffa // sourcery:end } -/// Descibes Swift generic type parameter -public final class GenericTypeParameter: NSObject, SourceryModel, Diffable { - - /// Generic parameter type name - public var typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Generic parameter type, if known - public var type: Type? - - /// :nodoc: - public init(typeName: TypeName, type: Type? = nil) { - self.typeName = typeName - self.type = type - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "typeName = \\(String(describing: self.typeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericTypeParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.typeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericTypeParameter else { return false } - if self.typeName != rhs.typeName { return false } - return true - } - -// sourcery:inline:GenericTypeParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - } - -// sourcery:end -} - -"""), - .init(name: "GenericRequirement.swift", content: -""" -import Foundation - -/// modifier can be thing like `private`, `class`, `nonmutating` -/// if a declaration has modifier like `private(set)` it's name will be `private` and detail will be `set` -public class GenericRequirement: NSObject, SourceryModel, Diffable { - - public enum Relationship: String { - case equals - case conformsTo - - var syntax: String { - switch self { - case .equals: - return "==" - case .conformsTo: - return ":" - } - } - } - - public var leftType: AssociatedType - public let rightType: GenericTypeParameter - - /// relationship name - public let relationship: String - - /// Syntax e.g. `==` or `:` - public let relationshipSyntax: String - - public init(leftType: AssociatedType, rightType: GenericTypeParameter, relationship: Relationship) { - self.leftType = leftType - self.rightType = rightType - self.relationship = relationship.rawValue - self.relationshipSyntax = relationship.syntax - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "leftType = \\(String(describing: self.leftType)), " - string += "rightType = \\(String(describing: self.rightType)), " - string += "relationship = \\(String(describing: self.relationship)), " - string += "relationshipSyntax = \\(String(describing: self.relationshipSyntax))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? GenericRequirement else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "leftType").trackDifference(actual: self.leftType, expected: castObject.leftType)) - results.append(contentsOf: DiffableResult(identifier: "rightType").trackDifference(actual: self.rightType, expected: castObject.rightType)) - results.append(contentsOf: DiffableResult(identifier: "relationship").trackDifference(actual: self.relationship, expected: castObject.relationship)) - results.append(contentsOf: DiffableResult(identifier: "relationshipSyntax").trackDifference(actual: self.relationshipSyntax, expected: castObject.relationshipSyntax)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.leftType) - hasher.combine(self.rightType) - hasher.combine(self.relationship) - hasher.combine(self.relationshipSyntax) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? GenericRequirement else { return false } - if self.leftType != rhs.leftType { return false } - if self.rightType != rhs.rightType { return false } - if self.relationship != rhs.relationship { return false } - if self.relationshipSyntax != rhs.relationshipSyntax { return false } - return true - } - - // sourcery:inline:GenericRequirement.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { - withVaList(["leftType"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.leftType = leftType - guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { - withVaList(["rightType"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.rightType = rightType - guard let relationship: String = aDecoder.decode(forKey: "relationship") else { - withVaList(["relationship"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.relationship = relationship - guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { - withVaList(["relationshipSyntax"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.relationshipSyntax = relationshipSyntax - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.leftType, forKey: "leftType") - aCoder.encode(self.rightType, forKey: "rightType") - aCoder.encode(self.relationship, forKey: "relationship") - aCoder.encode(self.relationshipSyntax, forKey: "relationshipSyntax") - } - // sourcery:end -} - """), .init(name: "Import.swift", content: """ import Foundation /// Defines import type +#if canImport(ObjectiveC) +@objcMembers +#endif public class Import: NSObject, SourceryModelWithoutDescription, Diffable { /// Import kind, e.g. class, struct in `import class Module.ClassName` public var kind: String? @@ -3018,6 +1937,8 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.kind) @@ -3038,7 +1959,7 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.kind = aDecoder.decode(forKey: "kind") - guard let path: String = aDecoder.decode(forKey: "path") else { + guard let path: String = aDecoder.decode(forKey: "path") else { withVaList(["path"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -3058,6 +1979,7 @@ public class Import: NSObject, SourceryModelWithoutDescription, Diffable { """), .init(name: "Log.swift", content: """ +//import Darwin import Foundation /// :nodoc: @@ -3132,781 +2054,6 @@ public enum Log { extension String: Error {} -"""), - .init(name: "MethodParameter.swift", content: -""" -import Foundation - -/// Describes method parameter -public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable { - - /// Parameter external name - public var argumentLabel: String? - - // Note: although method parameter can have no name, this property is not optional, - // this is so to maintain compatibility with existing templates. - /// Parameter internal name - public let name: String - - /// Parameter type name - public let typeName: TypeName - - /// Parameter flag whether it's inout or not - public let `inout`: Bool - - /// Is this variadic parameter? - public let isVariadic: Bool - - // sourcery: skipEquality, skipDescription - /// Parameter type, if known - public var type: Type? - - /// Parameter type attributes, i.e. `@escaping` - public var typeAttributes: AttributeList { - return typeName.attributes - } - - /// Method parameter default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(argumentLabel: String?, name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { - self.typeName = typeName - self.argumentLabel = argumentLabel - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - self.isVariadic = isVariadic - } - - /// :nodoc: - public init(name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { - self.typeName = typeName - self.argumentLabel = name - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - self.isVariadic = isVariadic - } - - public var asSource: String { - let typeSuffix = ": \\(`inout` ? "inout " : "")\\(typeName.asSource)\\(defaultValue.map { " = \\($0)" } ?? "")" + (isVariadic ? "..." : "") - guard argumentLabel != name else { - return name + typeSuffix - } - - let labels = [argumentLabel ?? "_", name.nilIfEmpty] - .compactMap { $0 } - .joined(separator: " ") - - return (labels.nilIfEmpty ?? "_") + typeSuffix - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "argumentLabel = \\(String(describing: self.argumentLabel)), " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "`inout` = \\(String(describing: self.`inout`)), " - string += "isVariadic = \\(String(describing: self.isVariadic)), " - string += "typeAttributes = \\(String(describing: self.typeAttributes)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? MethodParameter else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "argumentLabel").trackDifference(actual: self.argumentLabel, expected: castObject.argumentLabel)) - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "`inout`").trackDifference(actual: self.`inout`, expected: castObject.`inout`)) - results.append(contentsOf: DiffableResult(identifier: "isVariadic").trackDifference(actual: self.isVariadic, expected: castObject.isVariadic)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.argumentLabel) - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.`inout`) - hasher.combine(self.isVariadic) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? MethodParameter else { return false } - if self.argumentLabel != rhs.argumentLabel { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.`inout` != rhs.`inout` { return false } - if self.isVariadic != rhs.isVariadic { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - -// sourcery:inline:MethodParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.`inout` = aDecoder.decode(forKey: "`inout`") - self.isVariadic = aDecoder.decode(forKey: "isVariadic") - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.argumentLabel, forKey: "argumentLabel") - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.isVariadic, forKey: "isVariadic") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } -// sourcery:end -} - -extension Array where Element == MethodParameter { - public var asSource: String { - "(\\(map { $0.asSource }.joined(separator: ", ")))" - } -} - -"""), - .init(name: "ClosureParameter.swift", content: -""" -import Foundation - -// sourcery: skipDiffing -public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated { - /// Parameter external name - public var argumentLabel: String? - - /// Parameter internal name - public let name: String? - - /// Parameter type name - public let typeName: TypeName - - /// Parameter flag whether it's inout or not - public let `inout`: Bool - - // sourcery: skipEquality, skipDescription - /// Parameter type, if known - public var type: Type? - - /// Parameter type attributes, i.e. `@escaping` - public var typeAttributes: AttributeList { - return typeName.attributes - } - - /// Method parameter default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - /// :nodoc: - public init(argumentLabel: String? = nil, name: String? = nil, typeName: TypeName, type: Type? = nil, - defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false) { - self.typeName = typeName - self.argumentLabel = argumentLabel - self.name = name - self.type = type - self.defaultValue = defaultValue - self.annotations = annotations - self.`inout` = isInout - } - - public var asSource: String { - let typeInfo = "\\(`inout` ? "inout " : "")\\(typeName.asSource)" - if argumentLabel?.nilIfNotValidParameterName == nil, name?.nilIfNotValidParameterName == nil { - return typeInfo - } - - let typeSuffix = ": \\(typeInfo)" - guard argumentLabel != name else { - return name ?? "" + typeSuffix - } - - let labels = [argumentLabel ?? "_", name?.nilIfEmpty] - .compactMap { $0 } - .joined(separator: " ") - - return (labels.nilIfEmpty ?? "_") + typeSuffix - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.argumentLabel) - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.`inout`) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - return hasher.finalize() - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "argumentLabel = \\(String(describing: self.argumentLabel)), " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "`inout` = \\(String(describing: self.`inout`)), " - string += "typeAttributes = \\(String(describing: self.typeAttributes)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "asSource = \\(String(describing: self.asSource))" - return string - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? ClosureParameter else { return false } - if self.argumentLabel != rhs.argumentLabel { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.`inout` != rhs.`inout` { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - return true - } - - // sourcery:inline:ClosureParameter.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") - self.name = aDecoder.decode(forKey: "name") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.`inout` = aDecoder.decode(forKey: "`inout`") - self.type = aDecoder.decode(forKey: "type") - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.argumentLabel, forKey: "argumentLabel") - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.`inout`, forKey: "`inout`") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - } - - // sourcery:end -} - -extension Array where Element == ClosureParameter { - public var asSource: String { - "(\\(map { $0.asSource }.joined(separator: ", ")))" - } -} - -"""), - .init(name: "Method.swift", content: -""" -import Foundation - -/// :nodoc: -public typealias SourceryMethod = Method - -/// Describes method -public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable { - public subscript(dynamicMember member: String) -> Any? { - switch member { - case "definedInType": - return definedInType - case "shortName": - return shortName - case "name": - return name - case "selectorName": - return selectorName - case "callName": - return callName - case "parameters": - return parameters - case "throws": - return `throws` - case "isInitializer": - return isInitializer - case "accessLevel": - return accessLevel - case "isStatic": - return isStatic - case "returnTypeName": - return returnTypeName - case "isAsync": - return isAsync - case "attributes": - return attributes - case "isOptionalReturnType": - return isOptionalReturnType - case "actualReturnTypeName": - return actualReturnTypeName - case "isDynamic": - return isDynamic - case "genericRequirements": - return genericRequirements - default: - fatalError("unable to lookup: \\(member) in \\(self)") - } - } - - /// Full method name, including generic constraints, i.e. `foo(bar: T)` - public let name: String - - /// Method name including arguments names, i.e. `foo(bar:)` - public var selectorName: String - - // sourcery: skipEquality, skipDescription - /// Method name without arguments names and parenthesis, i.e. `foo` - public var shortName: String { - return name.range(of: "(").map({ String(name[..<$0.lowerBound]) }) ?? name - } - - // sourcery: skipEquality, skipDescription - /// Method name without arguments names, parenthesis and generic types, i.e. `foo` (can be used to generate code for method call) - public var callName: String { - return shortName.range(of: "<").map({ String(shortName[..<$0.lowerBound]) }) ?? shortName - } - - /// Method parameters - public var parameters: [MethodParameter] - - /// Return value type name used in declaration, including generic constraints, i.e. `where T: Equatable` - public var returnTypeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` - public var actualReturnTypeName: TypeName { - return returnTypeName.actualTypeName ?? returnTypeName - } - - // sourcery: skipEquality, skipDescription - /// Actual return value type, if known - public var returnType: Type? - - // sourcery: skipEquality, skipDescription - /// Whether return value type is optional - public var isOptionalReturnType: Bool { - return returnTypeName.isOptional || isFailableInitializer - } - - // sourcery: skipEquality, skipDescription - /// Whether return value type is implicitly unwrapped optional - public var isImplicitlyUnwrappedOptionalReturnType: Bool { - return returnTypeName.isImplicitlyUnwrappedOptional - } - - // sourcery: skipEquality, skipDescription - /// Return value type name without attributes and optional type information - public var unwrappedReturnTypeName: String { - return returnTypeName.unwrappedTypeName - } - - /// Whether method is async method - public let isAsync: Bool - - /// Whether method throws - public let `throws`: Bool - - /// Whether method rethrows - public let `rethrows`: Bool - - /// Method access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let accessLevel: String - - /// Whether method is a static method - public let isStatic: Bool - - /// Whether method is a class method - public let isClass: Bool - - // sourcery: skipEquality, skipDescription - /// Whether method is an initializer - public var isInitializer: Bool { - return selectorName.hasPrefix("init(") || selectorName == "init" - } - - // sourcery: skipEquality, skipDescription - /// Whether method is an deinitializer - public var isDeinitializer: Bool { - return selectorName == "deinit" - } - - /// Whether method is a failable initializer - public let isFailableInitializer: Bool - - // sourcery: skipEquality, skipDescription - /// Whether method is a convenience initializer - public var isConvenienceInitializer: Bool { - modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is required - public var isRequired: Bool { - modifiers.contains { $0.name == Attribute.Identifier.required.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is final - public var isFinal: Bool { - modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is mutating - public var isMutating: Bool { - modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is generic - public var isGeneric: Bool { - shortName.hasSuffix(">") - } - - // sourcery: skipEquality, skipDescription - /// Whether method is optional (in an Objective-C protocol) - public var isOptional: Bool { - modifiers.contains { $0.name == Attribute.Identifier.optional.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is nonisolated (this modifier only applies to actor methods) - public var isNonisolated: Bool { - modifiers.contains { $0.name == Attribute.Identifier.nonisolated.rawValue } - } - - // sourcery: skipEquality, skipDescription - /// Whether method is dynamic - public var isDynamic: Bool { - modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } - } - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public let annotations: Annotations - - public let documentation: Documentation - - /// Reference to type name where the method is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc - public let definedInTypeName: TypeName? - - // sourcery: skipEquality, skipDescription - /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` - public var actualDefinedInTypeName: TypeName? { - return definedInTypeName?.actualTypeName ?? definedInTypeName - } - - // sourcery: skipEquality, skipDescription - /// Reference to actual type where the object is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown - public var definedInType: Type? - - /// Method attributes, i.e. `@discardableResult` - public let attributes: AttributeList - - /// Method modifiers, i.e. `private` - public let modifiers: [SourceryModifier] - - // Underlying parser data, never to be used by anything else - // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport - /// :nodoc: - public var __parserData: Any? - - /// list of generic requirements - public var genericRequirements: [GenericRequirement] - - /// :nodoc: - public init(name: String, - selectorName: String? = nil, - parameters: [MethodParameter] = [], - returnTypeName: TypeName = TypeName(name: "Void"), - isAsync: Bool = false, - throws: Bool = false, - rethrows: Bool = false, - accessLevel: AccessLevel = .internal, - isStatic: Bool = false, - isClass: Bool = false, - isFailableInitializer: Bool = false, - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - definedInTypeName: TypeName? = nil, - genericRequirements: [GenericRequirement] = []) { - self.name = name - self.selectorName = selectorName ?? name - self.parameters = parameters - self.returnTypeName = returnTypeName - self.isAsync = isAsync - self.throws = `throws` - self.rethrows = `rethrows` - self.accessLevel = accessLevel.rawValue - self.isStatic = isStatic - self.isClass = isClass - self.isFailableInitializer = isFailableInitializer - self.attributes = attributes - self.modifiers = modifiers - self.annotations = annotations - self.documentation = documentation - self.definedInTypeName = definedInTypeName - self.genericRequirements = genericRequirements - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "selectorName = \\(String(describing: self.selectorName)), " - string += "parameters = \\(String(describing: self.parameters)), " - string += "returnTypeName = \\(String(describing: self.returnTypeName)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "`rethrows` = \\(String(describing: self.`rethrows`)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "isStatic = \\(String(describing: self.isStatic)), " - string += "isClass = \\(String(describing: self.isClass)), " - string += "isFailableInitializer = \\(String(describing: self.isFailableInitializer)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "definedInTypeName = \\(String(describing: self.definedInTypeName)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers))" - string += "genericRequirements = \\(String(describing: self.genericRequirements))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Method else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "selectorName").trackDifference(actual: self.selectorName, expected: castObject.selectorName)) - results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) - results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "`rethrows`").trackDifference(actual: self.`rethrows`, expected: castObject.`rethrows`)) - results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) - results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) - results.append(contentsOf: DiffableResult(identifier: "isClass").trackDifference(actual: self.isClass, expected: castObject.isClass)) - results.append(contentsOf: DiffableResult(identifier: "isFailableInitializer").trackDifference(actual: self.isFailableInitializer, expected: castObject.isFailableInitializer)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) - results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) - results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) - results.append(contentsOf: DiffableResult(identifier: "genericRequirements").trackDifference(actual: self.genericRequirements, expected: castObject.genericRequirements)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.selectorName) - hasher.combine(self.parameters) - hasher.combine(self.returnTypeName) - hasher.combine(self.isAsync) - hasher.combine(self.`throws`) - hasher.combine(self.`rethrows`) - hasher.combine(self.accessLevel) - hasher.combine(self.isStatic) - hasher.combine(self.isClass) - hasher.combine(self.isFailableInitializer) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.definedInTypeName) - hasher.combine(self.attributes) - hasher.combine(self.modifiers) - hasher.combine(self.genericRequirements) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Method else { return false } - if self.name != rhs.name { return false } - if self.selectorName != rhs.selectorName { return false } - if self.parameters != rhs.parameters { return false } - if self.returnTypeName != rhs.returnTypeName { return false } - if self.isAsync != rhs.isAsync { return false } - if self.`throws` != rhs.`throws` { return false } - if self.`rethrows` != rhs.`rethrows` { return false } - if self.accessLevel != rhs.accessLevel { return false } - if self.isStatic != rhs.isStatic { return false } - if self.isClass != rhs.isClass { return false } - if self.isFailableInitializer != rhs.isFailableInitializer { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.definedInTypeName != rhs.definedInTypeName { return false } - if self.attributes != rhs.attributes { return false } - if self.modifiers != rhs.modifiers { return false } - if self.genericRequirements != rhs.genericRequirements { return false } - return true - } - -// sourcery:inline:Method.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let selectorName: String = aDecoder.decode(forKey: "selectorName") else { - withVaList(["selectorName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.selectorName = selectorName - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { - withVaList(["parameters"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { - withVaList(["returnTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.returnTypeName = returnTypeName - self.returnType = aDecoder.decode(forKey: "returnType") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.`rethrows` = aDecoder.decode(forKey: "`rethrows`") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { - withVaList(["accessLevel"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.accessLevel = accessLevel - self.isStatic = aDecoder.decode(forKey: "isStatic") - self.isClass = aDecoder.decode(forKey: "isClass") - self.isFailableInitializer = aDecoder.decode(forKey: "isFailableInitializer") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") - self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { - withVaList(["attributes"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { - withVaList(["modifiers"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.modifiers = modifiers - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.selectorName, forKey: "selectorName") - aCoder.encode(self.parameters, forKey: "parameters") - aCoder.encode(self.returnTypeName, forKey: "returnTypeName") - aCoder.encode(self.returnType, forKey: "returnType") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.`rethrows`, forKey: "`rethrows`") - aCoder.encode(self.accessLevel, forKey: "accessLevel") - aCoder.encode(self.isStatic, forKey: "isStatic") - aCoder.encode(self.isClass, forKey: "isClass") - aCoder.encode(self.isFailableInitializer, forKey: "isFailableInitializer") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") - aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.attributes, forKey: "attributes") - aCoder.encode(self.modifiers, forKey: "modifiers") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") - } -// sourcery:end -} - """), .init(name: "Modifier.swift", content: """ @@ -3915,6 +2062,9 @@ import Foundation public typealias SourceryModifier = Modifier /// modifier can be thing like `private`, `class`, `nonmutating` /// if a declaration has modifier like `private(set)` it's name will be `private` and detail will be `set` +#if canImport(ObjectiveC) +@objcMembers +#endif public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJSExport, Diffable { /// The declaration modifier name. @@ -3947,6 +2097,8 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -3966,12 +2118,12 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name self.detail = aDecoder.decode(forKey: "detail") } @@ -3983,7 +2135,6 @@ public class Modifier: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJS // sourcery:end } - """), .init(name: "ParserResultsComposed.swift", content: """ @@ -4064,37 +2215,42 @@ internal struct ParserResultsComposed { } } + // if it had contained types, they might have been fully defined and so their name has to be noted in uniques + private mutating func rewriteChildren(of type: Type) { + // child is never an extension so no need to check + for child in type.containedTypes { + typeMap[child.globalName] = child + rewriteChildren(of: child) + } + } + private mutating func unifyTypes() -> [Type] { /// Resolve actual names of extensions, as they could have been done on typealias and note updated child names in uniques if needed parsedTypes .filter { $0.isExtension } - .forEach { - let oldName = $0.globalName + .forEach { (type: Type) in + let oldName = type.globalName - if $0.parent == nil, $0.localName.contains(".") { - resolveExtensionOfNestedType($0) + let hasDotInLocalName = type.localName.contains(".") as Bool + if let _ = type.parent, hasDotInLocalName { + resolveExtensionOfNestedType(type) } - if let resolved = resolveGlobalName(for: oldName, containingType: $0.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { - $0.localName = resolved.replacingOccurrences(of: "\\($0.module != nil ? "\\($0.module!)." : "")", with: "") + if let resolved = resolveGlobalName(for: oldName, containingType: type.parent, unique: typeMap, modules: modules, typealiases: resolvedTypealiases)?.name { + var moduleName: String = "" + if let module = type.module { + moduleName = "\\(module)." + } + type.localName = resolved.replacingOccurrences(of: moduleName, with: "") } else { return } // nothing left to do - guard oldName != $0.globalName else { + guard oldName != type.globalName else { return } - - // if it had contained types, they might have been fully defined and so their name has to be noted in uniques - func rewriteChildren(of type: Type) { - // child is never an extension so no need to check - for child in type.containedTypes { - typeMap[child.globalName] = child - rewriteChildren(of: child) - } - } - rewriteChildren(of: $0) + rewriteChildren(of: type) } // extend all types with their extensions @@ -4609,6 +2765,9 @@ import Foundation public typealias SourceryProtocol = Protocol /// Describes Swift protocol +#if canImport(ObjectiveC) +@objcMembers +#endif public final class Protocol: Type { /// Returns "protocol" @@ -4621,6 +2780,7 @@ public final class Protocol: Type { } } + // sourcery: skipCoding /// list of generic requirements public override var genericRequirements: [GenericRequirement] { didSet { @@ -4669,11 +2829,12 @@ public final class Protocol: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description - string += ", " - string += "kind = \\(String(describing: self.kind)), " - string += "associatedTypes = \\(String(describing: self.associatedTypes)), " + string.append(", ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("associatedTypes = \\(String(describing: self.associatedTypes)), ") return string } @@ -4688,6 +2849,8 @@ public final class Protocol: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.associatedTypes) @@ -4706,7 +2869,7 @@ public final class Protocol: Type { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let associatedTypes: [String: AssociatedType] = aDecoder.decode(forKey: "associatedTypes") else { + guard let associatedTypes: [String: AssociatedType] = aDecoder.decode(forKey: "associatedTypes") else { withVaList(["associatedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -4731,8 +2894,10 @@ public final class Protocol: Type { import Foundation -// sourcery: skipJSExport /// Describes a Swift [protocol composition](https://docs.swift.org/swift-book/ReferenceManual/Types.html#ID454). +#if canImport(ObjectiveC) +@objcMembers +#endif public final class ProtocolComposition: Type { /// Returns "protocolComposition" @@ -4782,6 +2947,7 @@ public final class ProtocolComposition: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -4801,6 +2967,8 @@ public final class ProtocolComposition: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.composedTypeNames) @@ -4819,7 +2987,7 @@ public final class ProtocolComposition: Type { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let composedTypeNames: [TypeName] = aDecoder.decode(forKey: "composedTypeNames") else { + guard let composedTypeNames: [TypeName] = aDecoder.decode(forKey: "composedTypeNames") else { withVaList(["composedTypeNames"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -4839,6 +3007,111 @@ public final class ProtocolComposition: Type { } +"""), + .init(name: "Set.swift", content: +""" +import Foundation + +/// Describes set type +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class SetType: NSObject, SourceryModel, Diffable { + /// Type name used in declaration + public var name: String + + /// Array element type name + public var elementTypeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Array element type, if known + public var elementType: Type? + + /// :nodoc: + public init(name: String, elementTypeName: TypeName, elementType: Type? = nil) { + self.name = name + self.elementTypeName = elementTypeName + self.elementType = elementType + } + + /// Returns array as generic type + public var asGeneric: GenericType { + GenericType(name: "Set", typeParameters: [ + .init(typeName: elementTypeName) + ]) + } + + public var asSource: String { + "[\\(elementTypeName.asSource)]" + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("elementTypeName = \\(String(describing: self.elementTypeName)), ") + string.append("asGeneric = \\(String(describing: self.asGeneric)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? SetType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "elementTypeName").trackDifference(actual: self.elementTypeName, expected: castObject.elementTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.elementTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? SetType else { return false } + if self.name != rhs.name { return false } + if self.elementTypeName != rhs.elementTypeName { return false } + return true + } + +// sourcery:inline:SetType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let elementTypeName: TypeName = aDecoder.decode(forKey: "elementTypeName") else { + withVaList(["elementTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.elementTypeName = elementTypeName + self.elementType = aDecoder.decode(forKey: "elementType") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.elementTypeName, forKey: "elementTypeName") + aCoder.encode(self.elementType, forKey: "elementType") + } +// sourcery:end +} + """), .init(name: "Struct.swift", content: """ @@ -4854,6 +3127,9 @@ import Foundation // sourcery: skipDescription /// Describes Swift struct +#if canImport(ObjectiveC) +@objcMembers +#endif public final class Struct: Type { /// Returns "struct" @@ -4899,6 +3175,7 @@ public final class Struct: Type { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = super.description string += ", " @@ -4916,6 +3193,8 @@ public final class Struct: Type { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(super.hash) @@ -4943,12 +3222,2431 @@ public final class Struct: Type { } """), - .init(name: "Subscript.swift", content: -#""" + .init(name: "TemplateContext.swift", content: +""" +// +// Created by Krzysztof Zablocki on 31/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// + +import Foundation + +/// :nodoc: +// sourcery: skipCoding +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class TemplateContext: NSObject, SourceryModel, NSCoding, Diffable { + // sourcery: skipJSExport + public let parserResult: FileParserResult? + public let functions: [SourceryMethod] + public let types: Types + public let argument: [String: NSObject] + + // sourcery: skipDescription + public var type: [String: Type] { + return types.typesByName + } + + public init(parserResult: FileParserResult?, types: Types, functions: [SourceryMethod], arguments: [String: NSObject]) { + self.parserResult = parserResult + self.types = types + self.functions = functions + self.argument = arguments + } + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let parserResult: FileParserResult = aDecoder.decode(forKey: "parserResult") else { + withVaList(["parserResult"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found. FileParserResults are required for template context that needs persisting.", arguments: arguments) + } + fatalError() + } + guard let argument: [String: NSObject] = aDecoder.decode(forKey: "argument") else { + withVaList(["argument"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + } + + // if we want to support multiple cycles of encode / decode we need deep copy because composer changes reference types + let fileParserResultCopy: FileParserResult? = nil +// fileParserResultCopy = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(NSKeyedArchiver.archivedData(withRootObject: parserResult)) as? FileParserResult + + let composed = Composer.uniqueTypesAndFunctions(parserResult) + self.types = .init(types: composed.types, typealiases: composed.typealiases) + self.functions = composed.functions + + self.parserResult = fileParserResultCopy + self.argument = argument + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.parserResult, forKey: "parserResult") + aCoder.encode(self.argument, forKey: "argument") + } + + public var stencilContext: [String: Any] { + return [ + "types": types, + "functions": functions, + "type": types.typesByName, + "argument": argument + ] + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("parserResult = \\(String(describing: self.parserResult)), ") + string.append("functions = \\(String(describing: self.functions)), ") + string.append("types = \\(String(describing: self.types)), ") + string.append("argument = \\(String(describing: self.argument)), ") + string.append("stencilContext = \\(String(describing: self.stencilContext))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? TemplateContext else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "parserResult").trackDifference(actual: self.parserResult, expected: castObject.parserResult)) + results.append(contentsOf: DiffableResult(identifier: "functions").trackDifference(actual: self.functions, expected: castObject.functions)) + results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) + results.append(contentsOf: DiffableResult(identifier: "argument").trackDifference(actual: self.argument, expected: castObject.argument)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.parserResult) + hasher.combine(self.functions) + hasher.combine(self.types) + hasher.combine(self.argument) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? TemplateContext else { return false } + if self.parserResult != rhs.parserResult { return false } + if self.functions != rhs.functions { return false } + if self.types != rhs.types { return false } + if self.argument != rhs.argument { return false } + return true + } + + // sourcery: skipDescription, skipEquality + public var jsContext: [String: Any] { + return [ + "types": [ + "all": types.all, + "protocols": types.protocols, + "classes": types.classes, + "structs": types.structs, + "enums": types.enums, + "extensions": types.extensions, + "based": types.based, + "inheriting": types.inheriting, + "implementing": types.implementing, + "protocolCompositions": types.protocolCompositions + ] as [String : Any], + "functions": functions, + "type": types.typesByName, + "argument": argument + ] + } + +} + +extension ProcessInfo { + /// :nodoc: + public var context: TemplateContext! { + return NSKeyedUnarchiver.unarchiveObject(withFile: arguments[1]) as? TemplateContext + } +} + +"""), + .init(name: "Typealias.swift", content: +""" +import Foundation + +/// :nodoc: +#if canImport(ObjectiveC) +@objcMembers +#endif +public final class Typealias: NSObject, Typed, SourceryModel, Diffable { + // New typealias name + public let aliasName: String + + // Target name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + public var type: Type? + + /// module in which this typealias was declared + public var module: String? + + /// typealias annotations + public var annotations: Annotations = [:] + + /// typealias documentation + public var documentation: Documentation = [] + + // sourcery: skipEquality, skipDescription + public var parent: Type? { + didSet { + parentName = parent?.name + } + } + + /// Type access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let accessLevel: String + + var parentName: String? + + public var name: String { + if let parentName = parent?.name { + return "\\(module != nil ? "\\(module!)." : "")\\(parentName).\\(aliasName)" + } else { + return "\\(module != nil ? "\\(module!)." : "")\\(aliasName)" + } + } + + public init(aliasName: String = "", typeName: TypeName, accessLevel: AccessLevel = .internal, parent: Type? = nil, module: String? = nil, annotations: [String: NSObject] = [:], documentation: [String] = []) { + self.aliasName = aliasName + self.typeName = typeName + self.accessLevel = accessLevel.rawValue + self.parent = parent + self.parentName = parent?.name + self.module = module + self.annotations = annotations + self.documentation = documentation + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("aliasName = \\(String(describing: self.aliasName)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("module = \\(String(describing: self.module)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("parentName = \\(String(describing: self.parentName)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Typealias else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "aliasName").trackDifference(actual: self.aliasName, expected: castObject.aliasName)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: castObject.module)) + results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) + results.append(contentsOf: DiffableResult(identifier: "parentName").trackDifference(actual: self.parentName, expected: castObject.parentName)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.aliasName) + hasher.combine(self.typeName) + hasher.combine(self.module) + hasher.combine(self.accessLevel) + hasher.combine(self.parentName) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Typealias else { return false } + if self.aliasName != rhs.aliasName { return false } + if self.typeName != rhs.typeName { return false } + if self.module != rhs.module { return false } + if self.accessLevel != rhs.accessLevel { return false } + if self.parentName != rhs.parentName { return false } + if self.documentation != rhs.documentation { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:Typealias.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let aliasName: String = aDecoder.decode(forKey: "aliasName") else { + withVaList(["aliasName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.aliasName = aliasName + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + self.module = aDecoder.decode(forKey: "module") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.parent = aDecoder.decode(forKey: "parent") + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + withVaList(["accessLevel"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.accessLevel = accessLevel + self.parentName = aDecoder.decode(forKey: "parentName") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.aliasName, forKey: "aliasName") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.module, forKey: "module") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.parent, forKey: "parent") + aCoder.encode(self.accessLevel, forKey: "accessLevel") + aCoder.encode(self.parentName, forKey: "parentName") + } +// sourcery:end +} + +"""), + .init(name: "Typed.swift", content: +""" +import Foundation + +/// Descibes typed declaration, i.e. variable, method parameter, tuple element, enum case associated value +public protocol Typed { + + // sourcery: skipEquality, skipDescription + /// Type, if known + var type: Type? { get } + + // sourcery: skipEquality, skipDescription + /// Type name + var typeName: TypeName { get } + + // sourcery: skipEquality, skipDescription + /// Whether type is optional + var isOptional: Bool { get } + + // sourcery: skipEquality, skipDescription + /// Whether type is implicitly unwrapped optional + var isImplicitlyUnwrappedOptional: Bool { get } + + // sourcery: skipEquality, skipDescription + /// Type name without attributes and optional type information + var unwrappedTypeName: String { get } +} + +"""), + .init(name: "AssociatedType_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Describes Swift AssociatedType +public final class AssociatedType: NSObject, SourceryModel, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "name": + return name + case "typeName": + return typeName + case "type": + return type + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Associated type name + public let name: String + + /// Associated type type constraint name, if specified + public let typeName: TypeName? + + // sourcery: skipEquality, skipDescription + /// Associated type constrained type, if known, i.e. if the type is declared in the scanned sources. + public var type: Type? + + /// :nodoc: + public init(name: String, typeName: TypeName? = nil, type: Type? = nil) { + self.name = name + self.typeName = typeName + self.type = type + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? AssociatedType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.typeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? AssociatedType else { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + return true + } + +// sourcery:inline:AssociatedType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.typeName = aDecoder.decode(forKey: "typeName") + self.type = aDecoder.decode(forKey: "type") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + } +// sourcery:end +} +#endif + +"""), + .init(name: "AssociatedValue_Linux.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if !canImport(ObjectiveC) +import Foundation + +/// Defines enum case associated value +public final class AssociatedValue: NSObject, SourceryModel, AutoDescription, Typed, Annotated, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "externalName": + return externalName + case "localName": + return localName + case "typeName": + return typeName + case "type": + return type + case "defaultValue": + return defaultValue + case "annotations": + return annotations + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Associated value local name. + /// This is a name to be used to construct enum case value + public let localName: String? + + /// Associated value external name. + /// This is a name to be used to access value in value-bindig + public let externalName: String? + + /// Associated value type name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Associated value type, if known + public var type: Type? + + /// Associated value default value + public let defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(localName: String?, externalName: String?, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { + self.localName = localName + self.externalName = externalName + self.typeName = typeName + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + } + + convenience init(name: String? = nil, typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:]) { + self.init(localName: name, externalName: name, typeName: typeName, type: type, defaultValue: defaultValue, annotations: annotations) + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("localName = \\(String(describing: self.localName)), ") + string.append("externalName = \\(String(describing: self.externalName)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? AssociatedValue else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "localName").trackDifference(actual: self.localName, expected: castObject.localName)) + results.append(contentsOf: DiffableResult(identifier: "externalName").trackDifference(actual: self.externalName, expected: castObject.externalName)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.localName) + hasher.combine(self.externalName) + hasher.combine(self.typeName) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? AssociatedValue else { return false } + if self.localName != rhs.localName { return false } + if self.externalName != rhs.externalName { return false } + if self.typeName != rhs.typeName { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:AssociatedValue.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.localName = aDecoder.decode(forKey: "localName") + self.externalName = aDecoder.decode(forKey: "externalName") + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.localName, forKey: "localName") + aCoder.encode(self.externalName, forKey: "externalName") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } +// sourcery:end + +} +#endif + +"""), + .init(name: "ClosureParameter_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +// sourcery: skipDiffing +public final class ClosureParameter: NSObject, SourceryModel, Typed, Annotated, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "argumentLabel": + return argumentLabel + case "name": + return name + case "typeName": + return typeName + case "inout": + return `inout` + case "type": + return type + case "isVariadic": + return isVariadic + case "defaultValue": + return defaultValue + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + /// Parameter external name + public var argumentLabel: String? + + /// Parameter internal name + public let name: String? + + /// Parameter type name + public let typeName: TypeName + + /// Parameter flag whether it's inout or not + public let `inout`: Bool + + // sourcery: skipEquality, skipDescription + /// Parameter type, if known + public var type: Type? + + /// Parameter if the argument has a variadic type or not + public let isVariadic: Bool + + /// Parameter type attributes, i.e. `@escaping` + public var typeAttributes: AttributeList { + return typeName.attributes + } + + /// Method parameter default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(argumentLabel: String? = nil, name: String? = nil, typeName: TypeName, type: Type? = nil, + defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, + isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = argumentLabel + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + public var asSource: String { + let typeInfo = "\\(`inout` ? "inout " : "")\\(typeName.asSource)\\(isVariadic ? "..." : "")" + if argumentLabel?.nilIfNotValidParameterName == nil, name?.nilIfNotValidParameterName == nil { + return typeInfo + } + + let typeSuffix = ": \\(typeInfo)" + guard argumentLabel != name else { + return name ?? "" + typeSuffix + } + + let labels = [argumentLabel ?? "_", name?.nilIfEmpty] + .compactMap { $0 } + .joined(separator: " ") + + return (labels.nilIfEmpty ?? "_") + typeSuffix + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.argumentLabel) + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.`inout`) + hasher.combine(self.isVariadic) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("argumentLabel = \\(String(describing: self.argumentLabel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("`inout` = \\(String(describing: self.`inout`)), ") + string.append("typeAttributes = \\(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? ClosureParameter else { return false } + if self.argumentLabel != rhs.argumentLabel { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.`inout` != rhs.`inout` { return false } + if self.isVariadic != rhs.isVariadic { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + + // sourcery:inline:ClosureParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") + self.name = aDecoder.decode(forKey: "name") + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.`inout` = aDecoder.decode(forKey: "`inout`") + self.type = aDecoder.decode(forKey: "type") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.argumentLabel, forKey: "argumentLabel") + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.`inout`, forKey: "`inout`") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.isVariadic, forKey: "isVariadic") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } + + // sourcery:end +} + +extension Array where Element == ClosureParameter { + public var asSource: String { + "(\\(map { $0.asSource }.joined(separator: ", ")))" + } +} +#endif + +"""), + .init(name: "Closure_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Describes closure type +public final class ClosureType: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "name": + return name + case "parameters": + return parameters + case "returnTypeName": + return returnTypeName + case "actualReturnTypeName": + return actualReturnTypeName + case "returnType": + return returnType + case "isOptionalReturnType": + return isOptionalReturnType + case "isImplicitlyUnwrappedOptionalReturnType": + return isImplicitlyUnwrappedOptionalReturnType + case "unwrappedReturnTypeName": + return unwrappedReturnTypeName + case "isAsync": + return isAsync + case "asyncKeyword": + return asyncKeyword + case "throws": + return `throws` + case "throwsOrRethrowsKeyword": + return throwsOrRethrowsKeyword + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + /// Type name used in declaration with stripped whitespaces and new lines + public let name: String + + /// List of closure parameters + public let parameters: [ClosureParameter] + + /// Return value type name + public let returnTypeName: TypeName + + /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` + public var actualReturnTypeName: TypeName { + return returnTypeName.actualTypeName ?? returnTypeName + } + + // sourcery: skipEquality, skipDescription + /// Actual return value type, if known + public var returnType: Type? + + // sourcery: skipEquality, skipDescription + /// Whether return value type is optional + public var isOptionalReturnType: Bool { + return returnTypeName.isOptional + } + + // sourcery: skipEquality, skipDescription + /// Whether return value type is implicitly unwrapped optional + public var isImplicitlyUnwrappedOptionalReturnType: Bool { + return returnTypeName.isImplicitlyUnwrappedOptional + } + + // sourcery: skipEquality, skipDescription + /// Return value type name without attributes and optional type information + public var unwrappedReturnTypeName: String { + return returnTypeName.unwrappedTypeName + } + + /// Whether method is async method + public let isAsync: Bool + + /// async keyword + public let asyncKeyword: String? + + /// Whether closure throws + public let `throws`: Bool + + /// throws or rethrows keyword + public let throwsOrRethrowsKeyword: String? + + /// :nodoc: + public init(name: String, parameters: [ClosureParameter], returnTypeName: TypeName, returnType: Type? = nil, asyncKeyword: String? = nil, throwsOrRethrowsKeyword: String? = nil) { + self.name = name + self.parameters = parameters + self.returnTypeName = returnTypeName + self.returnType = returnType + self.asyncKeyword = asyncKeyword + self.isAsync = asyncKeyword != nil + self.throwsOrRethrowsKeyword = throwsOrRethrowsKeyword + self.`throws` = throwsOrRethrowsKeyword != nil + } + + public var asSource: String { + "\\(parameters.asSource)\\(asyncKeyword != nil ? " \\(asyncKeyword!)" : "")\\(throwsOrRethrowsKeyword != nil ? " \\(throwsOrRethrowsKeyword!)" : "") -> \\(returnTypeName.asSource)" + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("asyncKeyword = \\(String(describing: self.asyncKeyword)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("throwsOrRethrowsKeyword = \\(String(describing: self.throwsOrRethrowsKeyword)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? ClosureType else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) + results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "asyncKeyword").trackDifference(actual: self.asyncKeyword, expected: castObject.asyncKeyword)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "throwsOrRethrowsKeyword").trackDifference(actual: self.throwsOrRethrowsKeyword, expected: castObject.throwsOrRethrowsKeyword)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.parameters) + hasher.combine(self.returnTypeName) + hasher.combine(self.isAsync) + hasher.combine(self.asyncKeyword) + hasher.combine(self.`throws`) + hasher.combine(self.throwsOrRethrowsKeyword) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? ClosureType else { return false } + if self.name != rhs.name { return false } + if self.parameters != rhs.parameters { return false } + if self.returnTypeName != rhs.returnTypeName { return false } + if self.isAsync != rhs.isAsync { return false } + if self.asyncKeyword != rhs.asyncKeyword { return false } + if self.`throws` != rhs.`throws` { return false } + if self.throwsOrRethrowsKeyword != rhs.throwsOrRethrowsKeyword { return false } + return true + } + +// sourcery:inline:ClosureType.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let parameters: [ClosureParameter] = aDecoder.decode(forKey: "parameters") else { + withVaList(["parameters"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.parameters = parameters + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + withVaList(["returnTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.returnTypeName = returnTypeName + self.returnType = aDecoder.decode(forKey: "returnType") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.asyncKeyword = aDecoder.decode(forKey: "asyncKeyword") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.throwsOrRethrowsKeyword = aDecoder.decode(forKey: "throwsOrRethrowsKeyword") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.parameters, forKey: "parameters") + aCoder.encode(self.returnTypeName, forKey: "returnTypeName") + aCoder.encode(self.returnType, forKey: "returnType") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.asyncKeyword, forKey: "asyncKeyword") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.throwsOrRethrowsKeyword, forKey: "throwsOrRethrowsKeyword") + } +// sourcery:end + +} +#endif + +"""), + .init(name: "DynamicMemberLookup_Linux.swift", content: +""" +// +// Stencil +// Copyright © 2022 Stencil +// MIT Licence +// + +#if !canImport(ObjectiveC) +#if canImport(Stencil) +import Stencil +#else +// This is not supposed to work at all, since in Stencil there is a protocol conformance check against `DynamicMemberLookup`, +// and, of course, a substitute with the "same name" but in `Sourcery` will never satisfy that check. +// Here, we are just mimicking `Stencil.DynamicMemberLookup` to showcase what is happening within the `Sourcery` during runtime. + +/// Marker protocol so we can know which types support `@dynamicMemberLookup`. Add this to your own types that support +/// lookup by String. +public protocol DynamicMemberLookup { + /// Get a value for a given `String` key + subscript(dynamicMember member: String) -> Any? { get } +} + +public extension DynamicMemberLookup where Self: RawRepresentable { + /// Get a value for a given `String` key + subscript(dynamicMember member: String) -> Any? { + switch member { + case "rawValue": + return rawValue + default: + return nil + } + } +} +#endif + +public protocol SourceryDynamicMemberLookup: DynamicMemberLookup {} + +#endif + +"""), + .init(name: "EnumCase_Linux.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if !canImport(ObjectiveC) +import Foundation + +/// Defines enum case +public final class EnumCase: NSObject, SourceryModel, AutoDescription, Annotated, Documented, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "name": + return name + case "hasAssociatedValue": + return hasAssociatedValue + case "associatedValues": + return associatedValues + case "indirect": + return indirect + case "annotations": + return annotations + case "rawValue": + return rawValue + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + /// Enum case name + public let name: String + + /// Enum case raw value, if any + public let rawValue: String? + + /// Enum case associated values + public let associatedValues: [AssociatedValue] + + /// Enum case annotations + public var annotations: Annotations = [:] + + public var documentation: Documentation = [] + + /// Whether enum case is indirect + public let indirect: Bool + + /// Whether enum case has associated value + public var hasAssociatedValue: Bool { + return !associatedValues.isEmpty + } + + // Underlying parser data, never to be used by anything else + // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport + /// :nodoc: + public var __parserData: Any? + + /// :nodoc: + public init(name: String, rawValue: String? = nil, associatedValues: [AssociatedValue] = [], annotations: [String: NSObject] = [:], documentation: [String] = [], indirect: Bool = false) { + self.name = name + self.rawValue = rawValue + self.associatedValues = associatedValues + self.annotations = annotations + self.documentation = documentation + self.indirect = indirect + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("rawValue = \\(String(describing: self.rawValue)), ") + string.append("associatedValues = \\(String(describing: self.associatedValues)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("indirect = \\(String(describing: self.indirect)), ") + string.append("hasAssociatedValue = \\(String(describing: self.hasAssociatedValue))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? EnumCase else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "rawValue").trackDifference(actual: self.rawValue, expected: castObject.rawValue)) + results.append(contentsOf: DiffableResult(identifier: "associatedValues").trackDifference(actual: self.associatedValues, expected: castObject.associatedValues)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "indirect").trackDifference(actual: self.indirect, expected: castObject.indirect)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.rawValue) + hasher.combine(self.associatedValues) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.indirect) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? EnumCase else { return false } + if self.name != rhs.name { return false } + if self.rawValue != rhs.rawValue { return false } + if self.associatedValues != rhs.associatedValues { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.indirect != rhs.indirect { return false } + return true + } + +// sourcery:inline:EnumCase.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.rawValue = aDecoder.decode(forKey: "rawValue") + guard let associatedValues: [AssociatedValue] = aDecoder.decode(forKey: "associatedValues") else { + withVaList(["associatedValues"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.associatedValues = associatedValues + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.indirect = aDecoder.decode(forKey: "indirect") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.rawValue, forKey: "rawValue") + aCoder.encode(self.associatedValues, forKey: "associatedValues") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.indirect, forKey: "indirect") + } +// sourcery:end +} +#endif + +"""), + .init(name: "Enum_Linux.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// + +#if !canImport(ObjectiveC) +import Foundation + +/// Defines Swift enum +public final class Enum: Type { + public override subscript(dynamicMember member: String) -> Any? { + switch member { + case "cases": + return cases + case "hasAssociatedValues": + return hasAssociatedValues + default: + return super[dynamicMember: member] + } + } + + // sourcery: skipDescription + /// Returns "enum" + public override var kind: String { return "enum" } + + /// Enum cases + public var cases: [EnumCase] + + /** + Enum raw value type name, if any. This type is removed from enum's `based` and `inherited` types collections. + + - important: Unless raw type is specified explicitly via type alias RawValue it will be set to the first type in the inheritance chain. + So if your enum does not have raw value but implements protocols you'll have to specify conformance to these protocols via extension to get enum with nil raw value type and all based and inherited types. + */ + public var rawTypeName: TypeName? { + didSet { + if let rawTypeName = rawTypeName { + hasRawType = true + if let index = inheritedTypes.firstIndex(of: rawTypeName.name) { + inheritedTypes.remove(at: index) + } + if based[rawTypeName.name] != nil { + based[rawTypeName.name] = nil + } + } else { + hasRawType = false + } + } + } + + // sourcery: skipDescription, skipEquality + /// :nodoc: + public private(set) var hasRawType: Bool + + // sourcery: skipDescription, skipEquality + /// Enum raw value type, if known + public var rawType: Type? + + // sourcery: skipEquality, skipDescription, skipCoding + /// Names of types or protocols this type inherits from, including unknown (not scanned) types + public override var based: [String: String] { + didSet { + if let rawTypeName = rawTypeName, based[rawTypeName.name] != nil { + based[rawTypeName.name] = nil + } + } + } + + /// Whether enum contains any associated values + public var hasAssociatedValues: Bool { + return cases.contains(where: { $0.hasAssociatedValue }) + } + + /// :nodoc: + public init(name: String = "", + parent: Type? = nil, + accessLevel: AccessLevel = .internal, + isExtension: Bool = false, + inheritedTypes: [String] = [], + rawTypeName: TypeName? = nil, + cases: [EnumCase] = [], + variables: [Variable] = [], + methods: [Method] = [], + containedTypes: [Type] = [], + typealiases: [Typealias] = [], + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + isGeneric: Bool = false) { + + self.cases = cases + self.rawTypeName = rawTypeName + self.hasRawType = rawTypeName != nil || !inheritedTypes.isEmpty + + super.init(name: name, parent: parent, accessLevel: accessLevel, isExtension: isExtension, variables: variables, methods: methods, inheritedTypes: inheritedTypes, containedTypes: containedTypes, typealiases: typealiases, attributes: attributes, modifiers: modifiers, annotations: annotations, documentation: documentation, isGeneric: isGeneric) + + if let rawTypeName = rawTypeName?.name, let index = self.inheritedTypes.firstIndex(of: rawTypeName) { + self.inheritedTypes.remove(at: index) + } + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = super.description + string.append(", ") + string.append("cases = \\(String(describing: self.cases)), ") + string.append("rawTypeName = \\(String(describing: self.rawTypeName)), ") + string.append("hasAssociatedValues = \\(String(describing: self.hasAssociatedValues))") + return string + } + + override public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Enum else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "cases").trackDifference(actual: self.cases, expected: castObject.cases)) + results.append(contentsOf: DiffableResult(identifier: "rawTypeName").trackDifference(actual: self.rawTypeName, expected: castObject.rawTypeName)) + results.append(contentsOf: super.diffAgainst(castObject)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.cases) + hasher.combine(self.rawTypeName) + hasher.combine(super.hash) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Enum else { return false } + if self.cases != rhs.cases { return false } + if self.rawTypeName != rhs.rawTypeName { return false } + return super.isEqual(rhs) + } + +// sourcery:inline:Enum.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let cases: [EnumCase] = aDecoder.decode(forKey: "cases") else { + withVaList(["cases"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.cases = cases + self.rawTypeName = aDecoder.decode(forKey: "rawTypeName") + self.hasRawType = aDecoder.decode(forKey: "hasRawType") + self.rawType = aDecoder.decode(forKey: "rawType") + super.init(coder: aDecoder) + } + + /// :nodoc: + override public func encode(with aCoder: NSCoder) { + super.encode(with: aCoder) + aCoder.encode(self.cases, forKey: "cases") + aCoder.encode(self.rawTypeName, forKey: "rawTypeName") + aCoder.encode(self.hasRawType, forKey: "hasRawType") + aCoder.encode(self.rawType, forKey: "rawType") + } +// sourcery:end +} +#endif + +"""), + .init(name: "GenericParameter_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic parameter +public final class GenericParameter: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "name": + return name + case "inheritedTypeName": + return inheritedTypeName + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Generic parameter name + public var name: String + + /// Generic parameter inherited type + public var inheritedTypeName: TypeName? + + /// :nodoc: + public init(name: String, inheritedTypeName: TypeName? = nil) { + self.name = name + self.inheritedTypeName = inheritedTypeName + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("inheritedTypeName = \\(String(describing: self.inheritedTypeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "inheritedTypeName").trackDifference(actual: self.inheritedTypeName, expected: castObject.inheritedTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.inheritedTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericParameter else { return false } + if self.name != rhs.name { return false } + if self.inheritedTypeName != rhs.inheritedTypeName { return false } + return true + } + +// sourcery:inline:GenericParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.inheritedTypeName = aDecoder.decode(forKey: "inheritedTypeName") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.inheritedTypeName, forKey: "inheritedTypeName") + } + +// sourcery:end +} +#endif + +"""), + .init(name: "GenericRequirement_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic requirement +public class GenericRequirement: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "leftType": + return leftType + case "rightType": + return rightType + case "relationship": + return relationship + case "relationshipSyntax": + return relationshipSyntax + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + public enum Relationship: String { + case equals + case conformsTo + + var syntax: String { + switch self { + case .equals: + return "==" + case .conformsTo: + return ":" + } + } + } + + public var leftType: AssociatedType + public let rightType: GenericTypeParameter + + /// relationship name + public let relationship: String + + /// Syntax e.g. `==` or `:` + public let relationshipSyntax: String + + public init(leftType: AssociatedType, rightType: GenericTypeParameter, relationship: Relationship) { + self.leftType = leftType + self.rightType = rightType + self.relationship = relationship.rawValue + self.relationshipSyntax = relationship.syntax + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("leftType = \\(String(describing: self.leftType)), ") + string.append("rightType = \\(String(describing: self.rightType)), ") + string.append("relationship = \\(String(describing: self.relationship)), ") + string.append("relationshipSyntax = \\(String(describing: self.relationshipSyntax))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericRequirement else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "leftType").trackDifference(actual: self.leftType, expected: castObject.leftType)) + results.append(contentsOf: DiffableResult(identifier: "rightType").trackDifference(actual: self.rightType, expected: castObject.rightType)) + results.append(contentsOf: DiffableResult(identifier: "relationship").trackDifference(actual: self.relationship, expected: castObject.relationship)) + results.append(contentsOf: DiffableResult(identifier: "relationshipSyntax").trackDifference(actual: self.relationshipSyntax, expected: castObject.relationshipSyntax)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.leftType) + hasher.combine(self.rightType) + hasher.combine(self.relationship) + hasher.combine(self.relationshipSyntax) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericRequirement else { return false } + if self.leftType != rhs.leftType { return false } + if self.rightType != rhs.rightType { return false } + if self.relationship != rhs.relationship { return false } + if self.relationshipSyntax != rhs.relationshipSyntax { return false } + return true + } + + // sourcery:inline:GenericRequirement.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let leftType: AssociatedType = aDecoder.decode(forKey: "leftType") else { + withVaList(["leftType"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.leftType = leftType + guard let rightType: GenericTypeParameter = aDecoder.decode(forKey: "rightType") else { + withVaList(["rightType"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.rightType = rightType + guard let relationship: String = aDecoder.decode(forKey: "relationship") else { + withVaList(["relationship"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.relationship = relationship + guard let relationshipSyntax: String = aDecoder.decode(forKey: "relationshipSyntax") else { + withVaList(["relationshipSyntax"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.relationshipSyntax = relationshipSyntax + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.leftType, forKey: "leftType") + aCoder.encode(self.rightType, forKey: "rightType") + aCoder.encode(self.relationship, forKey: "relationship") + aCoder.encode(self.relationshipSyntax, forKey: "relationshipSyntax") + } + // sourcery:end +} +#endif + +"""), + .init(name: "GenericTypeParameter_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Descibes Swift generic type parameter +public final class GenericTypeParameter: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "typeName": + return typeName + case "type": + return type + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Generic parameter type name + public var typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Generic parameter type, if known + public var type: Type? + + /// :nodoc: + public init(typeName: TypeName, type: Type? = nil) { + self.typeName = typeName + self.type = type + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("typeName = \\(String(describing: self.typeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? GenericTypeParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.typeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? GenericTypeParameter else { return false } + if self.typeName != rhs.typeName { return false } + return true + } + +// sourcery:inline:GenericTypeParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.type = aDecoder.decode(forKey: "type") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.type, forKey: "type") + } + +// sourcery:end +} +#endif + +"""), + .init(name: "MethodParameter_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// Describes method parameter +public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "argumentLabel": + return argumentLabel + case "name": + return name + case "typeName": + return typeName + case "isClosure": + return isClosure + case "typeAttributes": + return typeAttributes + case "isVariadic": + return isVariadic + case "asSource": + return asSource + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + /// Parameter external name + public var argumentLabel: String? + + // Note: although method parameter can have no name, this property is not optional, + // this is so to maintain compatibility with existing templates. + /// Parameter internal name + public let name: String + + /// Parameter type name + public let typeName: TypeName + + /// Parameter flag whether it's inout or not + public let `inout`: Bool + + /// Is this variadic parameter? + public let isVariadic: Bool + + // sourcery: skipEquality, skipDescription + /// Parameter type, if known + public var type: Type? + + /// Parameter type attributes, i.e. `@escaping` + public var typeAttributes: AttributeList { + return typeName.attributes + } + + /// Method parameter default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + /// :nodoc: + public init(argumentLabel: String?, name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = argumentLabel + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + /// :nodoc: + public init(name: String = "", typeName: TypeName, type: Type? = nil, defaultValue: String? = nil, annotations: [String: NSObject] = [:], isInout: Bool = false, isVariadic: Bool = false) { + self.typeName = typeName + self.argumentLabel = name + self.name = name + self.type = type + self.defaultValue = defaultValue + self.annotations = annotations + self.`inout` = isInout + self.isVariadic = isVariadic + } + + public var asSource: String { + let typeSuffix = ": \\(`inout` ? "inout " : "")\\(typeName.asSource)\\(defaultValue.map { " = \\($0)" } ?? "")" + (isVariadic ? "..." : "") + guard argumentLabel != name else { + return name + typeSuffix + } + + let labels = [argumentLabel ?? "_", name.nilIfEmpty] + .compactMap { $0 } + .joined(separator: " ") + + return (labels.nilIfEmpty ?? "_") + typeSuffix + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("argumentLabel = \\(String(describing: self.argumentLabel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("`inout` = \\(String(describing: self.`inout`)), ") + string.append("isVariadic = \\(String(describing: self.isVariadic)), ") + string.append("typeAttributes = \\(String(describing: self.typeAttributes)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("asSource = \\(String(describing: self.asSource))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? MethodParameter else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "argumentLabel").trackDifference(actual: self.argumentLabel, expected: castObject.argumentLabel)) + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "`inout`").trackDifference(actual: self.`inout`, expected: castObject.`inout`)) + results.append(contentsOf: DiffableResult(identifier: "isVariadic").trackDifference(actual: self.isVariadic, expected: castObject.isVariadic)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.argumentLabel) + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.`inout`) + hasher.combine(self.isVariadic) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? MethodParameter else { return false } + if self.argumentLabel != rhs.argumentLabel { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.`inout` != rhs.`inout` { return false } + if self.isVariadic != rhs.isVariadic { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + return true + } + +// sourcery:inline:MethodParameter.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + self.argumentLabel = aDecoder.decode(forKey: "argumentLabel") + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + withVaList(["typeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typeName = typeName + self.`inout` = aDecoder.decode(forKey: "`inout`") + self.isVariadic = aDecoder.decode(forKey: "isVariadic") + self.type = aDecoder.decode(forKey: "type") + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.argumentLabel, forKey: "argumentLabel") + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.typeName, forKey: "typeName") + aCoder.encode(self.`inout`, forKey: "`inout`") + aCoder.encode(self.isVariadic, forKey: "isVariadic") + aCoder.encode(self.type, forKey: "type") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + } +// sourcery:end +} + +extension Array where Element == MethodParameter { + public var asSource: String { + "(\\(map { $0.asSource }.joined(separator: ", ")))" + } +} +#endif + +"""), + .init(name: "Method_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +/// :nodoc: +public typealias SourceryMethod = Method + +/// Describes method +public final class Method: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "definedInType": + return definedInType + case "shortName": + return shortName + case "name": + return name + case "selectorName": + return selectorName + case "callName": + return callName + case "parameters": + return parameters + case "throws": + return `throws` + case "isInitializer": + return isInitializer + case "accessLevel": + return accessLevel + case "isStatic": + return isStatic + case "returnTypeName": + return returnTypeName + case "isAsync": + return isAsync + case "attributes": + return attributes + case "isOptionalReturnType": + return isOptionalReturnType + case "actualReturnTypeName": + return actualReturnTypeName + case "isDynamic": + return isDynamic + case "genericRequirements": + return genericRequirements + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Full method name, including generic constraints, i.e. `foo(bar: T)` + public let name: String + + /// Method name including arguments names, i.e. `foo(bar:)` + public var selectorName: String + + // sourcery: skipEquality, skipDescription + /// Method name without arguments names and parenthesis, i.e. `foo` + public var shortName: String { + return name.range(of: "(").map({ String(name[..<$0.lowerBound]) }) ?? name + } + + // sourcery: skipEquality, skipDescription + /// Method name without arguments names, parenthesis and generic types, i.e. `foo` (can be used to generate code for method call) + public var callName: String { + return shortName.range(of: "<").map({ String(shortName[..<$0.lowerBound]) }) ?? shortName + } + + /// Method parameters + public var parameters: [MethodParameter] + + /// Return value type name used in declaration, including generic constraints, i.e. `where T: Equatable` + public var returnTypeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Actual return value type name if declaration uses typealias, otherwise just a `returnTypeName` + public var actualReturnTypeName: TypeName { + return returnTypeName.actualTypeName ?? returnTypeName + } + + // sourcery: skipEquality, skipDescription + /// Actual return value type, if known + public var returnType: Type? + + // sourcery: skipEquality, skipDescription + /// Whether return value type is optional + public var isOptionalReturnType: Bool { + return returnTypeName.isOptional || isFailableInitializer + } + + // sourcery: skipEquality, skipDescription + /// Whether return value type is implicitly unwrapped optional + public var isImplicitlyUnwrappedOptionalReturnType: Bool { + return returnTypeName.isImplicitlyUnwrappedOptional + } + + // sourcery: skipEquality, skipDescription + /// Return value type name without attributes and optional type information + public var unwrappedReturnTypeName: String { + return returnTypeName.unwrappedTypeName + } + + /// Whether method is async method + public let isAsync: Bool + + /// Whether method throws + public let `throws`: Bool + + /// Whether method rethrows + public let `rethrows`: Bool + + /// Method access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let accessLevel: String + + /// Whether method is a static method + public let isStatic: Bool + + /// Whether method is a class method + public let isClass: Bool + + // sourcery: skipEquality, skipDescription + /// Whether method is an initializer + public var isInitializer: Bool { + return selectorName.hasPrefix("init(") || selectorName == "init" + } + + // sourcery: skipEquality, skipDescription + /// Whether method is an deinitializer + public var isDeinitializer: Bool { + return selectorName == "deinit" + } + + /// Whether method is a failable initializer + public let isFailableInitializer: Bool + + // sourcery: skipEquality, skipDescription + /// Whether method is a convenience initializer + public var isConvenienceInitializer: Bool { + modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is required + public var isRequired: Bool { + modifiers.contains { $0.name == Attribute.Identifier.required.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is final + public var isFinal: Bool { + modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is mutating + public var isMutating: Bool { + modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is generic + public var isGeneric: Bool { + shortName.hasSuffix(">") + } + + // sourcery: skipEquality, skipDescription + /// Whether method is optional (in an Objective-C protocol) + public var isOptional: Bool { + modifiers.contains { $0.name == Attribute.Identifier.optional.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is nonisolated (this modifier only applies to actor methods) + public var isNonisolated: Bool { + modifiers.contains { $0.name == Attribute.Identifier.nonisolated.rawValue } + } + + // sourcery: skipEquality, skipDescription + /// Whether method is dynamic + public var isDynamic: Bool { + modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } + } + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public let annotations: Annotations + + public let documentation: Documentation + + /// Reference to type name where the method is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc + public let definedInTypeName: TypeName? + + // sourcery: skipEquality, skipDescription + /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` + public var actualDefinedInTypeName: TypeName? { + return definedInTypeName?.actualTypeName ?? definedInTypeName + } + + // sourcery: skipEquality, skipDescription + /// Reference to actual type where the object is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown + public var definedInType: Type? + + /// Method attributes, i.e. `@discardableResult` + public let attributes: AttributeList + + /// Method modifiers, i.e. `private` + public let modifiers: [SourceryModifier] + + // Underlying parser data, never to be used by anything else + // sourcery: skipEquality, skipDescription, skipCoding, skipJSExport + /// :nodoc: + public var __parserData: Any? + + /// list of generic requirements + public var genericRequirements: [GenericRequirement] + + /// :nodoc: + public init(name: String, + selectorName: String? = nil, + parameters: [MethodParameter] = [], + returnTypeName: TypeName = TypeName(name: "Void"), + isAsync: Bool = false, + throws: Bool = false, + rethrows: Bool = false, + accessLevel: AccessLevel = .internal, + isStatic: Bool = false, + isClass: Bool = false, + isFailableInitializer: Bool = false, + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + definedInTypeName: TypeName? = nil, + genericRequirements: [GenericRequirement] = []) { + self.name = name + self.selectorName = selectorName ?? name + self.parameters = parameters + self.returnTypeName = returnTypeName + self.isAsync = isAsync + self.throws = `throws` + self.rethrows = `rethrows` + self.accessLevel = accessLevel.rawValue + self.isStatic = isStatic + self.isClass = isClass + self.isFailableInitializer = isFailableInitializer + self.attributes = attributes + self.modifiers = modifiers + self.annotations = annotations + self.documentation = documentation + self.definedInTypeName = definedInTypeName + self.genericRequirements = genericRequirements + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("selectorName = \\(String(describing: self.selectorName)), ") + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("`rethrows` = \\(String(describing: self.`rethrows`)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("isStatic = \\(String(describing: self.isStatic)), ") + string.append("isClass = \\(String(describing: self.isClass)), ") + string.append("isFailableInitializer = \\(String(describing: self.isFailableInitializer)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers))") + string.append("genericRequirements = \\(String(describing: self.genericRequirements))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Method else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "selectorName").trackDifference(actual: self.selectorName, expected: castObject.selectorName)) + results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) + results.append(contentsOf: DiffableResult(identifier: "returnTypeName").trackDifference(actual: self.returnTypeName, expected: castObject.returnTypeName)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "`rethrows`").trackDifference(actual: self.`rethrows`, expected: castObject.`rethrows`)) + results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) + results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) + results.append(contentsOf: DiffableResult(identifier: "isClass").trackDifference(actual: self.isClass, expected: castObject.isClass)) + results.append(contentsOf: DiffableResult(identifier: "isFailableInitializer").trackDifference(actual: self.isFailableInitializer, expected: castObject.isFailableInitializer)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) + results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) + results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) + results.append(contentsOf: DiffableResult(identifier: "genericRequirements").trackDifference(actual: self.genericRequirements, expected: castObject.genericRequirements)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.selectorName) + hasher.combine(self.parameters) + hasher.combine(self.returnTypeName) + hasher.combine(self.isAsync) + hasher.combine(self.`throws`) + hasher.combine(self.`rethrows`) + hasher.combine(self.accessLevel) + hasher.combine(self.isStatic) + hasher.combine(self.isClass) + hasher.combine(self.isFailableInitializer) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.definedInTypeName) + hasher.combine(self.attributes) + hasher.combine(self.modifiers) + hasher.combine(self.genericRequirements) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Method else { return false } + if self.name != rhs.name { return false } + if self.selectorName != rhs.selectorName { return false } + if self.parameters != rhs.parameters { return false } + if self.returnTypeName != rhs.returnTypeName { return false } + if self.isAsync != rhs.isAsync { return false } + if self.`throws` != rhs.`throws` { return false } + if self.`rethrows` != rhs.`rethrows` { return false } + if self.accessLevel != rhs.accessLevel { return false } + if self.isStatic != rhs.isStatic { return false } + if self.isClass != rhs.isClass { return false } + if self.isFailableInitializer != rhs.isFailableInitializer { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.definedInTypeName != rhs.definedInTypeName { return false } + if self.attributes != rhs.attributes { return false } + if self.modifiers != rhs.modifiers { return false } + if self.genericRequirements != rhs.genericRequirements { return false } + return true + } + +// sourcery:inline:Method.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let selectorName: String = aDecoder.decode(forKey: "selectorName") else { + withVaList(["selectorName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.selectorName = selectorName + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + withVaList(["parameters"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.parameters = parameters + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + withVaList(["returnTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.returnTypeName = returnTypeName + self.returnType = aDecoder.decode(forKey: "returnType") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.`rethrows` = aDecoder.decode(forKey: "`rethrows`") + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + withVaList(["accessLevel"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.accessLevel = accessLevel + self.isStatic = aDecoder.decode(forKey: "isStatic") + self.isClass = aDecoder.decode(forKey: "isClass") + self.isFailableInitializer = aDecoder.decode(forKey: "isFailableInitializer") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") + self.definedInType = aDecoder.decode(forKey: "definedInType") + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + withVaList(["attributes"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.attributes = attributes + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + withVaList(["modifiers"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.modifiers = modifiers + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.selectorName, forKey: "selectorName") + aCoder.encode(self.parameters, forKey: "parameters") + aCoder.encode(self.returnTypeName, forKey: "returnTypeName") + aCoder.encode(self.returnType, forKey: "returnType") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.`rethrows`, forKey: "`rethrows`") + aCoder.encode(self.accessLevel, forKey: "accessLevel") + aCoder.encode(self.isStatic, forKey: "isStatic") + aCoder.encode(self.isClass, forKey: "isClass") + aCoder.encode(self.isFailableInitializer, forKey: "isFailableInitializer") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") + aCoder.encode(self.definedInType, forKey: "definedInType") + aCoder.encode(self.attributes, forKey: "attributes") + aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + } +// sourcery:end +} +#endif + +"""), + .init(name: "NSException_Linux.swift", content: +""" +#if !canImport(ObjectiveC) +import Foundation + +public class NSException { + static func raise(_ name: String, format: String, arguments: CVaListPointer) { + fatalError ("\\(name) exception: \\(NSString(format: format, arguments: arguments))") + } + + static func raise(_ name: String) { + fatalError("\\(name) exception") + } +} + +public extension NSExceptionName { + static var parseErrorException = "parseErrorException" +} +#endif + +"""), + .init(name: "Subscript_Linux.swift", content: +""" +#if !canImport(ObjectiveC) import Foundation /// Describes subscript -public final class Subscript: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable { +public final class Subscript: NSObject, SourceryModel, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { + + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "parameters": + return parameters + case "returnTypeName": + return returnTypeName + case "actualReturnTypeName": + return actualReturnTypeName + case "returnType": + return returnType + case "isOptionalReturnType": + return isOptionalReturnType + case "isImplicitlyUnwrappedOptionalReturnType": + return isImplicitlyUnwrappedOptionalReturnType + case "unwrappedReturnTypeName": + return unwrappedReturnTypeName + case "isFinal": + return isFinal + case "readAccess": + return readAccess + case "writeAccess": + return writeAccess + case "isAsync": + return isAsync + case "throws": + return `throws` + case "isMutable": + return isMutable + case "annotations": + return annotations + case "documentation": + return documentation + case "definedInTypeName": + return definedInTypeName + case "actualDefinedInTypeName": + return actualDefinedInTypeName + case "attributes": + return attributes + case "modifiers": + return modifiers + case "genericParameters": + return genericParameters + case "genericRequirements": + return genericRequirements + case "isGeneric": + return isGeneric + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } /// Method parameters public var parameters: [MethodParameter] @@ -5077,33 +5775,34 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De } /// :nodoc: + // sourcery: skipJSExport override public var description: String { - var string = "\(Swift.type(of: self)): " - string += "parameters = \(String(describing: self.parameters)), " - string += "returnTypeName = \(String(describing: self.returnTypeName)), " - string += "actualReturnTypeName = \(String(describing: self.actualReturnTypeName)), " - string += "isFinal = \(String(describing: self.isFinal)), " - string += "readAccess = \(String(describing: self.readAccess)), " - string += "writeAccess = \(String(describing: self.writeAccess)), " - string += "isAsync = \(String(describing: self.isAsync)), " - string += "`throws` = \(String(describing: self.throws)), " - string += "isMutable = \(String(describing: self.isMutable)), " - string += "annotations = \(String(describing: self.annotations)), " - string += "documentation = \(String(describing: self.documentation)), " - string += "definedInTypeName = \(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \(String(describing: self.actualDefinedInTypeName)), " - string += "genericParameters = \(String(describing: self.genericParameters)), " - string += "genericRequirements = \(String(describing: self.genericRequirements)), " - string += "isGeneric = \(String(describing: self.isGeneric)), " - string += "attributes = \(String(describing: self.attributes)), " - string += "modifiers = \(String(describing: self.modifiers))" + var string = "\\(Swift.type(of: self)): " + string.append("parameters = \\(String(describing: self.parameters)), ") + string.append("returnTypeName = \\(String(describing: self.returnTypeName)), ") + string.append("actualReturnTypeName = \\(String(describing: self.actualReturnTypeName)), ") + string.append("isFinal = \\(String(describing: self.isFinal)), ") + string.append("readAccess = \\(String(describing: self.readAccess)), ") + string.append("writeAccess = \\(String(describing: self.writeAccess)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.throws)), ") + string.append("isMutable = \\(String(describing: self.isMutable)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName)), ") + string.append("genericParameters = \\(String(describing: self.genericParameters)), ") + string.append("genericRequirements = \\(String(describing: self.genericRequirements)), ") + string.append("isGeneric = \\(String(describing: self.isGeneric)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers))") return string } public func diffAgainst(_ object: Any?) -> DiffableResult { let results = DiffableResult() guard let castObject = object as? Subscript else { - results.append("Incorrect type ") + results.append("Incorrect type ") return results } results.append(contentsOf: DiffableResult(identifier: "parameters").trackDifference(actual: self.parameters, expected: castObject.parameters)) @@ -5122,6 +5821,8 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.parameters) @@ -5163,71 +5864,71 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { + guard let parameters: [MethodParameter] = aDecoder.decode(forKey: "parameters") else { withVaList(["parameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.parameters = parameters - guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { + guard let returnTypeName: TypeName = aDecoder.decode(forKey: "returnTypeName") else { withVaList(["returnTypeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.returnTypeName = returnTypeName self.returnType = aDecoder.decode(forKey: "returnType") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { withVaList(["writeAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.writeAccess = writeAccess - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") self.definedInType = aDecoder.decode(forKey: "definedInType") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers - guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { + guard let genericParameters: [GenericParameter] = aDecoder.decode(forKey: "genericParameters") else { withVaList(["genericParameters"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericParameters = genericParameters - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + }; self.genericParameters = genericParameters + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { withVaList(["genericRequirements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.genericRequirements = genericRequirements + }; self.genericRequirements = genericRequirements } /// :nodoc: @@ -5243,422 +5944,32 @@ public final class Subscript: NSObject, SourceryModel, Annotated, Documented, De aCoder.encode(self.documentation, forKey: "documentation") aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") aCoder.encode(self.definedInType, forKey: "definedInType") - aCoder.encode(self.genericParameters, forKey: "genericParameters") - aCoder.encode(self.genericRequirements, forKey: "genericRequirements") aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.genericParameters, forKey: "genericParameters") + aCoder.encode(self.genericRequirements, forKey: "genericRequirements") } // sourcery:end } - -"""#), - .init(name: "TemplateContext.swift", content: -""" -// -// Created by Krzysztof Zablocki on 31/12/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// :nodoc: -// sourcery: skipCoding -public final class TemplateContext: NSObject, SourceryModel, NSCoding, Diffable { - // sourcery: skipJSExport - public let parserResult: FileParserResult? - public let functions: [SourceryMethod] - public let types: Types - public let argument: [String: NSObject] - - // sourcery: skipDescription - public var type: [String: Type] { - return types.typesByName - } - - public init(parserResult: FileParserResult?, types: Types, functions: [SourceryMethod], arguments: [String: NSObject]) { - self.parserResult = parserResult - self.types = types - self.functions = functions - self.argument = arguments - } - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let parserResult: FileParserResult = aDecoder.decode(forKey: "parserResult") else { - withVaList(["parserResult"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found. FileParserResults are required for template context that needs persisting.", arguments: arguments) - } - fatalError() - } - guard let argument: [String: NSObject] = aDecoder.decode(forKey: "argument") else { - withVaList(["argument"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - } - - // if we want to support multiple cycles of encode / decode we need deep copy because composer changes reference types - let fileParserResultCopy: FileParserResult? = nil -// fileParserResultCopy = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(NSKeyedArchiver.archivedData(withRootObject: parserResult)) as? FileParserResult - - let composed = Composer.uniqueTypesAndFunctions(parserResult) - self.types = .init(types: composed.types, typealiases: composed.typealiases) - self.functions = composed.functions - - self.parserResult = fileParserResultCopy - self.argument = argument - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.parserResult, forKey: "parserResult") - aCoder.encode(self.argument, forKey: "argument") - } - - public var stencilContext: [String: Any] { - return [ - "types": types, - "functions": functions, - "type": types.typesByName, - "argument": argument - ] - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "parserResult = \\(String(describing: self.parserResult)), " - string += "functions = \\(String(describing: self.functions)), " - string += "types = \\(String(describing: self.types)), " - string += "argument = \\(String(describing: self.argument)), " - string += "stencilContext = \\(String(describing: self.stencilContext))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? TemplateContext else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "parserResult").trackDifference(actual: self.parserResult, expected: castObject.parserResult)) - results.append(contentsOf: DiffableResult(identifier: "functions").trackDifference(actual: self.functions, expected: castObject.functions)) - results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) - results.append(contentsOf: DiffableResult(identifier: "argument").trackDifference(actual: self.argument, expected: castObject.argument)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.parserResult) - hasher.combine(self.functions) - hasher.combine(self.types) - hasher.combine(self.argument) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? TemplateContext else { return false } - if self.parserResult != rhs.parserResult { return false } - if self.functions != rhs.functions { return false } - if self.types != rhs.types { return false } - if self.argument != rhs.argument { return false } - return true - } - - // sourcery: skipDescription, skipEquality - public var jsContext: [String: Any] { - return [ - "types": [ - "all": types.all, - "protocols": types.protocols, - "classes": types.classes, - "structs": types.structs, - "enums": types.enums, - "extensions": types.extensions, - "based": types.based, - "inheriting": types.inheriting, - "implementing": types.implementing - ] as [String : Any], - "functions": functions, - "type": types.typesByName, - "argument": argument - ] - } - -} - -extension ProcessInfo { - /// :nodoc: - public var context: TemplateContext! { - return NSKeyedUnarchiver.unarchiveObject(withFile: arguments[1]) as? TemplateContext - } -} +#endif """), - .init(name: "Types.swift", content: -""" -import Foundation - -// sourcery: skipJSExport -/// Collection of scanned types for accessing in templates -public final class Types: NSObject, SourceryModel, Diffable { - - /// :nodoc: - public let types: [Type] - - /// All known typealiases - public let typealiases: [Typealias] - - /// :nodoc: - public init(types: [Type], typealiases: [Typealias] = []) { - self.types = types - self.typealiases = typealiases - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "types = \\(String(describing: self.types)), " - string += "typealiases = \\(String(describing: self.typealiases))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Types else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) - results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: castObject.typealiases)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.types) - hasher.combine(self.typealiases) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Types else { return false } - if self.types != rhs.types { return false } - if self.typealiases != rhs.typealiases { return false } - return true - } - -// sourcery:inline:Types.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let types: [Type] = aDecoder.decode(forKey: "types") else { - withVaList(["types"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.types = types - guard let typealiases: [Typealias] = aDecoder.decode(forKey: "typealiases") else { - withVaList(["typealiases"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typealiases = typealiases - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.types, forKey: "types") - aCoder.encode(self.typealiases, forKey: "typealiases") - } -// sourcery:end - - // sourcery: skipDescription, skipEquality, skipCoding - /// :nodoc: - public lazy internal(set) var typesByName: [String: Type] = { - var typesByName = [String: Type]() - self.types.forEach { typesByName[$0.globalName] = $0 } - return typesByName - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// :nodoc: - public lazy internal(set) var typesaliasesByName: [String: Typealias] = { - var typesaliasesByName = [String: Typealias]() - self.typealiases.forEach { typesaliasesByName[$0.name] = $0 } - return typesaliasesByName - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known types, excluding protocols or protocol compositions. - public lazy internal(set) var all: [Type] = { - return self.types.filter { !($0 is Protocol || $0 is ProtocolComposition) } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known protocols - public lazy internal(set) var protocols: [Protocol] = { - return self.types.compactMap { $0 as? Protocol } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known protocol compositions - public lazy internal(set) var protocolCompositions: [ProtocolComposition] = { - return self.types.compactMap { $0 as? ProtocolComposition } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known classes - public lazy internal(set) var classes: [Class] = { - return self.all.compactMap { $0 as? Class } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known structs - public lazy internal(set) var structs: [Struct] = { - return self.all.compactMap { $0 as? Struct } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known enums - public lazy internal(set) var enums: [Enum] = { - return self.all.compactMap { $0 as? Enum } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// All known extensions - public lazy internal(set) var extensions: [Type] = { - return self.all.compactMap { $0.isExtension ? $0 : nil } - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Types based on any other type, grouped by its name, even if they are not known. - /// `types.based.MyType` returns list of types based on `MyType` - public lazy internal(set) var based: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.based.keys) } - ) - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Classes inheriting from any known class, grouped by its name. - /// `types.inheriting.MyClass` returns list of types inheriting from `MyClass` - public lazy internal(set) var inheriting: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.inherits.keys) }, - validate: { type in - guard type is Class else { - throw "\\(type.name) is not a class and should be used with `implementing` or `based`" - } - }) - }() - - // sourcery: skipDescription, skipEquality, skipCoding - /// Types implementing known protocol, grouped by its name. - /// `types.implementing.MyProtocol` returns list of types implementing `MyProtocol` - public lazy internal(set) var implementing: TypesCollection = { - TypesCollection( - types: self.types, - collection: { Array($0.implements.keys) }, - validate: { type in - guard type is Protocol else { - throw "\\(type.name) is a class and should be used with `inheriting` or `based`" - } - }) - }() -} - -"""), - .init(name: "TypesCollection.swift", content: -""" -import Foundation - -/// :nodoc: -public class TypesCollection: NSObject, AutoJSExport { - - // sourcery:begin: skipJSExport - let all: [Type] - let types: [String: [Type]] - let validate: ((Type) throws -> Void)? - // sourcery:end - - init(types: [Type], collection: (Type) -> [String], validate: ((Type) throws -> Void)? = nil) { - self.all = types - var content = [String: [Type]]() - self.all.forEach { type in - collection(type).forEach { name in - var list = content[name] ?? [Type]() - list.append(type) - content[name] = list - } - } - self.types = content - self.validate = validate - } - - public func types(forKey key: String) throws -> [Type] { - // In some configurations, the types are keyed by "ModuleName.TypeName" - var longKey: String? - - if let validate = validate { - guard let type = all.first(where: { $0.name == key }) else { - throw "Unknown type \\(key), should be used with `based`" - } - - try validate(type) - - if let module = type.module { - longKey = [module, type.name].joined(separator: ".") - } - } - - // If we find the types directly, return them - if let types = types[key] { - return types - } - - // if we find a types for the longKey, return them - if let longKey = longKey, let types = types[longKey] { - return types - } - - return [] - } - - /// :nodoc: - public func value(forKey key: String) -> Any? { - do { - return try types(forKey: key) - } catch { - Log.error(error) - return nil - } - } - - /// :nodoc: - public subscript(_ key: String) -> [Type] { - do { - return try types(forKey: key) - } catch { - Log.error(error) - return [] - } - } -} - -"""), - .init(name: "Tuple.swift", content: + .init(name: "Tuple_Linux.swift", content: """ +#if !canImport(ObjectiveC) import Foundation /// Describes tuple type -public final class TupleType: NSObject, SourceryModel, Diffable { +public final class TupleType: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "elements": + return elements + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } /// Type name used in declaration public var name: String @@ -5679,10 +5990,11 @@ public final class TupleType: NSObject, SourceryModel, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "elements = \\(String(describing: self.elements))" + string.append("name = \\(String(describing: self.name)), ") + string.append("elements = \\(String(describing: self.elements))") return string } @@ -5697,6 +6009,8 @@ public final class TupleType: NSObject, SourceryModel, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -5716,13 +6030,13 @@ public final class TupleType: NSObject, SourceryModel, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { + guard let name: String = aDecoder.decode(forKey: "name") else { withVaList(["name"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.name = name - guard let elements: [TupleElement] = aDecoder.decode(forKey: "elements") else { + guard let elements: [TupleElement] = aDecoder.decode(forKey: "elements") else { withVaList(["elements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -5739,7 +6053,19 @@ public final class TupleType: NSObject, SourceryModel, Diffable { } /// Describes tuple type element -public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { +public final class TupleElement: NSObject, SourceryModel, Typed, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "name": + return name + case "typeName": + return typeName + case "type": + return type + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } /// Tuple element name public let name: String? @@ -5764,11 +6090,12 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "asSource = \\(String(describing: self.asSource))" + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("asSource = \\(String(describing: self.asSource))") return string } @@ -5783,6 +6110,8 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.name) @@ -5803,7 +6132,7 @@ public final class TupleElement: NSObject, SourceryModel, Typed, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.name = aDecoder.decode(forKey: "name") - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -5830,22 +6159,364 @@ extension Array where Element == TupleElement { "(\\(map { $0.typeName.asSource }.joined(separator: ", ")))" } } +#endif """), - .init(name: "Type.swift", content: + .init(name: "TypeName_Linux.swift", content: +""" +// +// Created by Krzysztof Zabłocki on 25/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if !canImport(ObjectiveC) +import Foundation + +/// Describes name of the type used in typed declaration (variable, method parameter or return value etc.) +public final class TypeName: NSObject, SourceryModelWithoutDescription, LosslessStringConvertible, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "tuple": + return tuple + case "name": + return name + case "isOptional": + return isOptional + case "unwrappedTypeName": + return unwrappedTypeName + case "isProtocolComposition": + return isProtocolComposition + case "isVoid": + return isVoid + case "isClosure": + return isClosure + case "closure": + return closure + case "set": + return set + case "isSet": + return isSet + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// :nodoc: + public init(name: String, + actualTypeName: TypeName? = nil, + unwrappedTypeName: String? = nil, + attributes: AttributeList = [:], + isOptional: Bool = false, + isImplicitlyUnwrappedOptional: Bool = false, + tuple: TupleType? = nil, + array: ArrayType? = nil, + dictionary: DictionaryType? = nil, + closure: ClosureType? = nil, + set: SetType? = nil, + generic: GenericType? = nil, + isProtocolComposition: Bool = false) { + + let optionalSuffix: String + // TODO: TBR + if !name.hasPrefix("Optional<") && !name.contains(" where ") { + if isOptional { + optionalSuffix = "?" + } else if isImplicitlyUnwrappedOptional { + optionalSuffix = "!" + } else { + optionalSuffix = "" + } + } else { + optionalSuffix = "" + } + + self.name = name + optionalSuffix + self.actualTypeName = actualTypeName + self.unwrappedTypeName = unwrappedTypeName ?? name + self.tuple = tuple + self.array = array + self.dictionary = dictionary + self.closure = closure + self.generic = generic + self.isOptional = isOptional || isImplicitlyUnwrappedOptional + self.isImplicitlyUnwrappedOptional = isImplicitlyUnwrappedOptional + self.isProtocolComposition = isProtocolComposition + self.set = set + self.attributes = attributes + self.modifiers = [] + super.init() + } + + /// Type name used in declaration + public var name: String + + /// The generics of this TypeName + public var generic: GenericType? + + /// Whether this TypeName is generic + public var isGeneric: Bool { + actualTypeName?.generic != nil || generic != nil + } + + /// Whether this TypeName is protocol composition + public var isProtocolComposition: Bool + + // sourcery: skipEquality + /// Actual type name if given type name is a typealias + public var actualTypeName: TypeName? + + /// Type name attributes, i.e. `@escaping` + public var attributes: AttributeList + + /// Modifiers, i.e. `escaping` + public var modifiers: [SourceryModifier] + + // sourcery: skipEquality + /// Whether type is optional + public let isOptional: Bool + + // sourcery: skipEquality + /// Whether type is implicitly unwrapped optional + public let isImplicitlyUnwrappedOptional: Bool + + // sourcery: skipEquality + /// Type name without attributes and optional type information + public var unwrappedTypeName: String + + // sourcery: skipEquality + /// Whether type is void (`Void` or `()`) + public var isVoid: Bool { + return name == "Void" || name == "()" || unwrappedTypeName == "Void" + } + + /// Whether type is a tuple + public var isTuple: Bool { + actualTypeName?.tuple != nil || tuple != nil + } + + /// Tuple type data + public var tuple: TupleType? + + /// Whether type is an array + public var isArray: Bool { + actualTypeName?.array != nil || array != nil + } + + /// Array type data + public var array: ArrayType? + + /// Whether type is a dictionary + public var isDictionary: Bool { + actualTypeName?.dictionary != nil || dictionary != nil + } + + /// Dictionary type data + public var dictionary: DictionaryType? + + /// Whether type is a closure + public var isClosure: Bool { + actualTypeName?.closure != nil || closure != nil + } + + /// Closure type data + public var closure: ClosureType? + + /// Whether type is a Set + public var isSet: Bool { + actualTypeName?.set != nil || set != nil + } + + /// Set type data + public var set: SetType? + + /// Prints typename as it would appear on definition + public var asSource: String { + // TODO: TBR special treatment + let specialTreatment = isOptional && name.hasPrefix("Optional<") + + var description = ( + attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + + modifiers.map({ $0.asSource }) + + [specialTreatment ? name : unwrappedTypeName] + ).joined(separator: " ") + + if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name +// description.append(dictionary.asSource) + } else if let _ = self.array { +// description.append(array.asSource) + } else if let _ = self.generic { +// let arguments = generic.typeParameters +// .map({ $0.typeName.asSource }) +// .joined(separator: ", ") +// description.append("<\\(arguments)>") + } + if !specialTreatment { + if isImplicitlyUnwrappedOptional { + description.append("!") + } else if isOptional { + description.append("?") + } + } + + return description + } + + public override var description: String { + ( + attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + + modifiers.map({ $0.asSource }) + + [name] + ).joined(separator: " ") + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? TypeName else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "generic").trackDifference(actual: self.generic, expected: castObject.generic)) + results.append(contentsOf: DiffableResult(identifier: "isProtocolComposition").trackDifference(actual: self.isProtocolComposition, expected: castObject.isProtocolComposition)) + results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) + results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) + results.append(contentsOf: DiffableResult(identifier: "tuple").trackDifference(actual: self.tuple, expected: castObject.tuple)) + results.append(contentsOf: DiffableResult(identifier: "array").trackDifference(actual: self.array, expected: castObject.array)) + results.append(contentsOf: DiffableResult(identifier: "dictionary").trackDifference(actual: self.dictionary, expected: castObject.dictionary)) + results.append(contentsOf: DiffableResult(identifier: "closure").trackDifference(actual: self.closure, expected: castObject.closure)) + results.append(contentsOf: DiffableResult(identifier: "set").trackDifference(actual: self.set, expected: castObject.set)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.generic) + hasher.combine(self.isProtocolComposition) + hasher.combine(self.attributes) + hasher.combine(self.modifiers) + hasher.combine(self.tuple) + hasher.combine(self.array) + hasher.combine(self.dictionary) + hasher.combine(self.closure) + hasher.combine(self.set) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? TypeName else { return false } + if self.name != rhs.name { return false } + if self.generic != rhs.generic { return false } + if self.isProtocolComposition != rhs.isProtocolComposition { return false } + if self.attributes != rhs.attributes { return false } + if self.modifiers != rhs.modifiers { return false } + if self.tuple != rhs.tuple { return false } + if self.array != rhs.array { return false } + if self.dictionary != rhs.dictionary { return false } + if self.closure != rhs.closure { return false } + if self.set != rhs.set { return false } + return true + } + +// sourcery:inline:TypeName.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + self.generic = aDecoder.decode(forKey: "generic") + self.isProtocolComposition = aDecoder.decode(forKey: "isProtocolComposition") + self.actualTypeName = aDecoder.decode(forKey: "actualTypeName") + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + withVaList(["attributes"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.attributes = attributes + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + withVaList(["modifiers"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.modifiers = modifiers + self.isOptional = aDecoder.decode(forKey: "isOptional") + self.isImplicitlyUnwrappedOptional = aDecoder.decode(forKey: "isImplicitlyUnwrappedOptional") + guard let unwrappedTypeName: String = aDecoder.decode(forKey: "unwrappedTypeName") else { + withVaList(["unwrappedTypeName"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.unwrappedTypeName = unwrappedTypeName + self.tuple = aDecoder.decode(forKey: "tuple") + self.array = aDecoder.decode(forKey: "array") + self.dictionary = aDecoder.decode(forKey: "dictionary") + self.closure = aDecoder.decode(forKey: "closure") + self.set = aDecoder.decode(forKey: "set") + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.name, forKey: "name") + aCoder.encode(self.generic, forKey: "generic") + aCoder.encode(self.isProtocolComposition, forKey: "isProtocolComposition") + aCoder.encode(self.actualTypeName, forKey: "actualTypeName") + aCoder.encode(self.attributes, forKey: "attributes") + aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.isOptional, forKey: "isOptional") + aCoder.encode(self.isImplicitlyUnwrappedOptional, forKey: "isImplicitlyUnwrappedOptional") + aCoder.encode(self.unwrappedTypeName, forKey: "unwrappedTypeName") + aCoder.encode(self.tuple, forKey: "tuple") + aCoder.encode(self.array, forKey: "array") + aCoder.encode(self.dictionary, forKey: "dictionary") + aCoder.encode(self.closure, forKey: "closure") + aCoder.encode(self.set, forKey: "set") + } +// sourcery:end + + // sourcery: skipEquality, skipDescription + /// :nodoc: + public override var debugDescription: String { + return name + } + + public convenience init(_ description: String) { + self.init(name: description, actualTypeName: nil) + } +} + +extension TypeName { + public static func unknown(description: String?, attributes: AttributeList = [:]) -> TypeName { + if let description = description { + Log.astWarning("Unknown type, please add type attribution to \\(description)") + } else { + Log.astWarning("Unknown type, please add type attribution") + } + return TypeName(name: "UnknownTypeSoAddTypeAttributionToVariable", attributes: attributes) + } +} +#endif + +"""), + .init(name: "Type_Linux.swift", content: """ // // Created by Krzysztof Zablocki on 11/09/2016. // Copyright (c) 2016 Pixle. All rights reserved. // - +#if !canImport(ObjectiveC) import Foundation /// :nodoc: public typealias AttributeList = [String: [Attribute]] /// Defines Swift type -public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { +public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable, SourceryDynamicMemberLookup { public subscript(dynamicMember member: String) -> Any? { switch member { case "implements": @@ -5890,7 +6561,7 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { return genericRequirements default: fatalError("unable to lookup: \\(member) in \\(self)") - } + } } /// :nodoc: @@ -6305,41 +6976,42 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { } /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "module = \\(String(describing: self.module)), " - string += "imports = \\(String(describing: self.imports)), " - string += "allImports = \\(String(describing: self.allImports)), " - string += "typealiases = \\(String(describing: self.typealiases)), " - string += "isExtension = \\(String(describing: self.isExtension)), " - string += "kind = \\(String(describing: self.kind)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "name = \\(String(describing: self.name)), " - string += "isUnknownExtension = \\(String(describing: self.isUnknownExtension)), " - string += "isGeneric = \\(String(describing: self.isGeneric)), " - string += "localName = \\(String(describing: self.localName)), " - string += "rawVariables = \\(String(describing: self.rawVariables)), " - string += "rawMethods = \\(String(describing: self.rawMethods)), " - string += "rawSubscripts = \\(String(describing: self.rawSubscripts)), " - string += "initializers = \\(String(describing: self.initializers)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "staticVariables = \\(String(describing: self.staticVariables)), " - string += "staticMethods = \\(String(describing: self.staticMethods)), " - string += "classMethods = \\(String(describing: self.classMethods)), " - string += "instanceVariables = \\(String(describing: self.instanceVariables)), " - string += "instanceMethods = \\(String(describing: self.instanceMethods)), " - string += "computedVariables = \\(String(describing: self.computedVariables)), " - string += "storedVariables = \\(String(describing: self.storedVariables)), " - string += "inheritedTypes = \\(String(describing: self.inheritedTypes)), " - string += "inherits = \\(String(describing: self.inherits)), " - string += "containedTypes = \\(String(describing: self.containedTypes)), " - string += "parentName = \\(String(describing: self.parentName)), " - string += "parentTypes = \\(String(describing: self.parentTypes)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers)), " - string += "fileName = \\(String(describing: self.fileName)), " - string += "genericRequirements = \\(String(describing: self.genericRequirements))" + string.append("module = \\(String(describing: self.module)), ") + string.append("imports = \\(String(describing: self.imports)), ") + string.append("allImports = \\(String(describing: self.allImports)), ") + string.append("typealiases = \\(String(describing: self.typealiases)), ") + string.append("isExtension = \\(String(describing: self.isExtension)), ") + string.append("kind = \\(String(describing: self.kind)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("name = \\(String(describing: self.name)), ") + string.append("isUnknownExtension = \\(String(describing: self.isUnknownExtension)), ") + string.append("isGeneric = \\(String(describing: self.isGeneric)), ") + string.append("localName = \\(String(describing: self.localName)), ") + string.append("rawVariables = \\(String(describing: self.rawVariables)), ") + string.append("rawMethods = \\(String(describing: self.rawMethods)), ") + string.append("rawSubscripts = \\(String(describing: self.rawSubscripts)), ") + string.append("initializers = \\(String(describing: self.initializers)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("staticVariables = \\(String(describing: self.staticVariables)), ") + string.append("staticMethods = \\(String(describing: self.staticMethods)), ") + string.append("classMethods = \\(String(describing: self.classMethods)), ") + string.append("instanceVariables = \\(String(describing: self.instanceVariables)), ") + string.append("instanceMethods = \\(String(describing: self.instanceMethods)), ") + string.append("computedVariables = \\(String(describing: self.computedVariables)), ") + string.append("storedVariables = \\(String(describing: self.storedVariables)), ") + string.append("inheritedTypes = \\(String(describing: self.inheritedTypes)), ") + string.append("inherits = \\(String(describing: self.inherits)), ") + string.append("containedTypes = \\(String(describing: self.containedTypes)), ") + string.append("parentName = \\(String(describing: self.parentName)), ") + string.append("parentTypes = \\(String(describing: self.parentTypes)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers)), ") + string.append("fileName = \\(String(describing: self.fileName)), ") + string.append("genericRequirements = \\(String(describing: self.genericRequirements))") return string } @@ -6373,6 +7045,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() hasher.combine(self.module) @@ -6433,51 +7107,45 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { /// :nodoc: required public init?(coder aDecoder: NSCoder) { self.module = aDecoder.decode(forKey: "module") - guard let imports: [Import] = aDecoder.decode(forKey: "imports") else { + guard let imports: [Import] = aDecoder.decode(forKey: "imports") else { withVaList(["imports"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.imports = imports - guard let typealiases: [String: Typealias] = aDecoder.decode(forKey: "typealiases") else { + guard let typealiases: [String: Typealias] = aDecoder.decode(forKey: "typealiases") else { withVaList(["typealiases"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.typealiases = typealiases self.isExtension = aDecoder.decode(forKey: "isExtension") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { + guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { withVaList(["accessLevel"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.accessLevel = accessLevel self.isGeneric = aDecoder.decode(forKey: "isGeneric") - guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { - withVaList(["genericRequirements"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.genericRequirements = genericRequirements - guard let localName: String = aDecoder.decode(forKey: "localName") else { + guard let localName: String = aDecoder.decode(forKey: "localName") else { withVaList(["localName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.localName = localName - guard let rawVariables: [Variable] = aDecoder.decode(forKey: "rawVariables") else { + guard let rawVariables: [Variable] = aDecoder.decode(forKey: "rawVariables") else { withVaList(["rawVariables"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.rawVariables = rawVariables - guard let rawMethods: [Method] = aDecoder.decode(forKey: "rawMethods") else { + guard let rawMethods: [Method] = aDecoder.decode(forKey: "rawMethods") else { withVaList(["rawMethods"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.rawMethods = rawMethods - guard let rawSubscripts: [Subscript] = aDecoder.decode(forKey: "rawSubscripts") else { + guard let rawSubscripts: [Subscript] = aDecoder.decode(forKey: "rawSubscripts") else { withVaList(["rawSubscripts"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -6485,55 +7153,55 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { }; self.rawSubscripts = rawSubscripts self.bodyBytesRange = aDecoder.decode(forKey: "bodyBytesRange") self.completeDeclarationRange = aDecoder.decode(forKey: "completeDeclarationRange") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { withVaList(["annotations"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { withVaList(["documentation"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.documentation = documentation - guard let inheritedTypes: [String] = aDecoder.decode(forKey: "inheritedTypes") else { + guard let inheritedTypes: [String] = aDecoder.decode(forKey: "inheritedTypes") else { withVaList(["inheritedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.inheritedTypes = inheritedTypes - guard let based: [String: String] = aDecoder.decode(forKey: "based") else { + guard let based: [String: String] = aDecoder.decode(forKey: "based") else { withVaList(["based"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.based = based - guard let basedTypes: [String: Type] = aDecoder.decode(forKey: "basedTypes") else { + guard let basedTypes: [String: Type] = aDecoder.decode(forKey: "basedTypes") else { withVaList(["basedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.basedTypes = basedTypes - guard let inherits: [String: Type] = aDecoder.decode(forKey: "inherits") else { + guard let inherits: [String: Type] = aDecoder.decode(forKey: "inherits") else { withVaList(["inherits"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.inherits = inherits - guard let implements: [String: Type] = aDecoder.decode(forKey: "implements") else { + guard let implements: [String: Type] = aDecoder.decode(forKey: "implements") else { withVaList(["implements"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.implements = implements - guard let containedTypes: [Type] = aDecoder.decode(forKey: "containedTypes") else { + guard let containedTypes: [Type] = aDecoder.decode(forKey: "containedTypes") else { withVaList(["containedTypes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.containedTypes = containedTypes - guard let containedType: [String: Type] = aDecoder.decode(forKey: "containedType") else { + guard let containedType: [String: Type] = aDecoder.decode(forKey: "containedType") else { withVaList(["containedType"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } @@ -6542,19 +7210,25 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { self.parentName = aDecoder.decode(forKey: "parentName") self.parent = aDecoder.decode(forKey: "parent") self.supertype = aDecoder.decode(forKey: "supertype") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { withVaList(["attributes"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { withVaList(["modifiers"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.modifiers = modifiers self.path = aDecoder.decode(forKey: "path") + guard let genericRequirements: [GenericRequirement] = aDecoder.decode(forKey: "genericRequirements") else { + withVaList(["genericRequirements"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.genericRequirements = genericRequirements self.fileName = aDecoder.decode(forKey: "fileName") } @@ -6587,8 +7261,8 @@ public class Type: NSObject, SourceryModel, Annotated, Documented, Diffable { aCoder.encode(self.attributes, forKey: "attributes") aCoder.encode(self.modifiers, forKey: "modifiers") aCoder.encode(self.path, forKey: "path") - aCoder.encode(self.fileName, forKey: "fileName") aCoder.encode(self.genericRequirements, forKey: "genericRequirements") + aCoder.encode(self.fileName, forKey: "fileName") } // sourcery:end @@ -6603,460 +7277,1504 @@ extension Type { return !isNotClass && !isExtension } } +#endif """), - .init(name: "TypeName.swift", content: + .init(name: "TypesCollection_Linux.swift", content: """ // -// Created by Krzysztof Zabłocki on 25/12/2016. +// Created by Krzysztof Zablocki on 31/12/2016. // Copyright (c) 2016 Pixle. All rights reserved. // - +#if !canImport(ObjectiveC) import Foundation -/// Describes name of the type used in typed declaration (variable, method parameter or return value etc.) -public final class TypeName: NSObject, SourceryModelWithoutDescription, LosslessStringConvertible, Diffable { +/// :nodoc: +public class TypesCollection: NSObject, AutoJSExport, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + return try? types(forKey: member) + } - /// :nodoc: - public init(name: String, - actualTypeName: TypeName? = nil, - unwrappedTypeName: String? = nil, - attributes: AttributeList = [:], - isOptional: Bool = false, - isImplicitlyUnwrappedOptional: Bool = false, - tuple: TupleType? = nil, - array: ArrayType? = nil, - dictionary: DictionaryType? = nil, - closure: ClosureType? = nil, - set: SetType? = nil, - generic: GenericType? = nil, - isProtocolComposition: Bool = false) { + // sourcery:begin: skipJSExport + let all: [Type] + let types: [String: [Type]] + let validate: ((Type) throws -> Void)? + // sourcery:end - let optionalSuffix: String - // TODO: TBR - if !name.hasPrefix("Optional<") && !name.contains(" where ") { - if isOptional { - optionalSuffix = "?" - } else if isImplicitlyUnwrappedOptional { - optionalSuffix = "!" - } else { - optionalSuffix = "" + init(types: [Type], collection: (Type) -> [String], validate: ((Type) throws -> Void)? = nil) { + self.all = types + var content = [String: [Type]]() + self.all.forEach { type in + collection(type).forEach { name in + var list = content[name] ?? [Type]() + list.append(type) + content[name] = list } - } else { - optionalSuffix = "" } - - self.name = name + optionalSuffix - self.actualTypeName = actualTypeName - self.unwrappedTypeName = unwrappedTypeName ?? name - self.tuple = tuple - self.array = array - self.dictionary = dictionary - self.closure = closure - self.generic = generic - self.isOptional = isOptional || isImplicitlyUnwrappedOptional - self.isImplicitlyUnwrappedOptional = isImplicitlyUnwrappedOptional - self.isProtocolComposition = isProtocolComposition - self.set = set - self.attributes = attributes - self.modifiers = [] - super.init() + self.types = content + self.validate = validate } - /// Type name used in declaration - public var name: String + public func types(forKey key: String) throws -> [Type] { + // In some configurations, the types are keyed by "ModuleName.TypeName" + var longKey: String? - /// The generics of this TypeName - public var generic: GenericType? + if let validate = validate { + guard let type = all.first(where: { $0.name == key }) else { + throw "Unknown type \\(key), should be used with `based`" + } - /// Whether this TypeName is generic - public var isGeneric: Bool { - actualTypeName?.generic != nil || generic != nil - } + try validate(type) - /// Whether this TypeName is protocol composition - public var isProtocolComposition: Bool - - // sourcery: skipEquality - /// Actual type name if given type name is a typealias - public var actualTypeName: TypeName? - - /// Type name attributes, i.e. `@escaping` - public var attributes: AttributeList - - /// Modifiers, i.e. `escaping` - public var modifiers: [SourceryModifier] - - // sourcery: skipEquality - /// Whether type is optional - public let isOptional: Bool - - // sourcery: skipEquality - /// Whether type is implicitly unwrapped optional - public let isImplicitlyUnwrappedOptional: Bool - - // sourcery: skipEquality - /// Type name without attributes and optional type information - public var unwrappedTypeName: String - - // sourcery: skipEquality - /// Whether type is void (`Void` or `()`) - public var isVoid: Bool { - return name == "Void" || name == "()" || unwrappedTypeName == "Void" - } - - /// Whether type is a tuple - public var isTuple: Bool { - actualTypeName?.tuple != nil || tuple != nil - } - - /// Tuple type data - public var tuple: TupleType? - - /// Whether type is an array - public var isArray: Bool { - actualTypeName?.array != nil || array != nil - } - - /// Array type data - public var array: ArrayType? - - /// Whether type is a dictionary - public var isDictionary: Bool { - actualTypeName?.dictionary != nil || dictionary != nil - } - - /// Dictionary type data - public var dictionary: DictionaryType? - - /// Whether type is a closure - public var isClosure: Bool { - actualTypeName?.closure != nil || closure != nil - } - - /// Closure type data - public var closure: ClosureType? - - /// Whether type is a Set - public var isSet: Bool { - actualTypeName?.set != nil || set != nil - } - - /// Set type data - public var set: SetType? - - /// Prints typename as it would appear on definition - public var asSource: String { - // TODO: TBR special treatment - let specialTreatment = isOptional && name.hasPrefix("Optional<") - - var description = ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [specialTreatment ? name : unwrappedTypeName] - ).joined(separator: " ") - - if let _ = self.dictionary { // array and dictionary cases are covered by the unwrapped type name -// description.append(dictionary.asSource) - } else if let _ = self.array { -// description.append(array.asSource) - } else if let _ = self.generic { -// let arguments = generic.typeParameters -// .map({ $0.typeName.asSource }) -// .joined(separator: ", ") -// description.append("<\\(arguments)>") - } - if !specialTreatment { - if isImplicitlyUnwrappedOptional { - description.append("!") - } else if isOptional { - description.append("?") + if let module = type.module { + longKey = [module, type.name].joined(separator: ".") } } - return description - } - - public override var description: String { - ( - attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() + - modifiers.map({ $0.asSource }) + - [name] - ).joined(separator: " ") - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? TypeName else { - results.append("Incorrect type ") - return results + // If we find the types directly, return them + if let types = types[key] { + return types } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "generic").trackDifference(actual: self.generic, expected: castObject.generic)) - results.append(contentsOf: DiffableResult(identifier: "isProtocolComposition").trackDifference(actual: self.isProtocolComposition, expected: castObject.isProtocolComposition)) - results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) - results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) - results.append(contentsOf: DiffableResult(identifier: "tuple").trackDifference(actual: self.tuple, expected: castObject.tuple)) - results.append(contentsOf: DiffableResult(identifier: "array").trackDifference(actual: self.array, expected: castObject.array)) - results.append(contentsOf: DiffableResult(identifier: "dictionary").trackDifference(actual: self.dictionary, expected: castObject.dictionary)) - results.append(contentsOf: DiffableResult(identifier: "closure").trackDifference(actual: self.closure, expected: castObject.closure)) - results.append(contentsOf: DiffableResult(identifier: "set").trackDifference(actual: self.set, expected: castObject.set)) - return results - } - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.generic) - hasher.combine(self.isProtocolComposition) - hasher.combine(self.attributes) - hasher.combine(self.modifiers) - hasher.combine(self.tuple) - hasher.combine(self.array) - hasher.combine(self.dictionary) - hasher.combine(self.closure) - hasher.combine(self.set) - return hasher.finalize() + // if we find a types for the longKey, return them + if let longKey = longKey, let types = types[longKey] { + return types + } + + return [] } /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? TypeName else { return false } - if self.name != rhs.name { return false } - if self.generic != rhs.generic { return false } - if self.isProtocolComposition != rhs.isProtocolComposition { return false } - if self.attributes != rhs.attributes { return false } - if self.modifiers != rhs.modifiers { return false } - if self.tuple != rhs.tuple { return false } - if self.array != rhs.array { return false } - if self.dictionary != rhs.dictionary { return false } - if self.closure != rhs.closure { return false } - if self.set != rhs.set { return false } - return true + public func value(forKey key: String) -> Any? { + do { + return try types(forKey: key) + } catch { + Log.error(error) + return nil + } } -// sourcery:inline:TypeName.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - self.generic = aDecoder.decode(forKey: "generic") - self.isProtocolComposition = aDecoder.decode(forKey: "isProtocolComposition") - self.actualTypeName = aDecoder.decode(forKey: "actualTypeName") - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { - withVaList(["attributes"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { - withVaList(["modifiers"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.modifiers = modifiers - self.isOptional = aDecoder.decode(forKey: "isOptional") - self.isImplicitlyUnwrappedOptional = aDecoder.decode(forKey: "isImplicitlyUnwrappedOptional") - guard let unwrappedTypeName: String = aDecoder.decode(forKey: "unwrappedTypeName") else { - withVaList(["unwrappedTypeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.unwrappedTypeName = unwrappedTypeName - self.tuple = aDecoder.decode(forKey: "tuple") - self.array = aDecoder.decode(forKey: "array") - self.dictionary = aDecoder.decode(forKey: "dictionary") - self.closure = aDecoder.decode(forKey: "closure") - self.set = aDecoder.decode(forKey: "set") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.generic, forKey: "generic") - aCoder.encode(self.isProtocolComposition, forKey: "isProtocolComposition") - aCoder.encode(self.actualTypeName, forKey: "actualTypeName") - aCoder.encode(self.attributes, forKey: "attributes") - aCoder.encode(self.modifiers, forKey: "modifiers") - aCoder.encode(self.isOptional, forKey: "isOptional") - aCoder.encode(self.isImplicitlyUnwrappedOptional, forKey: "isImplicitlyUnwrappedOptional") - aCoder.encode(self.unwrappedTypeName, forKey: "unwrappedTypeName") - aCoder.encode(self.tuple, forKey: "tuple") - aCoder.encode(self.array, forKey: "array") - aCoder.encode(self.dictionary, forKey: "dictionary") - aCoder.encode(self.closure, forKey: "closure") - aCoder.encode(self.set, forKey: "set") - } -// sourcery:end - - // sourcery: skipEquality, skipDescription /// :nodoc: - public override var debugDescription: String { - return name - } - - public convenience init(_ description: String) { - self.init(name: description, actualTypeName: nil) - } -} - -extension TypeName { - public static func unknown(description: String?, attributes: AttributeList = [:]) -> TypeName { - if let description = description { - Log.astWarning("Unknown type, please add type attribution to \\(description)") - } else { - Log.astWarning("Unknown type, please add type attribution") + public subscript(_ key: String) -> [Type] { + do { + return try types(forKey: key) + } catch { + Log.error(error) + return [] } - return TypeName(name: "UnknownTypeSoAddTypeAttributionToVariable", attributes: attributes) } } +#endif """), - .init(name: "Typealias.swift", content: + .init(name: "Types_Linux.swift", content: """ +// +// Created by Krzysztof Zablocki on 31/12/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if !canImport(ObjectiveC) import Foundation // sourcery: skipJSExport -/// :nodoc: -public final class Typealias: NSObject, Typed, SourceryModel, Diffable { - // New typealias name - public let aliasName: String - - // Target name - public let typeName: TypeName - - // sourcery: skipEquality, skipDescription - public var type: Type? - - /// module in which this typealias was declared - public var module: String? - - // sourcery: skipEquality, skipDescription - public var parent: Type? { - didSet { - parentName = parent?.name +/// Collection of scanned types for accessing in templates +public final class Types: NSObject, SourceryModel, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "types": + return types + case "enums": + return enums + case "all": + return all + case "protocols": + return protocols + case "classes": + return classes + case "structs": + return structs + case "extensions": + return extensions + case "implementing": + return implementing + case "inheriting": + return inheriting + case "based": + return based + default: + fatalError("unable to lookup: \\(member) in \\(self)") } } - /// Type access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let accessLevel: String - - var parentName: String? - - public var name: String { - if let parentName = parent?.name { - return "\\(module != nil ? "\\(module!)." : "")\\(parentName).\\(aliasName)" - } else { - return "\\(module != nil ? "\\(module!)." : "")\\(aliasName)" - } - } - - public init(aliasName: String = "", typeName: TypeName, accessLevel: AccessLevel = .internal, parent: Type? = nil, module: String? = nil) { - self.aliasName = aliasName - self.typeName = typeName - self.accessLevel = accessLevel.rawValue - self.parent = parent - self.parentName = parent?.name - self.module = module - } - /// :nodoc: + public let types: [Type] + + /// All known typealiases + public let typealiases: [Typealias] + + /// :nodoc: + public init(types: [Type], typealiases: [Typealias] = []) { + self.types = types + self.typealiases = typealiases + } + + /// :nodoc: + // sourcery: skipJSExport override public var description: String { var string = "\\(Swift.type(of: self)): " - string += "aliasName = \\(String(describing: self.aliasName)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "module = \\(String(describing: self.module)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "parentName = \\(String(describing: self.parentName)), " - string += "name = \\(String(describing: self.name))" + string.append("types = \\(String(describing: self.types)), ") + string.append("typealiases = \\(String(describing: self.typealiases))") return string } public func diffAgainst(_ object: Any?) -> DiffableResult { let results = DiffableResult() - guard let castObject = object as? Typealias else { - results.append("Incorrect type ") + guard let castObject = object as? Types else { + results.append("Incorrect type ") return results } - results.append(contentsOf: DiffableResult(identifier: "aliasName").trackDifference(actual: self.aliasName, expected: castObject.aliasName)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "module").trackDifference(actual: self.module, expected: castObject.module)) - results.append(contentsOf: DiffableResult(identifier: "accessLevel").trackDifference(actual: self.accessLevel, expected: castObject.accessLevel)) - results.append(contentsOf: DiffableResult(identifier: "parentName").trackDifference(actual: self.parentName, expected: castObject.parentName)) + results.append(contentsOf: DiffableResult(identifier: "types").trackDifference(actual: self.types, expected: castObject.types)) + results.append(contentsOf: DiffableResult(identifier: "typealiases").trackDifference(actual: self.typealiases, expected: castObject.typealiases)) return results } + /// :nodoc: + // sourcery: skipJSExport public override var hash: Int { var hasher = Hasher() - hasher.combine(self.aliasName) - hasher.combine(self.typeName) - hasher.combine(self.module) - hasher.combine(self.accessLevel) - hasher.combine(self.parentName) + hasher.combine(self.types) + hasher.combine(self.typealiases) return hasher.finalize() } /// :nodoc: public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Typealias else { return false } - if self.aliasName != rhs.aliasName { return false } - if self.typeName != rhs.typeName { return false } - if self.module != rhs.module { return false } - if self.accessLevel != rhs.accessLevel { return false } - if self.parentName != rhs.parentName { return false } + guard let rhs = object as? Types else { return false } + if self.types != rhs.types { return false } + if self.typealiases != rhs.typealiases { return false } return true } -// sourcery:inline:Typealias.AutoCoding +// sourcery:inline:Types.AutoCoding /// :nodoc: required public init?(coder aDecoder: NSCoder) { - guard let aliasName: String = aDecoder.decode(forKey: "aliasName") else { - withVaList(["aliasName"]) { arguments in + guard let types: [Type] = aDecoder.decode(forKey: "types") else { + withVaList(["types"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.aliasName = aliasName - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { + }; self.types = types + guard let typealiases: [Typealias] = aDecoder.decode(forKey: "typealiases") else { + withVaList(["typealiases"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.typealiases = typealiases + } + + /// :nodoc: + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.types, forKey: "types") + aCoder.encode(self.typealiases, forKey: "typealiases") + } +// sourcery:end + + // sourcery: skipDescription, skipEquality, skipCoding + /// :nodoc: + public lazy internal(set) var typesByName: [String: Type] = { + var typesByName = [String: Type]() + self.types.forEach { typesByName[$0.globalName] = $0 } + return typesByName + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// :nodoc: + public lazy internal(set) var typesaliasesByName: [String: Typealias] = { + var typesaliasesByName = [String: Typealias]() + self.typealiases.forEach { typesaliasesByName[$0.name] = $0 } + return typesaliasesByName + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known types, excluding protocols or protocol compositions. + public lazy internal(set) var all: [Type] = { + return self.types.filter { !($0 is Protocol || $0 is ProtocolComposition) } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known protocols + public lazy internal(set) var protocols: [Protocol] = { + return self.types.compactMap { $0 as? Protocol } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known protocol compositions + public lazy internal(set) var protocolCompositions: [ProtocolComposition] = { + return self.types.compactMap { $0 as? ProtocolComposition } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known classes + public lazy internal(set) var classes: [Class] = { + return self.all.compactMap { $0 as? Class } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known structs + public lazy internal(set) var structs: [Struct] = { + return self.all.compactMap { $0 as? Struct } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known enums + public lazy internal(set) var enums: [Enum] = { + return self.all.compactMap { $0 as? Enum } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// All known extensions + public lazy internal(set) var extensions: [Type] = { + return self.all.compactMap { $0.isExtension ? $0 : nil } + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Types based on any other type, grouped by its name, even if they are not known. + /// `types.based.MyType` returns list of types based on `MyType` + public lazy internal(set) var based: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.based.keys) } + ) + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Classes inheriting from any known class, grouped by its name. + /// `types.inheriting.MyClass` returns list of types inheriting from `MyClass` + public lazy internal(set) var inheriting: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.inherits.keys) }, + validate: { type in + guard type is Class else { + throw "\\(type.name) is not a class and should be used with `implementing` or `based`" + } + }) + }() + + // sourcery: skipDescription, skipEquality, skipCoding + /// Types implementing known protocol, grouped by its name. + /// `types.implementing.MyProtocol` returns list of types implementing `MyProtocol` + public lazy internal(set) var implementing: TypesCollection = { + TypesCollection( + types: self.types, + collection: { Array($0.implements.keys) }, + validate: { type in + guard type is Protocol else { + throw "\\(type.name) is a class and should be used with `inheriting` or `based`" + } + }) + }() +} +#endif + +"""), + .init(name: "Variable_Linux.swift", content: +""" +// +// Created by Krzysztof Zablocki on 13/09/2016. +// Copyright (c) 2016 Pixle. All rights reserved. +// +#if !canImport(ObjectiveC) +import Foundation + +/// :nodoc: +public typealias SourceryVariable = Variable + +/// Defines variable +public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable, SourceryDynamicMemberLookup { + public subscript(dynamicMember member: String) -> Any? { + switch member { + case "readAccess": + return readAccess + case "annotations": + return annotations + case "isOptional": + return isOptional + case "name": + return name + case "typeName": + return typeName + case "type": + return type + case "definedInType": + return definedInType + case "isStatic": + return isStatic + case "isAsync": + return isAsync + case "throws": + return `throws` + case "isArray": + return isArray + case "isDictionary": + return isDictionary + case "isDynamic": + return isDynamic + default: + fatalError("unable to lookup: \\(member) in \\(self)") + } + } + + /// Variable name + public let name: String + + /// Variable type name + public let typeName: TypeName + + // sourcery: skipEquality, skipDescription + /// Variable type, if known, i.e. if the type is declared in the scanned sources. + /// For explanation, see + public var type: Type? + + /// Whether variable is computed and not stored + public let isComputed: Bool + + /// Whether variable is async + public let isAsync: Bool + + /// Whether variable throws + public let `throws`: Bool + + /// Whether variable is static + public let isStatic: Bool + + /// Variable read access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` + public let readAccess: String + + /// Variable write access, i.e. `internal`, `private`, `fileprivate`, `public`, `open`. + /// For immutable variables this value is empty string + public let writeAccess: String + + /// composed access level + /// sourcery: skipJSExport + public var accessLevel: (read: AccessLevel, write: AccessLevel) { + (read: AccessLevel(rawValue: readAccess) ?? .none, AccessLevel(rawValue: writeAccess) ?? .none) + } + + /// Whether variable is mutable or not + public var isMutable: Bool { + return writeAccess != AccessLevel.none.rawValue + } + + /// Variable default value expression + public var defaultValue: String? + + /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 + public var annotations: Annotations = [:] + + public var documentation: Documentation = [] + + /// Variable attributes, i.e. `@IBOutlet`, `@IBInspectable` + public var attributes: AttributeList + + /// Modifiers, i.e. `private` + public var modifiers: [SourceryModifier] + + /// Whether variable is final or not + public var isFinal: Bool { + return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } + } + + /// Whether variable is lazy or not + public var isLazy: Bool { + return modifiers.contains { $0.name == Attribute.Identifier.lazy.rawValue } + } + + /// Whether variable is dynamic or not + public var isDynamic: Bool { + modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } + } + + /// Reference to type name where the variable is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc + public internal(set) var definedInTypeName: TypeName? + + /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` + public var actualDefinedInTypeName: TypeName? { + return definedInTypeName?.actualTypeName ?? definedInTypeName + } + + // sourcery: skipEquality, skipDescription + /// Reference to actual type where the object is defined, + /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown + public var definedInType: Type? + + /// :nodoc: + public init(name: String = "", + typeName: TypeName, + type: Type? = nil, + accessLevel: (read: AccessLevel, write: AccessLevel) = (.internal, .internal), + isComputed: Bool = false, + isAsync: Bool = false, + `throws`: Bool = false, + isStatic: Bool = false, + defaultValue: String? = nil, + attributes: AttributeList = [:], + modifiers: [SourceryModifier] = [], + annotations: [String: NSObject] = [:], + documentation: [String] = [], + definedInTypeName: TypeName? = nil) { + + self.name = name + self.typeName = typeName + self.type = type + self.isComputed = isComputed + self.isAsync = isAsync + self.`throws` = `throws` + self.isStatic = isStatic + self.defaultValue = defaultValue + self.readAccess = accessLevel.read.rawValue + self.writeAccess = accessLevel.write.rawValue + self.attributes = attributes + self.modifiers = modifiers + self.annotations = annotations + self.documentation = documentation + self.definedInTypeName = definedInTypeName + } + + /// :nodoc: + // sourcery: skipJSExport + override public var description: String { + var string = "\\(Swift.type(of: self)): " + string.append("name = \\(String(describing: self.name)), ") + string.append("typeName = \\(String(describing: self.typeName)), ") + string.append("isComputed = \\(String(describing: self.isComputed)), ") + string.append("isAsync = \\(String(describing: self.isAsync)), ") + string.append("`throws` = \\(String(describing: self.`throws`)), ") + string.append("isStatic = \\(String(describing: self.isStatic)), ") + string.append("readAccess = \\(String(describing: self.readAccess)), ") + string.append("writeAccess = \\(String(describing: self.writeAccess)), ") + string.append("accessLevel = \\(String(describing: self.accessLevel)), ") + string.append("isMutable = \\(String(describing: self.isMutable)), ") + string.append("defaultValue = \\(String(describing: self.defaultValue)), ") + string.append("annotations = \\(String(describing: self.annotations)), ") + string.append("documentation = \\(String(describing: self.documentation)), ") + string.append("attributes = \\(String(describing: self.attributes)), ") + string.append("modifiers = \\(String(describing: self.modifiers)), ") + string.append("isFinal = \\(String(describing: self.isFinal)), ") + string.append("isLazy = \\(String(describing: self.isLazy)), ") + string.append("isDynamic = \\(String(describing: self.isDynamic)), ") + string.append("definedInTypeName = \\(String(describing: self.definedInTypeName)), ") + string.append("actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName))") + return string + } + + public func diffAgainst(_ object: Any?) -> DiffableResult { + let results = DiffableResult() + guard let castObject = object as? Variable else { + results.append("Incorrect type ") + return results + } + results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) + results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) + results.append(contentsOf: DiffableResult(identifier: "isComputed").trackDifference(actual: self.isComputed, expected: castObject.isComputed)) + results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) + results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) + results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) + results.append(contentsOf: DiffableResult(identifier: "readAccess").trackDifference(actual: self.readAccess, expected: castObject.readAccess)) + results.append(contentsOf: DiffableResult(identifier: "writeAccess").trackDifference(actual: self.writeAccess, expected: castObject.writeAccess)) + results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) + results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) + results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) + results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) + results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) + results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) + return results + } + + /// :nodoc: + // sourcery: skipJSExport + public override var hash: Int { + var hasher = Hasher() + hasher.combine(self.name) + hasher.combine(self.typeName) + hasher.combine(self.isComputed) + hasher.combine(self.isAsync) + hasher.combine(self.`throws`) + hasher.combine(self.isStatic) + hasher.combine(self.readAccess) + hasher.combine(self.writeAccess) + hasher.combine(self.defaultValue) + hasher.combine(self.annotations) + hasher.combine(self.documentation) + hasher.combine(self.attributes) + hasher.combine(self.modifiers) + hasher.combine(self.definedInTypeName) + return hasher.finalize() + } + + /// :nodoc: + public override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? Variable else { return false } + if self.name != rhs.name { return false } + if self.typeName != rhs.typeName { return false } + if self.isComputed != rhs.isComputed { return false } + if self.isAsync != rhs.isAsync { return false } + if self.`throws` != rhs.`throws` { return false } + if self.isStatic != rhs.isStatic { return false } + if self.readAccess != rhs.readAccess { return false } + if self.writeAccess != rhs.writeAccess { return false } + if self.defaultValue != rhs.defaultValue { return false } + if self.annotations != rhs.annotations { return false } + if self.documentation != rhs.documentation { return false } + if self.attributes != rhs.attributes { return false } + if self.modifiers != rhs.modifiers { return false } + if self.definedInTypeName != rhs.definedInTypeName { return false } + return true + } + +// sourcery:inline:Variable.AutoCoding + + /// :nodoc: + required public init?(coder aDecoder: NSCoder) { + guard let name: String = aDecoder.decode(forKey: "name") else { + withVaList(["name"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.name = name + guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { withVaList(["typeName"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() }; self.typeName = typeName self.type = aDecoder.decode(forKey: "type") - self.module = aDecoder.decode(forKey: "module") - self.parent = aDecoder.decode(forKey: "parent") - guard let accessLevel: String = aDecoder.decode(forKey: "accessLevel") else { - withVaList(["accessLevel"]) { arguments in + self.isComputed = aDecoder.decode(forKey: "isComputed") + self.isAsync = aDecoder.decode(forKey: "isAsync") + self.`throws` = aDecoder.decode(forKey: "`throws`") + self.isStatic = aDecoder.decode(forKey: "isStatic") + guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { + withVaList(["readAccess"]) { arguments in NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) } fatalError() - }; self.accessLevel = accessLevel - self.parentName = aDecoder.decode(forKey: "parentName") + }; self.readAccess = readAccess + guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { + withVaList(["writeAccess"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.writeAccess = writeAccess + self.defaultValue = aDecoder.decode(forKey: "defaultValue") + guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { + withVaList(["annotations"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.annotations = annotations + guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { + withVaList(["documentation"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.documentation = documentation + guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { + withVaList(["attributes"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.attributes = attributes + guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { + withVaList(["modifiers"]) { arguments in + NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) + } + fatalError() + }; self.modifiers = modifiers + self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") + self.definedInType = aDecoder.decode(forKey: "definedInType") } /// :nodoc: public func encode(with aCoder: NSCoder) { - aCoder.encode(self.aliasName, forKey: "aliasName") + aCoder.encode(self.name, forKey: "name") aCoder.encode(self.typeName, forKey: "typeName") aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.module, forKey: "module") - aCoder.encode(self.parent, forKey: "parent") - aCoder.encode(self.accessLevel, forKey: "accessLevel") - aCoder.encode(self.parentName, forKey: "parentName") + aCoder.encode(self.isComputed, forKey: "isComputed") + aCoder.encode(self.isAsync, forKey: "isAsync") + aCoder.encode(self.`throws`, forKey: "`throws`") + aCoder.encode(self.isStatic, forKey: "isStatic") + aCoder.encode(self.readAccess, forKey: "readAccess") + aCoder.encode(self.writeAccess, forKey: "writeAccess") + aCoder.encode(self.defaultValue, forKey: "defaultValue") + aCoder.encode(self.annotations, forKey: "annotations") + aCoder.encode(self.documentation, forKey: "documentation") + aCoder.encode(self.attributes, forKey: "attributes") + aCoder.encode(self.modifiers, forKey: "modifiers") + aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") + aCoder.encode(self.definedInType, forKey: "definedInType") } // sourcery:end } +#endif +"""), + .init(name: "AutoHashable.generated.swift", content: +""" +// Generated using Sourcery 1.3.1 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable all + + +// MARK: - AutoHashable for classes, protocols, structs + +// MARK: - AutoHashable for Enums + +"""), + .init(name: "Coding.generated.swift", content: +""" +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable vertical_whitespace trailing_newline + +import Foundation + + +extension NSCoder { + + @nonobjc func decode(forKey: String) -> String? { + return self.maybeDecode(forKey: forKey) as String? + } + + @nonobjc func decode(forKey: String) -> TypeName? { + return self.maybeDecode(forKey: forKey) as TypeName? + } + + @nonobjc func decode(forKey: String) -> AccessLevel? { + return self.maybeDecode(forKey: forKey) as AccessLevel? + } + + @nonobjc func decode(forKey: String) -> Bool { + return self.decodeBool(forKey: forKey) + } + + @nonobjc func decode(forKey: String) -> Int { + return self.decodeInteger(forKey: forKey) + } + + func decode(forKey: String) -> E? { + return maybeDecode(forKey: forKey) as E? + } + + fileprivate func maybeDecode(forKey: String) -> E? { + guard let object = self.decodeObject(forKey: forKey) else { + return nil + } + + return object as? E + } + +} + +extension ArrayType: NSCoding {} + +extension AssociatedType: NSCoding {} + +extension AssociatedValue: NSCoding {} + +extension Attribute: NSCoding {} + +extension BytesRange: NSCoding {} + + +extension ClosureParameter: NSCoding {} + +extension ClosureType: NSCoding {} + +extension DictionaryType: NSCoding {} + + +extension EnumCase: NSCoding {} + +extension FileParserResult: NSCoding {} + +extension GenericParameter: NSCoding {} + +extension GenericRequirement: NSCoding {} + +extension GenericType: NSCoding {} + +extension GenericTypeParameter: NSCoding {} + +extension Import: NSCoding {} + +extension Method: NSCoding {} + +extension MethodParameter: NSCoding {} + +extension Modifier: NSCoding {} + + + +extension SetType: NSCoding {} + + +extension Subscript: NSCoding {} + +extension TupleElement: NSCoding {} + +extension TupleType: NSCoding {} + +extension Type: NSCoding {} + +extension TypeName: NSCoding {} + +extension Typealias: NSCoding {} + +extension Types: NSCoding {} + +extension Variable: NSCoding {} + + +"""), + .init(name: "JSExport.generated.swift", content: +""" +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery +// DO NOT EDIT +// swiftlint:disable vertical_whitespace trailing_newline + +#if canImport(JavaScriptCore) +import JavaScriptCore + +@objc protocol ActorAutoJSExport: JSExport { + var kind: String { get } + var isFinal: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Actor: ActorAutoJSExport {} + +@objc protocol ArrayTypeAutoJSExport: JSExport { + var name: String { get } + var elementTypeName: TypeName { get } + var elementType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension ArrayType: ArrayTypeAutoJSExport {} + +@objc protocol AssociatedTypeAutoJSExport: JSExport { + var name: String { get } + var typeName: TypeName? { get } + var type: Type? { get } +} + +extension AssociatedType: AssociatedTypeAutoJSExport {} + +@objc protocol AssociatedValueAutoJSExport: JSExport { + var localName: String? { get } + var externalName: String? { get } + var typeName: TypeName { get } + var type: Type? { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension AssociatedValue: AssociatedValueAutoJSExport {} + +@objc protocol AttributeAutoJSExport: JSExport { + var name: String { get } + var arguments: [String: NSObject] { get } + var asSource: String { get } + var description: String { get } +} + +extension Attribute: AttributeAutoJSExport {} + +@objc protocol BytesRangeAutoJSExport: JSExport { + var offset: Int64 { get } + var length: Int64 { get } +} + +extension BytesRange: BytesRangeAutoJSExport {} + +@objc protocol ClassAutoJSExport: JSExport { + var kind: String { get } + var isFinal: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Class: ClassAutoJSExport {} + +@objc protocol ClosureParameterAutoJSExport: JSExport { + var argumentLabel: String? { get } + var name: String? { get } + var typeName: TypeName { get } + var `inout`: Bool { get } + var type: Type? { get } + var isVariadic: Bool { get } + var typeAttributes: AttributeList { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension ClosureParameter: ClosureParameterAutoJSExport {} + +@objc protocol ClosureTypeAutoJSExport: JSExport { + var name: String { get } + var parameters: [ClosureParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isAsync: Bool { get } + var asyncKeyword: String? { get } + var `throws`: Bool { get } + var throwsOrRethrowsKeyword: String? { get } + var asSource: String { get } +} + +extension ClosureType: ClosureTypeAutoJSExport {} + +@objc protocol DictionaryTypeAutoJSExport: JSExport { + var name: String { get } + var valueTypeName: TypeName { get } + var valueType: Type? { get } + var keyTypeName: TypeName { get } + var keyType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension DictionaryType: DictionaryTypeAutoJSExport {} + +@objc protocol EnumAutoJSExport: JSExport { + var kind: String { get } + var cases: [EnumCase] { get } + var rawTypeName: TypeName? { get } + var hasRawType: Bool { get } + var rawType: Type? { get } + var based: [String: String] { get } + var hasAssociatedValues: Bool { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Enum: EnumAutoJSExport {} + +@objc protocol EnumCaseAutoJSExport: JSExport { + var name: String { get } + var rawValue: String? { get } + var associatedValues: [AssociatedValue] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var indirect: Bool { get } + var hasAssociatedValue: Bool { get } +} + +extension EnumCase: EnumCaseAutoJSExport {} + + +@objc protocol GenericParameterAutoJSExport: JSExport { + var name: String { get } + var inheritedTypeName: TypeName? { get } +} + +extension GenericParameter: GenericParameterAutoJSExport {} + +@objc protocol GenericRequirementAutoJSExport: JSExport { + var leftType: AssociatedType { get } + var rightType: GenericTypeParameter { get } + var relationship: String { get } + var relationshipSyntax: String { get } +} + +extension GenericRequirement: GenericRequirementAutoJSExport {} + +@objc protocol GenericTypeAutoJSExport: JSExport { + var name: String { get } + var typeParameters: [GenericTypeParameter] { get } + var asSource: String { get } + var description: String { get } +} + +extension GenericType: GenericTypeAutoJSExport {} + +@objc protocol GenericTypeParameterAutoJSExport: JSExport { + var typeName: TypeName { get } + var type: Type? { get } +} + +extension GenericTypeParameter: GenericTypeParameterAutoJSExport {} + +@objc protocol ImportAutoJSExport: JSExport { + var kind: String? { get } + var path: String { get } + var description: String { get } + var moduleName: String { get } +} + +extension Import: ImportAutoJSExport {} + +@objc protocol MethodAutoJSExport: JSExport { + var name: String { get } + var selectorName: String { get } + var shortName: String { get } + var callName: String { get } + var parameters: [MethodParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var `rethrows`: Bool { get } + var accessLevel: String { get } + var isStatic: Bool { get } + var isClass: Bool { get } + var isInitializer: Bool { get } + var isDeinitializer: Bool { get } + var isFailableInitializer: Bool { get } + var isConvenienceInitializer: Bool { get } + var isRequired: Bool { get } + var isFinal: Bool { get } + var isMutating: Bool { get } + var isGeneric: Bool { get } + var isOptional: Bool { get } + var isNonisolated: Bool { get } + var isDynamic: Bool { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } +} + +extension Method: MethodAutoJSExport {} + +@objc protocol MethodParameterAutoJSExport: JSExport { + var argumentLabel: String? { get } + var name: String { get } + var typeName: TypeName { get } + var `inout`: Bool { get } + var isVariadic: Bool { get } + var type: Type? { get } + var typeAttributes: AttributeList { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension MethodParameter: MethodParameterAutoJSExport {} + +@objc protocol ModifierAutoJSExport: JSExport { + var name: String { get } + var detail: String? { get } + var asSource: String { get } +} + +extension Modifier: ModifierAutoJSExport {} + +@objc protocol ProtocolAutoJSExport: JSExport { + var kind: String { get } + var associatedTypes: [String: AssociatedType] { get } + var genericRequirements: [GenericRequirement] { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var fileName: String? { get } +} + +extension Protocol: ProtocolAutoJSExport {} + +@objc protocol ProtocolCompositionAutoJSExport: JSExport { + var kind: String { get } + var composedTypeNames: [TypeName] { get } + var composedTypes: [Type]? { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension ProtocolComposition: ProtocolCompositionAutoJSExport {} + +@objc protocol SetTypeAutoJSExport: JSExport { + var name: String { get } + var elementTypeName: TypeName { get } + var elementType: Type? { get } + var asGeneric: GenericType { get } + var asSource: String { get } +} + +extension SetType: SetTypeAutoJSExport {} + + + +@objc protocol StructAutoJSExport: JSExport { + var kind: String { get } + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Struct: StructAutoJSExport {} + +@objc protocol SubscriptAutoJSExport: JSExport { + var parameters: [MethodParameter] { get } + var returnTypeName: TypeName { get } + var actualReturnTypeName: TypeName { get } + var returnType: Type? { get } + var isOptionalReturnType: Bool { get } + var isImplicitlyUnwrappedOptionalReturnType: Bool { get } + var unwrappedReturnTypeName: String { get } + var isFinal: Bool { get } + var readAccess: String { get } + var writeAccess: String { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var isMutable: Bool { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericParameters: [GenericParameter] { get } + var genericRequirements: [GenericRequirement] { get } + var isGeneric: Bool { get } +} + +extension Subscript: SubscriptAutoJSExport {} + +@objc protocol TemplateContextAutoJSExport: JSExport { + var functions: [SourceryMethod] { get } + var types: Types { get } + var argument: [String: NSObject] { get } + var type: [String: Type] { get } + var stencilContext: [String: Any] { get } + var jsContext: [String: Any] { get } +} + +extension TemplateContext: TemplateContextAutoJSExport {} + +@objc protocol TupleElementAutoJSExport: JSExport { + var name: String? { get } + var typeName: TypeName { get } + var type: Type? { get } + var asSource: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension TupleElement: TupleElementAutoJSExport {} + +@objc protocol TupleTypeAutoJSExport: JSExport { + var name: String { get } + var elements: [TupleElement] { get } +} + +extension TupleType: TupleTypeAutoJSExport {} + +@objc protocol TypeAutoJSExport: JSExport { + var module: String? { get } + var imports: [Import] { get } + var allImports: [Import] { get } + var typealiases: [String: Typealias] { get } + var kind: String { get } + var accessLevel: String { get } + var name: String { get } + var isUnknownExtension: Bool { get } + var globalName: String { get } + var isGeneric: Bool { get } + var localName: String { get } + var variables: [Variable] { get } + var rawVariables: [Variable] { get } + var allVariables: [Variable] { get } + var methods: [Method] { get } + var rawMethods: [Method] { get } + var allMethods: [Method] { get } + var subscripts: [Subscript] { get } + var rawSubscripts: [Subscript] { get } + var allSubscripts: [Subscript] { get } + var initializers: [Method] { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var staticVariables: [Variable] { get } + var staticMethods: [Method] { get } + var classMethods: [Method] { get } + var instanceVariables: [Variable] { get } + var instanceMethods: [Method] { get } + var computedVariables: [Variable] { get } + var storedVariables: [Variable] { get } + var inheritedTypes: [String] { get } + var based: [String: String] { get } + var basedTypes: [String: Type] { get } + var inherits: [String: Type] { get } + var implements: [String: Type] { get } + var containedTypes: [Type] { get } + var containedType: [String: Type] { get } + var parentName: String? { get } + var parent: Type? { get } + var supertype: Type? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var genericRequirements: [GenericRequirement] { get } + var fileName: String? { get } +} + +extension Type: TypeAutoJSExport {} + +@objc protocol TypeNameAutoJSExport: JSExport { + var name: String { get } + var generic: GenericType? { get } + var isGeneric: Bool { get } + var isProtocolComposition: Bool { get } + var actualTypeName: TypeName? { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } + var isVoid: Bool { get } + var isTuple: Bool { get } + var tuple: TupleType? { get } + var isArray: Bool { get } + var array: ArrayType? { get } + var isDictionary: Bool { get } + var dictionary: DictionaryType? { get } + var isClosure: Bool { get } + var closure: ClosureType? { get } + var isSet: Bool { get } + var set: SetType? { get } + var asSource: String { get } + var description: String { get } + var debugDescription: String { get } +} + +extension TypeName: TypeNameAutoJSExport {} + +@objc protocol TypealiasAutoJSExport: JSExport { + var aliasName: String { get } + var typeName: TypeName { get } + var type: Type? { get } + var module: String? { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var parent: Type? { get } + var accessLevel: String { get } + var parentName: String? { get } + var name: String { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension Typealias: TypealiasAutoJSExport {} + + +@objc protocol TypesCollectionAutoJSExport: JSExport { +} + +extension TypesCollection: TypesCollectionAutoJSExport {} + +@objc protocol VariableAutoJSExport: JSExport { + var name: String { get } + var typeName: TypeName { get } + var type: Type? { get } + var isComputed: Bool { get } + var isAsync: Bool { get } + var `throws`: Bool { get } + var isStatic: Bool { get } + var readAccess: String { get } + var writeAccess: String { get } + var isMutable: Bool { get } + var defaultValue: String? { get } + var annotations: Annotations { get } + var documentation: Documentation { get } + var attributes: AttributeList { get } + var modifiers: [SourceryModifier] { get } + var isFinal: Bool { get } + var isLazy: Bool { get } + var isDynamic: Bool { get } + var definedInTypeName: TypeName? { get } + var actualDefinedInTypeName: TypeName? { get } + var definedInType: Type? { get } + var isOptional: Bool { get } + var isImplicitlyUnwrappedOptional: Bool { get } + var unwrappedTypeName: String { get } +} + +extension Variable: VariableAutoJSExport {} + + +#endif """), .init(name: "Typed.generated.swift", content: """ -// Generated using Sourcery 2.0.3 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT // swiftlint:disable vertical_whitespace @@ -7182,340 +8900,6 @@ extension Variable { public var isDictionary: Bool { return typeName.isDictionary } } -"""), - .init(name: "Typed.swift", content: -""" -import Foundation - -/// Descibes typed declaration, i.e. variable, method parameter, tuple element, enum case associated value -public protocol Typed { - - // sourcery: skipEquality, skipDescription - /// Type, if known - var type: Type? { get } - - // sourcery: skipEquality, skipDescription - /// Type name - var typeName: TypeName { get } - - // sourcery: skipEquality, skipDescription - /// Whether type is optional - var isOptional: Bool { get } - - // sourcery: skipEquality, skipDescription - /// Whether type is implicitly unwrapped optional - var isImplicitlyUnwrappedOptional: Bool { get } - - // sourcery: skipEquality, skipDescription - /// Type name without attributes and optional type information - var unwrappedTypeName: String { get } -} - -"""), - .init(name: "Variable.swift", content: -""" -// -// Created by Krzysztof Zablocki on 13/09/2016. -// Copyright (c) 2016 Pixle. All rights reserved. -// - -import Foundation - -/// :nodoc: -public typealias SourceryVariable = Variable - -/// Defines variable -public final class Variable: NSObject, SourceryModel, Typed, Annotated, Documented, Definition, Diffable { - - /// Variable name - public let name: String - - /// Variable type name - public let typeName: TypeName - - // sourcery: skipEquality, skipDescription - /// Variable type, if known, i.e. if the type is declared in the scanned sources. - /// For explanation, see - public var type: Type? - - /// Whether variable is computed and not stored - public let isComputed: Bool - - /// Whether variable is async - public let isAsync: Bool - - /// Whether variable throws - public let `throws`: Bool - - /// Whether variable is static - public let isStatic: Bool - - /// Variable read access level, i.e. `internal`, `private`, `fileprivate`, `public`, `open` - public let readAccess: String - - /// Variable write access, i.e. `internal`, `private`, `fileprivate`, `public`, `open`. - /// For immutable variables this value is empty string - public let writeAccess: String - - /// composed access level - /// sourcery: skipJSExport - public var accessLevel: (read: AccessLevel, write: AccessLevel) { - (read: AccessLevel(rawValue: readAccess) ?? .none, AccessLevel(rawValue: writeAccess) ?? .none) - } - - /// Whether variable is mutable or not - public var isMutable: Bool { - return writeAccess != AccessLevel.none.rawValue - } - - /// Variable default value expression - public var defaultValue: String? - - /// Annotations, that were created with // sourcery: annotation1, other = "annotation value", alterantive = 2 - public var annotations: Annotations = [:] - - public var documentation: Documentation = [] - - /// Variable attributes, i.e. `@IBOutlet`, `@IBInspectable` - public var attributes: AttributeList - - /// Modifiers, i.e. `private` - public var modifiers: [SourceryModifier] - - /// Whether variable is final or not - public var isFinal: Bool { - return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue } - } - - /// Whether variable is lazy or not - public var isLazy: Bool { - return modifiers.contains { $0.name == Attribute.Identifier.lazy.rawValue } - } - - /// Whether variable is dynamic or not - public var isDynamic: Bool { - modifiers.contains { $0.name == Attribute.Identifier.dynamic.rawValue } - } - - /// Reference to type name where the variable is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc - public internal(set) var definedInTypeName: TypeName? - - /// Reference to actual type name where the method is defined if declaration uses typealias, otherwise just a `definedInTypeName` - public var actualDefinedInTypeName: TypeName? { - return definedInTypeName?.actualTypeName ?? definedInTypeName - } - - // sourcery: skipEquality, skipDescription - /// Reference to actual type where the object is defined, - /// nil if defined outside of any `enum`, `struct`, `class` etc or type is unknown - public var definedInType: Type? - - /// :nodoc: - public init(name: String = "", - typeName: TypeName, - type: Type? = nil, - accessLevel: (read: AccessLevel, write: AccessLevel) = (.internal, .internal), - isComputed: Bool = false, - isAsync: Bool = false, - `throws`: Bool = false, - isStatic: Bool = false, - defaultValue: String? = nil, - attributes: AttributeList = [:], - modifiers: [SourceryModifier] = [], - annotations: [String: NSObject] = [:], - documentation: [String] = [], - definedInTypeName: TypeName? = nil) { - - self.name = name - self.typeName = typeName - self.type = type - self.isComputed = isComputed - self.isAsync = isAsync - self.`throws` = `throws` - self.isStatic = isStatic - self.defaultValue = defaultValue - self.readAccess = accessLevel.read.rawValue - self.writeAccess = accessLevel.write.rawValue - self.attributes = attributes - self.modifiers = modifiers - self.annotations = annotations - self.documentation = documentation - self.definedInTypeName = definedInTypeName - } - - /// :nodoc: - override public var description: String { - var string = "\\(Swift.type(of: self)): " - string += "name = \\(String(describing: self.name)), " - string += "typeName = \\(String(describing: self.typeName)), " - string += "isComputed = \\(String(describing: self.isComputed)), " - string += "isAsync = \\(String(describing: self.isAsync)), " - string += "`throws` = \\(String(describing: self.`throws`)), " - string += "isStatic = \\(String(describing: self.isStatic)), " - string += "readAccess = \\(String(describing: self.readAccess)), " - string += "writeAccess = \\(String(describing: self.writeAccess)), " - string += "accessLevel = \\(String(describing: self.accessLevel)), " - string += "isMutable = \\(String(describing: self.isMutable)), " - string += "defaultValue = \\(String(describing: self.defaultValue)), " - string += "annotations = \\(String(describing: self.annotations)), " - string += "documentation = \\(String(describing: self.documentation)), " - string += "attributes = \\(String(describing: self.attributes)), " - string += "modifiers = \\(String(describing: self.modifiers)), " - string += "isFinal = \\(String(describing: self.isFinal)), " - string += "isLazy = \\(String(describing: self.isLazy)), " - string += "isDynamic = \\(String(describing: self.isDynamic)), " - string += "definedInTypeName = \\(String(describing: self.definedInTypeName)), " - string += "actualDefinedInTypeName = \\(String(describing: self.actualDefinedInTypeName))" - return string - } - - public func diffAgainst(_ object: Any?) -> DiffableResult { - let results = DiffableResult() - guard let castObject = object as? Variable else { - results.append("Incorrect type ") - return results - } - results.append(contentsOf: DiffableResult(identifier: "name").trackDifference(actual: self.name, expected: castObject.name)) - results.append(contentsOf: DiffableResult(identifier: "typeName").trackDifference(actual: self.typeName, expected: castObject.typeName)) - results.append(contentsOf: DiffableResult(identifier: "isComputed").trackDifference(actual: self.isComputed, expected: castObject.isComputed)) - results.append(contentsOf: DiffableResult(identifier: "isAsync").trackDifference(actual: self.isAsync, expected: castObject.isAsync)) - results.append(contentsOf: DiffableResult(identifier: "`throws`").trackDifference(actual: self.`throws`, expected: castObject.`throws`)) - results.append(contentsOf: DiffableResult(identifier: "isStatic").trackDifference(actual: self.isStatic, expected: castObject.isStatic)) - results.append(contentsOf: DiffableResult(identifier: "readAccess").trackDifference(actual: self.readAccess, expected: castObject.readAccess)) - results.append(contentsOf: DiffableResult(identifier: "writeAccess").trackDifference(actual: self.writeAccess, expected: castObject.writeAccess)) - results.append(contentsOf: DiffableResult(identifier: "defaultValue").trackDifference(actual: self.defaultValue, expected: castObject.defaultValue)) - results.append(contentsOf: DiffableResult(identifier: "annotations").trackDifference(actual: self.annotations, expected: castObject.annotations)) - results.append(contentsOf: DiffableResult(identifier: "documentation").trackDifference(actual: self.documentation, expected: castObject.documentation)) - results.append(contentsOf: DiffableResult(identifier: "attributes").trackDifference(actual: self.attributes, expected: castObject.attributes)) - results.append(contentsOf: DiffableResult(identifier: "modifiers").trackDifference(actual: self.modifiers, expected: castObject.modifiers)) - results.append(contentsOf: DiffableResult(identifier: "definedInTypeName").trackDifference(actual: self.definedInTypeName, expected: castObject.definedInTypeName)) - return results - } - - public override var hash: Int { - var hasher = Hasher() - hasher.combine(self.name) - hasher.combine(self.typeName) - hasher.combine(self.isComputed) - hasher.combine(self.isAsync) - hasher.combine(self.`throws`) - hasher.combine(self.isStatic) - hasher.combine(self.readAccess) - hasher.combine(self.writeAccess) - hasher.combine(self.defaultValue) - hasher.combine(self.annotations) - hasher.combine(self.documentation) - hasher.combine(self.attributes) - hasher.combine(self.modifiers) - hasher.combine(self.definedInTypeName) - return hasher.finalize() - } - - /// :nodoc: - public override func isEqual(_ object: Any?) -> Bool { - guard let rhs = object as? Variable else { return false } - if self.name != rhs.name { return false } - if self.typeName != rhs.typeName { return false } - if self.isComputed != rhs.isComputed { return false } - if self.isAsync != rhs.isAsync { return false } - if self.`throws` != rhs.`throws` { return false } - if self.isStatic != rhs.isStatic { return false } - if self.readAccess != rhs.readAccess { return false } - if self.writeAccess != rhs.writeAccess { return false } - if self.defaultValue != rhs.defaultValue { return false } - if self.annotations != rhs.annotations { return false } - if self.documentation != rhs.documentation { return false } - if self.attributes != rhs.attributes { return false } - if self.modifiers != rhs.modifiers { return false } - if self.definedInTypeName != rhs.definedInTypeName { return false } - return true - } - -// sourcery:inline:Variable.AutoCoding - - /// :nodoc: - required public init?(coder aDecoder: NSCoder) { - guard let name: String = aDecoder.decode(forKey: "name") else { - withVaList(["name"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.name = name - guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else { - withVaList(["typeName"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.typeName = typeName - self.type = aDecoder.decode(forKey: "type") - self.isComputed = aDecoder.decode(forKey: "isComputed") - self.isAsync = aDecoder.decode(forKey: "isAsync") - self.`throws` = aDecoder.decode(forKey: "`throws`") - self.isStatic = aDecoder.decode(forKey: "isStatic") - guard let readAccess: String = aDecoder.decode(forKey: "readAccess") else { - withVaList(["readAccess"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.readAccess = readAccess - guard let writeAccess: String = aDecoder.decode(forKey: "writeAccess") else { - withVaList(["writeAccess"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.writeAccess = writeAccess - self.defaultValue = aDecoder.decode(forKey: "defaultValue") - guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else { - withVaList(["annotations"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.annotations = annotations - guard let documentation: Documentation = aDecoder.decode(forKey: "documentation") else { - withVaList(["documentation"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.documentation = documentation - guard let attributes: AttributeList = aDecoder.decode(forKey: "attributes") else { - withVaList(["attributes"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.attributes = attributes - guard let modifiers: [SourceryModifier] = aDecoder.decode(forKey: "modifiers") else { - withVaList(["modifiers"]) { arguments in - NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments) - } - fatalError() - }; self.modifiers = modifiers - self.definedInTypeName = aDecoder.decode(forKey: "definedInTypeName") - self.definedInType = aDecoder.decode(forKey: "definedInType") - } - - /// :nodoc: - public func encode(with aCoder: NSCoder) { - aCoder.encode(self.name, forKey: "name") - aCoder.encode(self.typeName, forKey: "typeName") - aCoder.encode(self.type, forKey: "type") - aCoder.encode(self.isComputed, forKey: "isComputed") - aCoder.encode(self.isAsync, forKey: "isAsync") - aCoder.encode(self.`throws`, forKey: "`throws`") - aCoder.encode(self.isStatic, forKey: "isStatic") - aCoder.encode(self.readAccess, forKey: "readAccess") - aCoder.encode(self.writeAccess, forKey: "writeAccess") - aCoder.encode(self.defaultValue, forKey: "defaultValue") - aCoder.encode(self.annotations, forKey: "annotations") - aCoder.encode(self.documentation, forKey: "documentation") - aCoder.encode(self.attributes, forKey: "attributes") - aCoder.encode(self.modifiers, forKey: "modifiers") - aCoder.encode(self.definedInTypeName, forKey: "definedInTypeName") - aCoder.encode(self.definedInType, forKey: "definedInType") - } -// sourcery:end -} - """), ] #endif diff --git a/SourceryTests/Models/TypedSpec.generated.swift b/SourceryTests/Models/TypedSpec.generated.swift index 69f49a6f..bc45a938 100644 --- a/SourceryTests/Models/TypedSpec.generated.swift +++ b/SourceryTests/Models/TypedSpec.generated.swift @@ -1,4 +1,4 @@ -// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT import Quick import Nimble @@ -27,6 +27,7 @@ class TypedSpec: QuickSpec { let variable = result?.types.first?.variables.first return variable?.typeName ?? TypeName(name: "") } + #if canImport(ObjectiveC) it("can report optional via KVC") { expect(AssociatedValue(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true)) @@ -140,6 +141,7 @@ class TypedSpec: QuickSpec { let variable = result?.types.first?.variables.first return variable?.typeName ?? TypeName(name: "") } + #if canImport(ObjectiveC) it("can report optional via KVC") { expect(MethodParameter(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true)) @@ -196,6 +198,7 @@ class TypedSpec: QuickSpec { let variable = result?.types.first?.variables.first return variable?.typeName ?? TypeName(name: "") } + #if canImport(ObjectiveC) it("can report optional via KVC") { expect(TupleElement(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true)) @@ -309,6 +312,7 @@ class TypedSpec: QuickSpec { let variable = result?.types.first?.variables.first return variable?.typeName ?? TypeName(name: "") } + #if canImport(ObjectiveC) it("can report optional via KVC") { expect(Variable(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))