-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lazar Otasevic
committed
Sep 5, 2024
1 parent
6e9b298
commit c3331a2
Showing
9 changed files
with
153 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
protocol ReflectionElement { | ||
var node: ReflectionNode { get } | ||
init(node: ReflectionNode) | ||
static func isValid(_ node: ReflectionNode) -> Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,46 @@ | ||
struct TypeDerivedElement<T>: ReflectionElement { | ||
let node: ReflectionNode | ||
import SwiftUI | ||
|
||
protocol TypeDerivedElement: ReflectionElement { | ||
associatedtype RelatedType | ||
} | ||
|
||
extension TypeDerivedElement { | ||
static var typeInfo: TypeInfo { TypeInfo(type: T.self) } | ||
|
||
static func isSameType(_ node: ReflectionNode) -> Bool { | ||
node.object is T | ||
} | ||
|
||
static func isSameBasetype(_ node: ReflectionNode) -> Bool { | ||
node.typeInfo.baseTypename == typeInfo.baseTypename | ||
} | ||
|
||
static func isSameClosure(_ node: ReflectionNode) -> Bool { | ||
node.typeInfo.typename.hasSuffix(typeInfo.typename) | ||
} | ||
|
||
var castValue: T { | ||
CastingUtils.memoryCast(node.object) | ||
static var typeInfo: TypeInfo { TypeInfo(type: RelatedType.self) } | ||
} | ||
|
||
protocol CastableTypeDerivedElement: TypeDerivedElement { | ||
var castValue: RelatedType { get } | ||
} | ||
|
||
extension CastableTypeDerivedElement { | ||
var castValue: RelatedType { CastingUtils.memoryCast(node.object) } | ||
} | ||
|
||
struct SameBaseElement<T>: TypeDerivedElement { | ||
let node: ReflectionNode | ||
typealias RelatedType = T | ||
static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.baseTypename == typeInfo.baseTypename } | ||
} | ||
|
||
protocol ModifierDerivedElement: ReflectionElement { | ||
static func makeModifiedContent() -> Any | ||
} | ||
|
||
extension ModifierDerivedElement { | ||
static func isValid(_ node: ReflectionNode) -> Bool { | ||
let modChild = ReflectionNode(object: makeModifiedContent()).children[1] | ||
return node.typeInfo.typename == modChild.typeInfo.typename | ||
} | ||
} | ||
|
||
struct SameTypeElement<T>: CastableTypeDerivedElement { | ||
let node: ReflectionNode | ||
typealias RelatedType = T | ||
static func isValid(_ node: ReflectionNode) -> Bool { node.object is T } | ||
} | ||
|
||
struct ClosureElement<T>: CastableTypeDerivedElement { | ||
let node: ReflectionNode | ||
typealias RelatedType = T | ||
static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.typename.hasSuffix(typeInfo.typename) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.