Skip to content

Commit

Permalink
fix: automackable to support protocols with inheritedTypes and variab…
Browse files Browse the repository at this point in the history
…les with get computed properties
  • Loading branch information
Mr-T-Dev committed Nov 6, 2024
1 parent c2633b1 commit 15f5db7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [0.2.3] - 2024-11-06

### Fixed

- Allow Automackable to support protocolos with other inherited protocols
- Allow Automackable to support variables with setters
-
# [0.2.2] - 2024-11-06

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions Sources/SageSwiftKitClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ struct PlayingObject {

var identifier: Int
}



protocol Foo {
}

protocol FooA {
}

@AutoMockable()
protocol Bar: Foo, FooA {
var foo: String { set get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public enum AutoMockable: PeerMacro {
name: .identifier(procotolName)
)
)

if let inherited = protocolSyntax.inheritanceClause {
inherited.inheritedTypes
}
})
),
memberBlock: MemberBlockSyntax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ProtocolVarsConformanceBuilder {
self.variable = variable
self.accessLevel = accessLevel
}

func build() -> VariableDeclSyntax {
return VariableDeclSyntax(
modifiers: .init(itemsBuilder: {
Expand All @@ -49,12 +49,29 @@ struct ProtocolVarsConformanceBuilder {
.init(
pattern: IdentifierPatternSyntax(identifier: name.tokenSyntax),
typeAnnotation: variable.bindings.first?.typeAnnotation,
accessorBlock: AccessorBlockSyntax(
accessors: .getter(
.init(itemsBuilder: {
DeclReferenceExprSyntax(baseName: varReturnName.tokenSyntax)
})
)
accessorBlock: .init(accessors:
.accessors(
.init(
itemsBuilder: {
AccessorDeclSyntax(
accessorSpecifier: .keyword(.get),
bodyBuilder: {
ReturnStmtSyntax(
expression: DeclReferenceExprSyntax(baseName: varReturnName.tokenSyntax)
)
}
)

AccessorDeclSyntax(
accessorSpecifier: .keyword(.set),
bodyBuilder: {
.init(stringLiteral: "self.\(varReturnName) = newValue")
}
)

}
)
)
)
)
})
Expand Down

0 comments on commit 15f5db7

Please sign in to comment.