Skip to content

Commit

Permalink
Merge pull request #102 from angelolloqui/feature/swift-update
Browse files Browse the repository at this point in the history
Updated to Swift 5
  • Loading branch information
angelolloqui authored Nov 8, 2019
2 parents e993ad5 + 354ea02 commit ec5a7f5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 4 additions & 13 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
{
"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"
}
},
{
"package": "swift-transform",
"repositoryURL": "https://github.com/yanagiba/swift-transform",
"state": {
"branch": null,
"revision": "45464c7747d97f320ca153b713affede11ce3bf4",
"version": "0.18.10"
"revision": "b58a8317967099115faef82ab52d74f2b5430ef7",
"version": "0.19.9"
}
}
]
Expand Down
7 changes: 3 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:5.1


import PackageDescription
Expand All @@ -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: [

Expand All @@ -32,6 +32,5 @@ let package = Package(
"SwiftKotlin.xcworkspace"
]
)
],
swiftLanguageVersions: [4]
]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)
- [Levi Dahlstrom](https://github.com/LeviDahl)
2 changes: 1 addition & 1 deletion Sources/SwiftKotlinApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2.1</string>
<string>0.2.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down
26 changes: 13 additions & 13 deletions Sources/SwiftKotlinFramework/KotlinTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: [])
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -658,15 +658,15 @@ 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)
}

// 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)
Expand Down Expand Up @@ -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, " "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions SwiftKotlinApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};
Expand Down
5 changes: 3 additions & 2 deletions SwiftKotlinCommandLine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ec5a7f5

Please sign in to comment.