From 7d1c0bf996a628a657ce2b29037b8ef42813540c Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 17:13:31 +0100 Subject: [PATCH 1/6] Fixed issue converting lists --- Assets/Tests/KotlinTokenizer/foundation_types.kt | 1 + Assets/Tests/KotlinTokenizer/foundation_types.swift | 1 + Sources/SwiftKotlinFramework/KotlinTokenizer.swift | 9 ++++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Assets/Tests/KotlinTokenizer/foundation_types.kt b/Assets/Tests/KotlinTokenizer/foundation_types.kt index 433442a..c249deb 100644 --- a/Assets/Tests/KotlinTokenizer/foundation_types.kt +++ b/Assets/Tests/KotlinTokenizer/foundation_types.kt @@ -12,3 +12,4 @@ var map: Promise>? = null var map: Map>> var map = mapOf(1 to "a", 2 to "b") var map = mapOf() +method(value = listOf("value1", "value")) diff --git a/Assets/Tests/KotlinTokenizer/foundation_types.swift b/Assets/Tests/KotlinTokenizer/foundation_types.swift index 6ed5a3e..236fac2 100644 --- a/Assets/Tests/KotlinTokenizer/foundation_types.swift +++ b/Assets/Tests/KotlinTokenizer/foundation_types.swift @@ -12,3 +12,4 @@ var map: Promise<[Int: String]>? var map: [Int: Promise<[String: String]>] var map = [1: "a", 2: "b"] var map = [String: String]() +method(value: ["value1", "value"]) diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index 3ab998b..e4b0a73 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -588,12 +588,11 @@ public class KotlinTokenizer: SwiftTokenizer { case let .staticString(_, rawText): return [expression.newToken(.string, conversionUnicodeString(rawText, node: expression))] case .array(let exprs): - let isGenericTypeInfo = expression.lexicalParent is FunctionCallExpression - return - expression.newToken(.identifier, "listOf") + - expression.newToken(.startOfScope, isGenericTypeInfo ? "<" : "(") + + let isGenericTypeInfo = (expression.lexicalParent as? FunctionCallExpression)?.postfixExpression.textDescription.starts(with: "[") == true + return expression.newToken(.identifier, "listOf") + + expression.newToken(.startOfScope, isGenericTypeInfo ? "<" : "(") + exprs.map { tokenize($0) }.joined(token: expression.newToken(.delimiter, ", ")) + - expression.newToken(.endOfScope, isGenericTypeInfo ? ">" : ")") + expression.newToken(.endOfScope, isGenericTypeInfo ? ">" : ")") case .dictionary(let entries): let isGenericTypeInfo = expression.lexicalParent is FunctionCallExpression var entryTokens = entries.map { tokenize($0, node: expression) }.joined(token: expression.newToken(.delimiter, ", ")) From 158cd9473f6271a85b83eaf995087b0333378ce7 Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 17:39:54 +0100 Subject: [PATCH 2/6] #101 Fixed type inheritance on structs --- Assets/Tests/KotlinTokenizer/structs.kt | 8 +++++++ Assets/Tests/KotlinTokenizer/structs.swift | 9 +++++++ .../KotlinTokenizer.swift | 24 ++++++++++++------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Assets/Tests/KotlinTokenizer/structs.kt b/Assets/Tests/KotlinTokenizer/structs.kt index 0d3fdcb..130045b 100644 --- a/Assets/Tests/KotlinTokenizer/structs.kt +++ b/Assets/Tests/KotlinTokenizer/structs.kt @@ -8,3 +8,11 @@ data class Person( fun eat() {} } + +data class User( + var id: Int? = 0, + var name: String? = null, + var content: Content): Codable { + + data class Content(val text: String) {} +} diff --git a/Assets/Tests/KotlinTokenizer/structs.swift b/Assets/Tests/KotlinTokenizer/structs.swift index 959319f..a640cfd 100644 --- a/Assets/Tests/KotlinTokenizer/structs.swift +++ b/Assets/Tests/KotlinTokenizer/structs.swift @@ -9,3 +9,12 @@ struct Person { func eat() {} } + +struct User: Codable { + struct Content { + let text: String + } + var id: Int? = 0 + var name: String? + var content: Content +} diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index e4b0a73..3b52253 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -127,7 +127,7 @@ public class KotlinTokenizer: SwiftTokenizer { accessLevelModifier: declaration.accessLevelModifier, name: declaration.name, genericParameterClause: declaration.genericParameterClause, - typeInheritanceClause: declaration.typeInheritanceClause, + typeInheritanceClause: nil, genericWhereClause: declaration.genericWhereClause, members: otherMembers) newStruct.setSourceRange(declaration.sourceRange) @@ -136,13 +136,6 @@ public class KotlinTokenizer: SwiftTokenizer { .replacing({ $0.value == "struct"}, with: [declaration.newToken(.keyword, "data class")]) - if !staticMembers.isEmpty, let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { - let companionTokens = indent(tokenizeCompanion(staticMembers, node: declaration)) - .prefix(with: declaration.newToken(.linebreak, "\n")) - .suffix(with: declaration.newToken(.linebreak, "\n")) - tokens.insert(contentsOf: companionTokens, at: bodyStart + 1) - } - if !declarationMembers.isEmpty, let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { let linebreak = declaration.newToken(.linebreak, "\n") let declarationTokens: [Token] @@ -166,6 +159,21 @@ public class KotlinTokenizer: SwiftTokenizer { at: bodyStart - 1) } + if let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList, + !typeInheritanceList.isEmpty, + let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { + let clause = TypeInheritanceClause(classRequirement: false, typeInheritanceList: typeInheritanceList) + let inheritanceTokens = tokenize(clause, node: declaration) + tokens.insert(contentsOf: inheritanceTokens, at: bodyStart - 1) + } + + if !staticMembers.isEmpty, let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { + let companionTokens = indent(tokenizeCompanion(staticMembers, node: declaration)) + .prefix(with: declaration.newToken(.linebreak, "\n")) + .suffix(with: declaration.newToken(.linebreak, "\n")) + tokens.insert(contentsOf: companionTokens, at: bodyStart + 1) + } + return tokens } From 4b20e0c119c17d095390c3cf2ef620e21e670e4f Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 17:48:39 +0100 Subject: [PATCH 3/6] Updated travis Xcode --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18f88cb..05a2632 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode11.2 +osx_image: xcode11.3 install: - swift package update - swift package generate-xcodeproj --enable-code-coverage From 62d9ed70dc691b7066ec3238600533c1e4830d50 Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 18:05:32 +0100 Subject: [PATCH 4/6] #108 Fixed equatable enums --- Assets/Tests/KotlinTokenizer/enums.swift | 2 +- Sources/SwiftKotlinFramework/KotlinTokenizer.swift | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Assets/Tests/KotlinTokenizer/enums.swift b/Assets/Tests/KotlinTokenizer/enums.swift index 0752ba9..32f26b5 100644 --- a/Assets/Tests/KotlinTokenizer/enums.swift +++ b/Assets/Tests/KotlinTokenizer/enums.swift @@ -6,7 +6,7 @@ enum CompassPoint { case west } -private enum Planet { +private enum Planet: Equatable { case mercury, venus, earth case mars, jupiter, saturn, uranus, neptune } diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index 3b52253..692c851 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -439,8 +439,11 @@ public class KotlinTokenizer: SwiftTokenizer { // Simple enums (no tuple values) if !simpleCases.contains(where: { $0.tuple != nil }) { - if declaration.typeInheritanceClause != nil { - return tokenizeSimpleValueEnum(declaration:declaration, simpleCases: simpleCases) + let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.filter { + $0.names.contains { $0.name.textDescription != "Equatable" } + } + if typeInheritanceList?.isEmpty == false { + return tokenizeSimpleValueEnum(declaration: declaration, simpleCases: simpleCases) } else { return tokenizeNoValueEnum(declaration: declaration, simpleCases: simpleCases) } From 08db8c0c440fa8a2abc6b9f1de0c7adec9aecf8f Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 18:20:36 +0100 Subject: [PATCH 5/6] #110 Equatable structs should not include type inheritance --- Assets/Tests/KotlinTokenizer/structs.swift | 2 +- Sources/SwiftKotlinFramework/KotlinTokenizer.swift | 8 +++----- Sources/SwiftKotlinFramework/utils/AST+Operations.swift | 7 +++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Assets/Tests/KotlinTokenizer/structs.swift b/Assets/Tests/KotlinTokenizer/structs.swift index a640cfd..9c48c54 100644 --- a/Assets/Tests/KotlinTokenizer/structs.swift +++ b/Assets/Tests/KotlinTokenizer/structs.swift @@ -2,7 +2,7 @@ struct Data { var text: String } -struct Person { +struct Person: Equatable { let name: String let surname: String var age: Int diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index 692c851..84cbe1a 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -159,8 +159,8 @@ public class KotlinTokenizer: SwiftTokenizer { at: bodyStart - 1) } - if let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList, - !typeInheritanceList.isEmpty, + if let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.nonEquatable, + typeInheritanceList.isEmpty == false, let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { let clause = TypeInheritanceClause(classRequirement: false, typeInheritanceList: typeInheritanceList) let inheritanceTokens = tokenize(clause, node: declaration) @@ -439,9 +439,7 @@ public class KotlinTokenizer: SwiftTokenizer { // Simple enums (no tuple values) if !simpleCases.contains(where: { $0.tuple != nil }) { - let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.filter { - $0.names.contains { $0.name.textDescription != "Equatable" } - } + let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.nonEquatable if typeInheritanceList?.isEmpty == false { return tokenizeSimpleValueEnum(declaration: declaration, simpleCases: simpleCases) } else { diff --git a/Sources/SwiftKotlinFramework/utils/AST+Operations.swift b/Sources/SwiftKotlinFramework/utils/AST+Operations.swift index 0435185..8998b19 100644 --- a/Sources/SwiftKotlinFramework/utils/AST+Operations.swift +++ b/Sources/SwiftKotlinFramework/utils/AST+Operations.swift @@ -273,3 +273,10 @@ extension GuardStatement { (bodyStatement is ReturnStatement || bodyStatement is ThrowStatement) } } + +extension Collection where Iterator.Element == TypeIdentifier { + var nonEquatable: [TypeIdentifier] { + return filter { $0.names.contains { $0.name.textDescription != "Equatable" } } + } +} + From 3a8ccaf53049caff4025be0f49b461cde83e993b Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Sat, 21 Mar 2020 18:26:02 +0100 Subject: [PATCH 6/6] Version bump --- Sources/SwiftKotlinApp/Info.plist | 2 +- Sources/SwiftKotlinCommandLine/main.swift | 4 ++-- SwiftKotlinApp.xcodeproj/project.pbxproj | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftKotlinApp/Info.plist b/Sources/SwiftKotlinApp/Info.plist index fab7ff1..fc45ba4 100644 --- a/Sources/SwiftKotlinApp/Info.plist +++ b/Sources/SwiftKotlinApp/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.2.2 + $(MARKETING_VERSION) CFBundleVersion 1 LSMinimumSystemVersion diff --git a/Sources/SwiftKotlinCommandLine/main.swift b/Sources/SwiftKotlinCommandLine/main.swift index 4304141..c042c61 100644 --- a/Sources/SwiftKotlinCommandLine/main.swift +++ b/Sources/SwiftKotlinCommandLine/main.swift @@ -16,7 +16,7 @@ let kotlinTokenizer = KotlinTokenizer( CommentsAdditionTransformPlugin() ] ) -let version = "0.2.1" +let version = "0.2.3" let arguments = [ "output", "help", @@ -26,7 +26,7 @@ let arguments = [ func showHelp() { print("swiftkotlin, version \(version)") - print("copyright (c) 2019 Angel G. Olloqui") + print("copyright (c) 2020 Angel G. Olloqui") print("") print("usage: swiftkotlin [] [--output path]") print("") diff --git a/SwiftKotlinApp.xcodeproj/project.pbxproj b/SwiftKotlinApp.xcodeproj/project.pbxproj index b75fe16..68938c0 100644 --- a/SwiftKotlinApp.xcodeproj/project.pbxproj +++ b/SwiftKotlinApp.xcodeproj/project.pbxproj @@ -297,6 +297,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftKotlinApp/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; + MARKETING_VERSION = 0.2.3; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = com.angelolloqui.SwiftKotlinApp; PRODUCT_NAME = SwiftKotlin; @@ -351,6 +352,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Sources/SwiftKotlinApp/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; + MARKETING_VERSION = 0.2.3; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.angelolloqui.SwiftKotlinApp; PRODUCT_NAME = SwiftKotlin;