diff --git a/Assets/Tests/KotlinTokenizer/expressions.kt b/Assets/Tests/KotlinTokenizer/expressions.kt index 53855a1..f3bee3b 100644 --- a/Assets/Tests/KotlinTokenizer/expressions.kt +++ b/Assets/Tests/KotlinTokenizer/expressions.kt @@ -6,3 +6,5 @@ val text = label ?: "default" service.deleteObject() this.service.fetchData()?.user?.name?.size this.data.filter { it.item?.value == 1 }.map { it.key }.firstOrNull()?.name?.size +this.object = data as ObjectType +this.object = data as? ObjectType diff --git a/Assets/Tests/KotlinTokenizer/expressions.swift b/Assets/Tests/KotlinTokenizer/expressions.swift index fdaa343..7510ead 100644 --- a/Assets/Tests/KotlinTokenizer/expressions.swift +++ b/Assets/Tests/KotlinTokenizer/expressions.swift @@ -12,3 +12,7 @@ _ = service.deleteObject() // Optional chaning self.service.fetchData()?.user.name?.count self.data.filter { $0.item?.value == 1 }.map { $0.key }.first?.name.count + +// Type casting +self.object = data as! ObjectType +self.object = data as? ObjectType diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index 1712163..1149b74 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -833,6 +833,20 @@ public class KotlinTokenizer: SwiftTokenizer { } return tokens } + + open override func tokenize(_ expression: TypeCastingOperatorExpression) -> [Token] { + switch expression.kind { + case let .forcedCast(expr, type): + return [ + tokenize(expr), + [expression.newToken(.keyword, "as")], + tokenize(type, node: expression) + ].joined(token: expression.newToken(.space, " ")) + default: + return super.tokenize(expression) + } + } + // MARK: - Types open override func tokenize(_ type: ArrayType, node: ASTNode) -> [Token] {