mirror of
https://github.com/krzysztofzablocki/Sourcery.git
synced 2026-04-07 19:17:40 +00:00
cec7895f0a
* Adjusted file structure to accommodate two generated files * Adjusted scripting * Removed Description, Diffable, Equality for now * Removed Stencil import * Updated templates * Updated scripting * Updated generated coding * Disable build deletion (temp) * Updated template * Updated generated code * updated generated code * Updated generated code * Adjusted scripting * Updated scripting * Updated generated code * Reverted template deletion * Removed Stencil imports * Updated generated code * trigger CI * Removed description, diffable and equality stencil templates * Reverted temporary changes * Commented failing tests * Skipping JSExport for description & hash * Updated generated code * Enabled failing tests * Adding stencil templates back to test tests * Reset generated file for linux for test * Reverted Extensions for testing * Reverted ParserResultsComposed * Attempt to fix unit tests * Attempt to resolve unit test * Reverted TypeName asSource * Reverted TypeName revertion * Reverted revert of ParserResultComposed * Reverted revert of Extensions * Reverted revert of Linux.content.generated * Reverted attempts to fix unit tests * Fix for the failing codegen tests * Added clarifying comment * Removed description, diffable and equality stencil templates * Updated generated code * Tinkering with optimization level for speed boost * Excluded stencil templates for codegen * Fixed wrong compiler flag * Removed speed optimization to a separate PR * Reverted test code
123 lines
5.3 KiB
Swift
123 lines
5.3 KiB
Swift
#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 <expected: GenericRequirement, received: \(Swift.type(of: object))>")
|
|
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
|