Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ let package = Package(
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "Logging", package: "swift-log"),
"SwiftExtractConfigurationShared",
],
path: "Sources/SwiftExtract",
Expand Down
6 changes: 5 additions & 1 deletion Sources/JExtractSwiftLib/Configuration+SwiftExtract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ import SwiftJavaConfigurationShared
/// protocol extension on `SwiftExtractConfiguration` defaults
/// `availableImportModules` and `allowUnresolvedTypeReferences`, so this
/// conformance is empty.
extension Configuration: SwiftExtractConfiguration {}
extension Configuration: SwiftExtractConfiguration {
public var unresolvedTypeHint: String? {
"If the unresolved type lives in another Swift module, declare it as a SwiftPM target dependency with its own swift-java.config (the JExtractSwiftPlugin wires --depends-on automatically), or pass --depends-on <Module>=<config-path> explicitly."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import SwiftExtract

extension SwiftQualifiedTypeName {
/// Dollar-separated for JNI C symbol parent names, e.g. "Logger$Message"
package var jniEscapedName: String { components.joined(separator: "$") }
}

extension String {
/// Returns whether the string is of the format `isX` (Java Beans boolean
/// property naming convention)
Expand Down
18 changes: 10 additions & 8 deletions Sources/SwiftExtract/SwiftAnalysisVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import Logging
import SwiftIfConfig
import SwiftParser
import SwiftSyntax
Expand Down Expand Up @@ -207,7 +206,7 @@ final class SwiftAnalysisVisitor {
)
} catch {
self.log.warning(
Self.makeMissingTypeMessage(
self.makeMissingTypeMessage(
"Failed to import: '\(node.qualifiedNameForDebug)' in module '\(analyzer.swiftModuleName)'; \(error)"
)
)
Expand Down Expand Up @@ -281,7 +280,7 @@ final class SwiftAnalysisVisitor {
}
} catch {
self.log.warning(
Self.makeMissingTypeMessage(
self.makeMissingTypeMessage(
"Failed to import: \(node.qualifiedNameForDebug) in module '\(analyzer.swiftModuleName)'; \(error)"
)
)
Expand Down Expand Up @@ -328,7 +327,7 @@ final class SwiftAnalysisVisitor {
}
} catch {
self.log.warning(
Self.makeMissingTypeMessage(
self.makeMissingTypeMessage(
"Failed to import: \(node.qualifiedNameForDebug) in module '\(analyzer.swiftModuleName)'; \(error)"
)
)
Expand Down Expand Up @@ -358,7 +357,7 @@ final class SwiftAnalysisVisitor {
)
} catch {
self.log.warning(
Self.makeMissingTypeMessage(
self.makeMissingTypeMessage(
"Failed to import: \(node.qualifiedNameForDebug) in module '\(analyzer.swiftModuleName)'; \(error)"
)
)
Expand Down Expand Up @@ -409,7 +408,7 @@ final class SwiftAnalysisVisitor {
}
} catch {
self.log.warning(
Self.makeMissingTypeMessage(
self.makeMissingTypeMessage(
"Failed to import: \(node.qualifiedNameForDebug) in module '\(analyzer.swiftModuleName)'; \(error)"
)
)
Expand Down Expand Up @@ -720,8 +719,11 @@ final class SwiftAnalysisVisitor {
return true
}

static func makeMissingTypeMessage(_ message: String) -> String {
"\(message). If the unresolved type lives in another Swift module, declare it as a SwiftPM target dependency with its own swift-java.config (the JExtractSwiftPlugin wires --depends-on automatically), or pass --depends-on <Module>=<config-path> explicitly."
func makeMissingTypeMessage(_ message: String) -> String {
guard let hint = config.unresolvedTypeHint else {
return message
}
return "\(message). \(hint)"
}
}

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftExtract/SwiftAnalyzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import Logging
import SwiftIfConfig
import SwiftParser
import SwiftSyntax
Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftExtract/SwiftExtractConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public protocol SwiftExtractConfiguration {
/// generator can declare its runtime module importable here). Default: empty.
var availableImportModules: Set<String> { get }

/// Consumer-specific guidance appended to "unresolved type" log messages,
/// e.g. pointing the user at the consumer's mechanism for declaring
/// cross-module dependencies. `nil` appends nothing.
var unresolvedTypeHint: String? { get }

/// Whether type lookups that can't resolve a name should fall back to a
/// synthetic, unresolved nominal reference instead of throwing
/// `TypeTranslationError.unknown`.
Expand Down Expand Up @@ -88,6 +93,8 @@ extension SwiftExtractConfiguration {

public var allowUnresolvedTypeReferences: Bool { false }

public var unresolvedTypeHint: String? { nil }

public func hasImportedModuleStub(moduleOfNominal moduleName: String) -> Bool {
importedModuleStubs?.keys.contains(moduleName) ?? false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import Logging
import SwiftIfConfig
import SwiftSyntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public struct SwiftQualifiedTypeName: Hashable, Sendable, CustomStringConvertibl
/// Underscore-separated for C symbols and Java identifiers, e.g. "Logger_Message"
public var fullFlatName: String { components.joined(separator: "_") }

/// Dollar-separated for JNI C symbol parent names, e.g. "Logger$Message"
public var jniEscapedName: String { components.joined(separator: "$") }

/// CustomStringConvertible - uses fullName
public var description: String { fullName }

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftExtract/SwiftTypes/SwiftSymbolTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import Logging
import SwiftIfConfig
import SwiftParser
import SwiftSyntax
Expand Down
Loading