Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic method modifier support #1244

Merged
merged 10 commits into from
Dec 23, 2023
3 changes: 3 additions & 0 deletions SourceryRuntime/Sources/AST/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ
case autoclosure
case convention
case mutating
case nonisolated
case isolated
case escaping
case final
case open
Expand All @@ -69,6 +71,7 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ
case privateSetter = "setter_access.private"
case fileprivateSetter = "setter_access.fileprivate"
case optional
case dynamic

public init?(identifier: String) {
let identifier = identifier.trimmingPrefix("source.decl.attribute.")
Expand Down
18 changes: 12 additions & 6 deletions SourceryRuntime/Sources/AST/Method.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is a convenience initializer
public var isConvenienceInitializer: Bool {
modifiers.contains { $0.name == "convenience" }
modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is required
public var isRequired: Bool {
modifiers.contains { $0.name == "required" }
modifiers.contains { $0.name == Attribute.Identifier.required.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is final
public var isFinal: Bool {
modifiers.contains { $0.name == "final" }
modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is mutating
public var isMutating: Bool {
modifiers.contains { $0.name == "mutating" }
modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue }
}

// sourcery: skipEquality, skipDescription
Expand All @@ -126,13 +126,19 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is optional (in an Objective-C protocol)
public var isOptional: Bool {
modifiers.contains { $0.name == "optional" }
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 == "nonisolated" }
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
Expand Down
20 changes: 14 additions & 6 deletions SourceryRuntime/Sources/AST/Method_Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
return isOptionalReturnType
case "actualReturnTypeName":
return actualReturnTypeName
case "isDynamic":
return isDynamic
default:
fatalError("unable to lookup: \(member) in \(self)")
}
Expand Down Expand Up @@ -135,25 +137,25 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is a convenience initializer
public var isConvenienceInitializer: Bool {
modifiers.contains { $0.name == "convenience" }
modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is required
public var isRequired: Bool {
modifiers.contains { $0.name == "required" }
modifiers.contains { $0.name == Attribute.Identifier.required.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is final
public var isFinal: Bool {
modifiers.contains { $0.name == "final" }
modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is mutating
public var isMutating: Bool {
modifiers.contains { $0.name == "mutating" }
modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue }
}

// sourcery: skipEquality, skipDescription
Expand All @@ -165,13 +167,19 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is optional (in an Objective-C protocol)
public var isOptional: Bool {
modifiers.contains { $0.name == "optional" }
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 == "nonisolated" }
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
Expand Down
10 changes: 8 additions & 2 deletions SourceryRuntime/Sources/AST/Variable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document

/// Whether variable is final or not
public var isFinal: Bool {
return modifiers.contains { $0.name == "final" }
return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

/// Whether variable is lazy or not
public var isLazy: Bool {
return modifiers.contains { $0.name == "lazy" }
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,
Expand Down Expand Up @@ -145,6 +150,7 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document
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
Expand Down
12 changes: 10 additions & 2 deletions SourceryRuntime/Sources/AST/Variable_Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document
return isArray
case "isDictionary":
return isDictionary
case "isDynamic":
return isDynamic
default:
fatalError("unable to lookup: \(member) in \(self)")
}
Expand Down Expand Up @@ -102,12 +104,17 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document

/// Whether variable is final or not
public var isFinal: Bool {
return modifiers.contains { $0.name == "final" }
return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

/// Whether variable is lazy or not
public var isLazy: Bool {
return modifiers.contains { $0.name == "lazy" }
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,
Expand Down Expand Up @@ -177,6 +184,7 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document
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
Expand Down
31 changes: 23 additions & 8 deletions SourcerySwift/Sources/SourceryRuntime.content.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ
case autoclosure
case convention
case mutating
case nonisolated
case isolated
case escaping
case final
case open
Expand All @@ -437,6 +439,7 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ
case privateSetter = "setter_access.private"
case fileprivateSetter = "setter_access.fileprivate"
case optional
case dynamic

public init?(identifier: String) {
let identifier = identifier.trimmingPrefix("source.decl.attribute.")
Expand Down Expand Up @@ -3992,25 +3995,25 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is a convenience initializer
public var isConvenienceInitializer: Bool {
modifiers.contains { $0.name == "convenience" }
modifiers.contains { $0.name == Attribute.Identifier.convenience.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is required
public var isRequired: Bool {
modifiers.contains { $0.name == "required" }
modifiers.contains { $0.name == Attribute.Identifier.required.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is final
public var isFinal: Bool {
modifiers.contains { $0.name == "final" }
modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

// sourcery: skipEquality, skipDescription
/// Whether method is mutating
public var isMutating: Bool {
modifiers.contains { $0.name == "mutating" }
modifiers.contains { $0.name == Attribute.Identifier.mutating.rawValue }
}

// sourcery: skipEquality, skipDescription
Expand All @@ -4022,13 +4025,19 @@ public final class Method: NSObject, SourceryModel, Annotated, Documented, Defin
// sourcery: skipEquality, skipDescription
/// Whether method is optional (in an Objective-C protocol)
public var isOptional: Bool {
modifiers.contains { $0.name == "optional" }
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 == "nonisolated" }
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
Expand Down Expand Up @@ -7461,12 +7470,17 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document

/// Whether variable is final or not
public var isFinal: Bool {
return modifiers.contains { $0.name == "final" }
return modifiers.contains { $0.name == Attribute.Identifier.final.rawValue }
}

/// Whether variable is lazy or not
public var isLazy: Bool {
return modifiers.contains { $0.name == "lazy" }
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,
Expand Down Expand Up @@ -7536,6 +7550,7 @@ public final class Variable: NSObject, SourceryModel, Typed, Annotated, Document
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
Expand Down
Loading