Files
Ruslan A 7153768c65 Fix associatedtype generics (#1345)
* Preliminary associatedtype support

* Implemented associatedtype support with generic requirements

* Fixed failing test

* Squashed commit of the following:

commit 9d01e6f99a
Author: Ruslan A <r.alikhamov@gmail.com>
Date:   Fri Jun 14 20:06:41 2024 +0400

    Improved concurrency support in SwiftTemplate caching (#1344)

* Removed test code

* Removed comment

* Updated Linux classes

* update internal boilerplate code.

* Updated generated code

* Removed warnings

* Updated expected file

* Updated expected file

* Adjusted protocol type for Linux

* Removed protocol composition due to Swift compiler crash under Linux
2024-06-19 22:50:18 +04:00

123 lines
4.5 KiB
Swift

// Created by eric_horacek on 2/12/20.
// Copyright © 2020 Airbnb Inc. All rights reserved.
import Foundation
/// 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 {
// sourcery: skipJSExport
public class var kind: String { return "protocolComposition" }
/// Returns "protocolComposition"
public override var kind: String { Self.kind }
/// The names of the types composed to form this composition
public let composedTypeNames: [TypeName]
// sourcery: skipEquality, skipDescription
/// The types composed to form this composition, if known
public var composedTypes: [Type]?
/// :nodoc:
public init(name: String = "",
parent: Type? = nil,
accessLevel: AccessLevel = .internal,
isExtension: Bool = false,
variables: [Variable] = [],
methods: [Method] = [],
subscripts: [Subscript] = [],
inheritedTypes: [String] = [],
containedTypes: [Type] = [],
typealiases: [Typealias] = [],
attributes: AttributeList = [:],
annotations: [String: NSObject] = [:],
isGeneric: Bool = false,
composedTypeNames: [TypeName] = [],
composedTypes: [Type]? = nil,
implements: [String: Type] = [:],
kind: String = ProtocolComposition.kind) {
self.composedTypeNames = composedTypeNames
self.composedTypes = composedTypes
super.init(
name: name,
parent: parent,
accessLevel: accessLevel,
isExtension: isExtension,
variables: variables,
methods: methods,
subscripts: subscripts,
inheritedTypes: inheritedTypes,
containedTypes: containedTypes,
typealiases: typealiases,
annotations: annotations,
isGeneric: isGeneric,
implements: implements,
kind: kind
)
}
/// :nodoc:
// sourcery: skipJSExport
override public var description: String {
var string = super.description
string += ", "
string += "kind = \(String(describing: self.kind)), "
string += "composedTypeNames = \(String(describing: self.composedTypeNames))"
return string
}
override public func diffAgainst(_ object: Any?) -> DiffableResult {
let results = DiffableResult()
guard let castObject = object as? ProtocolComposition else {
results.append("Incorrect type <expected: ProtocolComposition, received: \(Swift.type(of: object))>")
return results
}
results.append(contentsOf: DiffableResult(identifier: "composedTypeNames").trackDifference(actual: self.composedTypeNames, expected: castObject.composedTypeNames))
results.append(contentsOf: super.diffAgainst(castObject))
return results
}
/// :nodoc:
// sourcery: skipJSExport
public override var hash: Int {
var hasher = Hasher()
hasher.combine(self.composedTypeNames)
hasher.combine(super.hash)
return hasher.finalize()
}
/// :nodoc:
public override func isEqual(_ object: Any?) -> Bool {
guard let rhs = object as? ProtocolComposition else { return false }
if self.composedTypeNames != rhs.composedTypeNames { return false }
return super.isEqual(rhs)
}
// sourcery:inline:ProtocolComposition.AutoCoding
/// :nodoc:
required public init?(coder aDecoder: NSCoder) {
guard let composedTypeNames: [TypeName] = aDecoder.decode(forKey: "composedTypeNames") else {
withVaList(["composedTypeNames"]) { arguments in
NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments)
}
fatalError()
}; self.composedTypeNames = composedTypeNames
self.composedTypes = aDecoder.decode(forKey: "composedTypes")
super.init(coder: aDecoder)
}
/// :nodoc:
override public func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(self.composedTypeNames, forKey: "composedTypeNames")
aCoder.encode(self.composedTypes, forKey: "composedTypes")
}
// sourcery:end
}