Skip to content

Commit 10143bc

Browse files
committed
move typealiases
1 parent 0e80d82 commit 10143bc

2 files changed

Lines changed: 83 additions & 4 deletions

File tree

Sources/JExtractSwiftLib/JavaSourceDependencies.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ import FoundationEssentials
2424
import Foundation
2525
#endif
2626

27-
package typealias JavaClassName = String
28-
package typealias JavaFullyQualifiedClassName = String
29-
package typealias JavaPackageName = String
30-
3127
extension SourceDependencies {
3228
/// Inject synthetic `@JavaClass public class <Name> {}` stubs so the symbol
3329
/// table can resolve Java wrapper types referenced in the Swift API.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024-2026 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import CodePrinting
16+
import SwiftExtract
17+
18+
extension SwiftSymbolTable {
19+
package func printImportedModules(_ printer: inout CodePrinter) {
20+
let mainSymbolSourceModules = Set(
21+
self.importedModules.values.filter { $0.alternativeModules?.isMainSourceOfSymbols ?? false }.map(\.moduleName)
22+
)
23+
24+
for module in self.importedModules.keys.sorted() {
25+
guard module != "Swift" else {
26+
continue
27+
}
28+
29+
// Synthetic stub modules (e.g. <javaClassStubs>) exist purely for
30+
// symbol-table resolution; they are not real Swift modules and must
31+
// not be emitted as `import` statements.
32+
guard !self.syntheticImportedModuleNames.contains(module) else {
33+
continue
34+
}
35+
36+
guard let alternativeModules = self.importedModules[module]?.alternativeModules else {
37+
printer.print("import \(module)")
38+
continue
39+
}
40+
41+
// Only the main source of symbols emits the conditional import block.
42+
// Secondary modules (e.g. FoundationEssentials when Foundation is the main source)
43+
// are skipped when their main source is already present, because the main source's
44+
// block already covers the import. If no main source is present, fall back to a
45+
// plain import so the module is still imported.
46+
guard alternativeModules.isMainSourceOfSymbols else {
47+
if mainSymbolSourceModules.isDisjoint(with: alternativeModules.moduleNames) {
48+
printer.print("import \(module)")
49+
}
50+
continue
51+
}
52+
53+
var importGroups: [String: [String]] = [:]
54+
for name in alternativeModules.moduleNames {
55+
guard let otherModule = self.importedModules[name] else { continue }
56+
57+
let groupKey = otherModule.requiredAvailablityOfModuleWithName ?? otherModule.moduleName
58+
importGroups[groupKey, default: []].append(otherModule.moduleName)
59+
}
60+
61+
for (index, group) in importGroups.keys.sorted().enumerated() {
62+
if index > 0 && importGroups.keys.count > 1 {
63+
printer.print("#elseif canImport(\(group))")
64+
} else {
65+
printer.print("#if canImport(\(group))")
66+
}
67+
68+
for groupModule in importGroups[group] ?? [] {
69+
printer.print("import \(groupModule)")
70+
}
71+
}
72+
73+
if importGroups.keys.isEmpty {
74+
printer.print("import \(module)")
75+
} else {
76+
printer.print("#else")
77+
printer.print("import \(module)")
78+
printer.print("#endif")
79+
}
80+
}
81+
printer.println()
82+
}
83+
}

0 commit comments

Comments
 (0)