Skip to content

Commit 9e5c5a7

Browse files
committed
format all swift sources, enable format checks
1 parent e16ef46 commit 9e5c5a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+685
-442
lines changed

.github/workflows/pull_request.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ jobs:
99
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1010
with:
1111
api_breakage_check_enabled: false
12-
# FIXME: Something is off with the format task and it gets "stuck", need to investigate
13-
format_check_enabled: false
1412
license_header_check_project_name: Swift.org
1513

1614
test-java:

Samples/JavaKitSampleApp/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let package = Package(
5555
name: "JavaKitExample",
5656
type: .dynamic,
5757
targets: ["JavaKitExample"]
58-
),
58+
)
5959
],
6060

6161
dependencies: [
@@ -71,12 +71,12 @@ let package = Package(
7171
],
7272
swiftSettings: [
7373
.swiftLanguageMode(.v5),
74-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
74+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
7575
],
7676
plugins: [
7777
.plugin(name: "JavaCompilerPlugin", package: "swift-java"),
7878
.plugin(name: "Java2SwiftPlugin", package: "swift-java"),
7979
]
80-
),
80+
)
8181
]
8282
)

Sources/ExampleSwiftLibrary/MySwiftLibrary.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
// No annotations are necessary on the Swift side to perform the export.
1919

2020
#if os(Linux)
21-
import Glibc
21+
import Glibc
2222
#else
23-
import Darwin.C
23+
import Darwin.C
2424
#endif
2525

2626
public func helloWorld() {
@@ -35,7 +35,7 @@ public func globalTakeIntInt(i: Int, j: Int) {
3535
p("i:\(i), j:\(j)")
3636
}
3737

38-
public func globalCallMeRunnable(run: () -> ()) {
38+
public func globalCallMeRunnable(run: () -> Void) {
3939
run()
4040
}
4141

@@ -85,13 +85,15 @@ public func _getTypeByMangledNameInEnvironment(
8585
_ name: UnsafePointer<UInt8>,
8686
_ nameLength: UInt,
8787
genericEnvironment: UnsafeRawPointer?,
88-
genericArguments: UnsafeRawPointer?)
88+
genericArguments: UnsafeRawPointer?
89+
)
8990
-> Any.Type?
9091

91-
9292
// ==== Internal helpers
9393

94-
private func p(_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function) {
94+
private func p(
95+
_ msg: String, file: String = #fileID, line: UInt = #line, function: String = #function
96+
) {
9597
print("[swift][\(file):\(line)](\(function)) \(msg)")
9698
fflush(stdout)
9799
}

Sources/JExtractSwift/CodePrinter.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct CodePrinter {
3434
}
3535
public var indentationText: String = ""
3636

37-
public static func toString(_ block: (inout CodePrinter) -> ()) -> String {
37+
public static func toString(_ block: (inout CodePrinter) -> Void) -> String {
3838
var printer = CodePrinter()
3939
block(&printer)
4040
return printer.finalize()
@@ -66,7 +66,7 @@ public struct CodePrinter {
6666
function: String = #function,
6767
file: String = #fileID,
6868
line: UInt = #line,
69-
body: (inout CodePrinter) -> ()
69+
body: (inout CodePrinter) -> Void
7070
) {
7171
indent()
7272
print("\(text) {")
@@ -145,12 +145,16 @@ public struct CodePrinter {
145145
return contents
146146
}
147147

148-
public mutating func indent(file: String = #fileID, line: UInt = #line, function: String = #function) {
148+
public mutating func indent(
149+
file: String = #fileID, line: UInt = #line, function: String = #function
150+
) {
149151
indentationDepth += 1
150152
log.trace("Indent => \(indentationDepth)", file: file, line: line, function: function)
151153
}
152154

153-
public mutating func outdent(file: String = #fileID, line: UInt = #line, function: String = #function) {
155+
public mutating func outdent(
156+
file: String = #fileID, line: UInt = #line, function: String = #function
157+
) {
154158
indentationDepth -= 1
155159
log.trace("Outdent => \(indentationDepth)", file: file, line: line, function: function)
156160
assert(indentationDepth >= 0, "Outdent beyond zero at [\(file):\(line)](\(function))")

Sources/JExtractSwift/Convenience/Collection+Extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
public extension Dictionary {
15+
extension Dictionary {
1616
/// Same values, corresponding to mapped keys.
17-
func mapKeys<Transformed>(
17+
public func mapKeys<Transformed>(
1818
_ transform: (Key) throws -> Transformed
1919
) rethrows -> [Transformed: Value] {
2020
.init(

Sources/JExtractSwift/Convenience/String+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ extension String {
2222

2323
return "\(f.uppercased())\(String(dropFirst()))"
2424
}
25-
}
25+
}

Sources/JExtractSwift/Convenience/SwiftSyntax+Extensions.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,8 @@ extension DeclSyntaxProtocol {
7979
extension DeclModifierSyntax {
8080
var isAccessControl: Bool {
8181
switch self.name.tokenKind {
82-
case .keyword(.private): fallthrough
83-
case .keyword(.fileprivate): fallthrough
84-
case .keyword(.internal): fallthrough
85-
case .keyword(.package): fallthrough
86-
case .keyword(.public):
82+
case .keyword(.private), .keyword(.fileprivate), .keyword(.internal), .keyword(.package),
83+
.keyword(.public):
8784
return true
8885
default:
8986
return false

Sources/JExtractSwift/ImportedDecls+Printing.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import Foundation
1616
import JavaTypes
17-
import SwiftSyntax
1817
import OrderedCollections
18+
import SwiftSyntax
1919

2020
extension ImportedFunc {
2121
/// Render a `@{@snippet ... }` comment section that can be put inside a JavaDoc comment
@@ -37,8 +37,8 @@ extension VariableAccessorKind {
3737

3838
public var fieldSuffix: String {
3939
switch self {
40-
case .get: "_GET"
41-
case .set: "_SET"
40+
case .get: "_GET"
41+
case .set: "_SET"
4242
}
4343
}
4444

@@ -99,4 +99,4 @@ extension Optional where Wrapped == VariableAccessorKind {
9999
func renderMethodName(_ decl: ImportedFunc) -> String {
100100
self?.renderMethodName(decl) ?? decl.baseIdentifier
101101
}
102-
}
102+
}

Sources/JExtractSwift/ImportedDecls.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import Foundation
1616
import JavaTypes
17-
import SwiftSyntax
1817
import OrderedCollections
18+
import SwiftSyntax
1919

2020
/// Any imported (Swift) declaration
2121
protocol ImportedDecl {
@@ -36,7 +36,10 @@ public struct ImportedNominalType: ImportedDecl {
3636
public var methods: [ImportedFunc] = []
3737
public var variables: [ImportedVariable] = []
3838

39-
public init(swiftTypeName: String, javaType: JavaType, swiftMangledName: String? = nil, kind: NominalTypeKind) {
39+
public init(
40+
swiftTypeName: String, javaType: JavaType, swiftMangledName: String? = nil,
41+
kind: NominalTypeKind
42+
) {
4043
self.swiftTypeName = swiftTypeName
4144
self.javaType = javaType
4245
self.swiftMangledName = swiftMangledName
@@ -56,7 +59,7 @@ public struct ImportedNominalType: ImportedDecl {
5659
/// The Java class name without the package.
5760
public var javaClassName: String {
5861
switch javaType {
59-
case .class(package: _, name: let name): name
62+
case .class(package: _, let name): name
6063
default: javaType.description
6164
}
6265
}
@@ -250,7 +253,7 @@ public struct ImportedVariable: ImportedDecl, CustomStringConvertible {
250253
public var identifier: String
251254

252255
/// Which accessors are we able to expose.
253-
///
256+
///
254257
/// Usually this will be all the accessors the variable declares,
255258
/// however if the getter is async or throwing we may not be able to import it
256259
/// (yet), and therefore would skip it from the supported set.
@@ -285,13 +288,14 @@ public struct ImportedVariable: ImportedDecl, CustomStringConvertible {
285288

286289
switch kind {
287290
case .set:
288-
let newValueParam: FunctionParameterSyntax = "_ newValue: \(self.returnType.cCompatibleSwiftType)"
291+
let newValueParam: FunctionParameterSyntax =
292+
"_ newValue: \(self.returnType.cCompatibleSwiftType)"
289293
var funcDecl = ImportedFunc(
290294
parentName: self.parentName,
291295
identifier: self.identifier,
292296
returnType: TranslatedType.void,
293297
parameters: [.init(param: newValueParam, type: self.returnType)])
294-
funcDecl.swiftMangledName = self.swiftMangledName + "s" // form mangled name of the getter by adding the suffix
298+
funcDecl.swiftMangledName = self.swiftMangledName + "s" // form mangled name of the getter by adding the suffix
295299
return funcDecl
296300

297301
case .get:
@@ -300,21 +304,24 @@ public struct ImportedVariable: ImportedDecl, CustomStringConvertible {
300304
identifier: self.identifier,
301305
returnType: self.returnType,
302306
parameters: [])
303-
funcDecl.swiftMangledName = self.swiftMangledName + "g" // form mangled name of the getter by adding the suffix
307+
funcDecl.swiftMangledName = self.swiftMangledName + "g" // form mangled name of the getter by adding the suffix
304308
return funcDecl
305309
}
306310
}
307311

308-
public func effectiveAccessorParameters(_ kind: VariableAccessorKind, selfVariant: SelfParameterVariant?) -> [ImportedParam] {
312+
public func effectiveAccessorParameters(
313+
_ kind: VariableAccessorKind, selfVariant: SelfParameterVariant?
314+
) -> [ImportedParam] {
309315
var params: [ImportedParam] = []
310316

311317
if kind == .set {
312-
let newValueParam: FunctionParameterSyntax = "_ newValue: \(raw: self.returnType.swiftTypeName)"
318+
let newValueParam: FunctionParameterSyntax =
319+
"_ newValue: \(raw: self.returnType.swiftTypeName)"
313320
params.append(
314321
ImportedParam(
315322
param: newValueParam,
316323
type: self.returnType)
317-
)
324+
)
318325
}
319326

320327
if let parentName {

Sources/JExtractSwift/JavaType+Printing.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import Foundation
16+
import JavaTypes
1617
import SwiftBasicFormat
1718
import SwiftParser
1819
import SwiftSyntax
19-
import JavaTypes
2020

2121
extension JavaType {
2222
/// Returns a 'handle' name to pass to the `invoke` call as well as the
@@ -42,6 +42,7 @@ extension JavaType {
4242
"""
4343
}
4444

45-
fatalError("Cannot render closure downcall handle for: \(self), in: \(decl), parameter: \(parameter)")
45+
fatalError(
46+
"Cannot render closure downcall handle for: \(self), in: \(decl), parameter: \(parameter)")
4647
}
4748
}

0 commit comments

Comments
 (0)