From 354ea02a82954bc568a5afa9c7b0ffd702669e22 Mon Sep 17 00:00:00 2001 From: Angel Luis Garcia Date: Fri, 8 Nov 2019 18:50:50 +0100 Subject: [PATCH] Updated to Swift 5 --- .travis.yml | 2 +- Package.resolved | 17 +++--------- Package.swift | 7 +++-- README.md | 4 +-- Sources/SwiftKotlinApp/Info.plist | 2 +- .../KotlinTokenizer.swift | 26 +++++++++---------- .../XCTTestToJUnitTokenTransformPlugin.swift | 8 +++--- SwiftKotlinApp.xcodeproj/project.pbxproj | 5 ++-- .../project.pbxproj | 5 ++-- 9 files changed, 34 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc94253..18f88cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode10 +osx_image: xcode11.2 install: - swift package update - swift package generate-xcodeproj --enable-code-coverage diff --git a/Package.resolved b/Package.resolved index 75e1e99..c2a6a2e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,22 +1,13 @@ { "object": { "pins": [ - { - "package": "bocho", - "repositoryURL": "https://github.com/yanagiba/bocho", - "state": { - "branch": null, - "revision": "11a60ae8509658ea38bbe166d9c4e9af4d411700", - "version": "0.18.10" - } - }, { "package": "swift-ast", "repositoryURL": "https://github.com/yanagiba/swift-ast", "state": { "branch": null, - "revision": "295998ce223da98cab6b7189db22f0be3dfc0eb7", - "version": "0.18.10" + "revision": "e8507d78b32dbd33ea5ea975bbbc82b7613870a1", + "version": "0.19.9" } }, { @@ -24,8 +15,8 @@ "repositoryURL": "https://github.com/yanagiba/swift-transform", "state": { "branch": null, - "revision": "45464c7747d97f320ca153b713affede11ce3bf4", - "version": "0.18.10" + "revision": "b58a8317967099115faef82ab52d74f2b5430ef7", + "version": "0.19.9" } } ] diff --git a/Package.swift b/Package.swift index b01cbf1..3dadba6 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.1 import PackageDescription @@ -11,7 +11,7 @@ let package = Package( targets: ["SwiftKotlinFramework"] )], dependencies: [ - .package(url: "https://github.com/yanagiba/swift-transform", .exact("0.18.10")) + .package(url: "https://github.com/yanagiba/swift-transform", .exact("0.19.9")) ], targets: [ @@ -32,6 +32,5 @@ let package = Package( "SwiftKotlin.xcworkspace" ] ) - ], - swiftLanguageVersions: [4] + ] ) diff --git a/README.md b/README.md index 3c44232..eea7c35 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ The project comes with 2 executable targets: Checkout the [project's releases page](https://github.com/angelolloqui/SwiftKotlin/releases) to get a preview compiled version of the app or compile it manually: -- Install Xcode 10+ and check it is the default selected one by running `xcode-select -p` +- Install Xcode 11+ and check it is the default selected one by running `xcode-select -p` - clone the repo: `git clone git@github.com:angelolloqui/SwiftKotlin.git; cd SwiftKotlin` - Run `swift package update` and `swift package generate-xcodeproj --enable-code-coverage` - Open the project: `open SwiftKotlin.xcworkspace` @@ -145,4 +145,4 @@ And special credits for the contributors: - [jonnermut](https://github.com/jonnermut) - [Tomohiro Matsuzawa](https://github.com/thmatuza) - [Tor Langballe](https://github.com/torlangballe) -- [Levi Dahlstrom](https://github.com/LeviDahl) \ No newline at end of file +- [Levi Dahlstrom](https://github.com/LeviDahl) diff --git a/Sources/SwiftKotlinApp/Info.plist b/Sources/SwiftKotlinApp/Info.plist index 3f9bb6e..fab7ff1 100644 --- a/Sources/SwiftKotlinApp/Info.plist +++ b/Sources/SwiftKotlinApp/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.2.1 + 0.2.2 CFBundleVersion 1 LSMinimumSystemVersion diff --git a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift index fb6bef7..cde8b8c 100644 --- a/Sources/SwiftKotlinFramework/KotlinTokenizer.swift +++ b/Sources/SwiftKotlinFramework/KotlinTokenizer.swift @@ -97,7 +97,7 @@ public class KotlinTokenizer: SwiftTokenizer { members: declaration.members.filter({ !$0.isStatic })) newClass.setSourceRange(declaration.sourceRange) var tokens = super.tokenize(newClass) - if !staticMembers.isEmpty, let bodyStart = tokens.index(where: { $0.value == "{"}) { + 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")) @@ -136,14 +136,14 @@ public class KotlinTokenizer: SwiftTokenizer { .replacing({ $0.value == "struct"}, with: [declaration.newToken(.keyword, "data class")]) - if !staticMembers.isEmpty, let bodyStart = tokens.index(where: { $0.value == "{"}) { + 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.index(where: { $0.value == "{"}) { + if !declarationMembers.isEmpty, let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) { let linebreak = declaration.newToken(.linebreak, "\n") let declarationTokens: [Token] if declarationMembers.count == 1 { @@ -208,12 +208,12 @@ public class KotlinTokenizer: SwiftTokenizer { .filter { $0.isInitializer } .first - let bodyStart = tokens.index(where: { $0.node === declaration.body }) + let bodyStart = tokens.firstIndex(where: { $0.node === declaration.body }) if let bodyStart = bodyStart, let initExpression: ASTNode = superInitExpression ?? selfInitExpression, - let superIndex = tokens.index(where: { $0.node === initExpression }), - let endOfScopeIndex = tokens[superIndex...].index(where: { $0.kind == .endOfScope && $0.value == ")" }){ + let superIndex = tokens.firstIndex(where: { $0.node === initExpression }), + let endOfScopeIndex = tokens[superIndex...].firstIndex(where: { $0.kind == .endOfScope && $0.value == ")" }){ let keyword = superInitExpression != nil ? "super" : "this" let superCallTokens = Array(tokens[superIndex...endOfScopeIndex]) .replacing({ $0.node === initExpression }, with: []) @@ -252,9 +252,9 @@ public class KotlinTokenizer: SwiftTokenizer { let memberTokens = declaration.members.map { member in var tokens = tokenize(member) - let firstToken = tokens.index(where: { $0.kind != .linebreak }) ?? 0 + let firstToken = tokens.firstIndex(where: { $0.kind != .linebreak }) ?? 0 tokens.insert(contentsOf: modifierTokens, at: firstToken) - if let index = tokens.index(where: { $0.kind == .identifier }) { + if let index = tokens.firstIndex(where: { $0.kind == .identifier }) { if member.isStatic { tokens.insert(contentsOf: [declaration.newToken(.keyword, "Companion"), declaration.newToken(.delimiter, ".")], at: index) } @@ -531,7 +531,7 @@ public class KotlinTokenizer: SwiftTokenizer { open override func tokenize(_ statement: ForInStatement) -> [Token] { var tokens = super.tokenize(statement) - if let endIndex = tokens.index(where: { $0.value == "{"}) { + if let endIndex = tokens.firstIndex(where: { $0.value == "{"}) { tokens.insert(statement.newToken(.endOfScope, ")"), at: endIndex - 1) tokens.insert(statement.newToken(.startOfScope, "("), at: 2) } @@ -658,7 +658,7 @@ public class KotlinTokenizer: SwiftTokenizer { // Last return can be removed if let lastReturn = expression.statements?.last as? ReturnStatement, - let index = tokens.index(where: { $0.node === lastReturn && $0.value == "return" }) { + let index = tokens.firstIndex(where: { $0.node === lastReturn && $0.value == "return" }) { tokens.remove(at: index) tokens.remove(at: index) } @@ -666,7 +666,7 @@ public class KotlinTokenizer: SwiftTokenizer { // Other returns must be suffixed with call name if let callExpression = expression.lexicalParent as? FunctionCallExpression, let memberExpression = callExpression.postfixExpression as? ExplicitMemberExpression { - while let returnIndex = tokens.index(where: { $0.value == "return" }) { + while let returnIndex = tokens.firstIndex(where: { $0.value == "return" }) { tokens.remove(at: returnIndex) tokens.insert(expression.newToken(.keyword, "return@"), at: returnIndex) tokens.insert(expression.newToken(.identifier, memberExpression.identifier), at: returnIndex + 1) @@ -747,9 +747,9 @@ public class KotlinTokenizer: SwiftTokenizer { var elementTokens = expression.elements.map({ tokenize($0, node: expression) }) //If there is a ternary, then prefix with if - if let ternaryOperatorIndex = expression.elements.index(where: { $0.isTernaryConditionalOperator }), + if let ternaryOperatorIndex = expression.elements.firstIndex(where: { $0.isTernaryConditionalOperator }), ternaryOperatorIndex > 0 { - let assignmentIndex = expression.elements.index(where: { $0.isAssignmentOperator }) ?? -1 + let assignmentIndex = expression.elements.firstIndex(where: { $0.isAssignmentOperator }) ?? -1 let prefixTokens = [ expression.newToken(.keyword, "if"), expression.newToken(.space, " "), diff --git a/Sources/SwiftKotlinFramework/plugins/XCTTestToJUnitTokenTransformPlugin.swift b/Sources/SwiftKotlinFramework/plugins/XCTTestToJUnitTokenTransformPlugin.swift index 48a8788..6abd50a 100644 --- a/Sources/SwiftKotlinFramework/plugins/XCTTestToJUnitTokenTransformPlugin.swift +++ b/Sources/SwiftKotlinFramework/plugins/XCTTestToJUnitTokenTransformPlugin.swift @@ -57,7 +57,7 @@ public class XCTTestToJUnitTokenTransformPlugin: TokenTransformPlugin { private func removeXCTestInheritance(_ tokens: [Token], node: ClassDeclaration) -> [Token] { var newTokens = tokens - if let inheritanceIndex = newTokens.index(where: { $0.value == "XCTestCase" }) { + if let inheritanceIndex = newTokens.firstIndex(where: { $0.value == "XCTestCase" }) { newTokens.remove(at: inheritanceIndex) if (node.typeInheritanceClause?.typeInheritanceList.count ?? 0) > 1 { newTokens.remove(at: inheritanceIndex) @@ -76,7 +76,7 @@ public class XCTTestToJUnitTokenTransformPlugin: TokenTransformPlugin { var newTokens = tokens for method in testMethods { - if let firstTokenIndex = newTokens.index(where: { $0.node === method && $0.kind != .linebreak && $0.kind != .indentation }), + if let firstTokenIndex = newTokens.firstIndex(where: { $0.node === method && $0.kind != .linebreak && $0.kind != .indentation }), let lineBreakIndex = newTokens.indexOf(kind: .linebreak, before: firstTokenIndex) { let indentation = newTokens.lineIndentationToken(at: firstTokenIndex) newTokens.insert(method.newToken(.identifier, annotation), at: lineBreakIndex) @@ -92,7 +92,7 @@ public class XCTTestToJUnitTokenTransformPlugin: TokenTransformPlugin { private func removeSuperCall(_ tokens: [Token], node: FunctionDeclaration) -> [Token] { guard node.modifiers.contains(.override) else { return tokens } var newTokens = tokens - if let overrideIndex = newTokens.index(where: { $0.node === node && $0.value == "override" }) { + if let overrideIndex = newTokens.firstIndex(where: { $0.node === node && $0.value == "override" }) { newTokens.remove(at: overrideIndex) newTokens.remove(at: overrideIndex) // Remove the spacing } @@ -103,7 +103,7 @@ public class XCTTestToJUnitTokenTransformPlugin: TokenTransformPlugin { .first else { return newTokens } - guard let superIndex = newTokens.index(where: { $0.node === superCallExpression }) else { + guard let superIndex = newTokens.firstIndex(where: { $0.node === superCallExpression }) else { return newTokens } diff --git a/SwiftKotlinApp.xcodeproj/project.pbxproj b/SwiftKotlinApp.xcodeproj/project.pbxproj index c04258f..b75fe16 100644 --- a/SwiftKotlinApp.xcodeproj/project.pbxproj +++ b/SwiftKotlinApp.xcodeproj/project.pbxproj @@ -196,6 +196,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -300,7 +301,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.angelolloqui.SwiftKotlinApp; PRODUCT_NAME = SwiftKotlin; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -353,7 +354,7 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.angelolloqui.SwiftKotlinApp; PRODUCT_NAME = SwiftKotlin; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/SwiftKotlinCommandLine.xcodeproj/project.pbxproj b/SwiftKotlinCommandLine.xcodeproj/project.pbxproj index 4c415e8..3549ddd 100644 --- a/SwiftKotlinCommandLine.xcodeproj/project.pbxproj +++ b/SwiftKotlinCommandLine.xcodeproj/project.pbxproj @@ -176,6 +176,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -215,7 +216,7 @@ OTHER_SWIFT_FLAGS = "$(inherited)"; SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGET_NAME = swiftkotlin; }; name = Debug; @@ -234,7 +235,7 @@ OTHER_SWIFT_FLAGS = "$(inherited)"; SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES; SWIFT_FORCE_STATIC_LINK_STDLIB = NO; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGET_NAME = swiftkotlin; }; name = Release;