From 882a9cd964cc7141ba450c9a14ab838a0681dbbe Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 27 Feb 2026 12:01:14 +0900 Subject: [PATCH 1/2] Allow loading fully qualified type names --- .../SwiftTypes/SwiftSymbolTable.swift | 7 +++++++ .../SwiftTypes/SwiftType.swift | 2 +- .../SwiftSymbolTableTests.swift | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Sources/JExtractSwiftLib/SwiftTypes/SwiftSymbolTable.swift b/Sources/JExtractSwiftLib/SwiftTypes/SwiftSymbolTable.swift index 151aac1a..162b67e9 100644 --- a/Sources/JExtractSwiftLib/SwiftTypes/SwiftSymbolTable.swift +++ b/Sources/JExtractSwiftLib/SwiftTypes/SwiftSymbolTable.swift @@ -52,6 +52,13 @@ package class SwiftSymbolTable { self.parsedModule = parsedModule self.importedModules = importedModules } + + func isModuleName(_ name: String) -> Bool { + if name == moduleName { + return true + } + return importedModules.keys.contains(name) + } } extension SwiftSymbolTable { diff --git a/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift b/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift index bfa7d272..41bd4ba1 100644 --- a/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift +++ b/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift @@ -309,7 +309,7 @@ extension SwiftType { // FIXME: Need a more reasonable notion of which names are module names // for this to work. What can we query for this information? let parentType: SwiftType? - if memberType.baseType.trimmedDescription == "Swift" { + if lookupContext.symbolTable.isModuleName(memberType.baseType.trimmedDescription) { parentType = nil } else { parentType = try SwiftType(memberType.baseType, lookupContext: lookupContext) diff --git a/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift b/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift index eaa82da4..3c74ed02 100644 --- a/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift +++ b/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// @_spi(Testing) import JExtractSwiftLib +import SwiftJavaConfigurationShared import SwiftParser import SwiftSyntax import Testing @@ -49,4 +50,22 @@ struct SwiftSymbolTableSuite { #expect(symbolTable.lookupType("Y", parent: nil) == nil) #expect(symbolTable.lookupType("Z", parent: nil) == nil) } + + @Test(arguments: [JExtractGenerationMode.jni, .ffm]) + func resolveSelfModuleName(mode: JExtractGenerationMode) throws { + try assertOutput( + input: """ + public struct MyValue {} + + public func fullyQualifiedType() -> MyModule.MyValue + """, + mode, + .java, + swiftModuleName: "MyModule", + detectChunkByInitialLines: 1, + expectedChunks: [ + "public static MyValue fullyQualifiedType(" + ] + ) + } } From 8627938b17645cdc1f3092026f3822c48a135a60 Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 27 Feb 2026 16:13:10 +0900 Subject: [PATCH 2/2] Add case of module duplicated type name --- ...MSwift2JavaGenerator+JavaTranslation.swift | 2 +- ...ISwift2JavaGenerator+JavaTranslation.swift | 2 +- .../SwiftTypes/SwiftType.swift | 4 ++- .../SwiftSymbolTableTests.swift | 25 ++++++++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift index 5c7d8713..a066fa40 100644 --- a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift +++ b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift @@ -675,7 +675,7 @@ extension FFMSwift2JavaGenerator { throw JavaTranslationError.unhandledType(swiftType) } - let javaType: JavaType = .class(package: nil, name: swiftNominalType.nominalTypeDecl.name) + let javaType: JavaType = .class(package: nil, name: swiftNominalType.nominalTypeDecl.qualifiedName) return TranslatedResult( javaResultType: javaType, annotations: resultAnnotations, diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift index 26999878..a67ce4e3 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift @@ -788,7 +788,7 @@ extension JNISwift2JavaGenerator { } // We assume this is a JExtract class. - let javaType = JavaType.class(package: nil, name: nominalType.nominalTypeDecl.name) + let javaType = JavaType.class(package: nil, name: nominalType.nominalTypeDecl.qualifiedName) return TranslatedResult( javaType: javaType, annotations: resultAnnotations, diff --git a/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift b/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift index 41bd4ba1..8bfb7acd 100644 --- a/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift +++ b/Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift @@ -309,7 +309,9 @@ extension SwiftType { // FIXME: Need a more reasonable notion of which names are module names // for this to work. What can we query for this information? let parentType: SwiftType? - if lookupContext.symbolTable.isModuleName(memberType.baseType.trimmedDescription) { + if let base = memberType.baseType.as(IdentifierTypeSyntax.self), + lookupContext.symbolTable.isModuleName(base.name.trimmedDescription) + { parentType = nil } else { parentType = try SwiftType(memberType.baseType, lookupContext: lookupContext) diff --git a/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift b/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift index 3c74ed02..d11d5aa7 100644 --- a/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift +++ b/Tests/JExtractSwiftTests/SwiftSymbolTableTests.swift @@ -55,16 +55,39 @@ struct SwiftSymbolTableSuite { func resolveSelfModuleName(mode: JExtractGenerationMode) throws { try assertOutput( input: """ + import Foundation public struct MyValue {} public func fullyQualifiedType() -> MyModule.MyValue + public func fullyQualifiedType2() -> Foundation.Data """, mode, .java, swiftModuleName: "MyModule", detectChunkByInitialLines: 1, expectedChunks: [ - "public static MyValue fullyQualifiedType(" + "public static MyValue fullyQualifiedType(", + "public static Data fullyQualifiedType2(", + ] + ) + } + + @Test(arguments: [JExtractGenerationMode.jni, .ffm]) + func resolveSelfModuleName_moduleDuplicatedName(mode: JExtractGenerationMode) throws { + try assertOutput( + input: """ + public struct MyModule { + public struct MyValue {} + } + + public func fullyQualifiedType() -> MyModule.MyModule.MyValue + """, + mode, + .java, + swiftModuleName: "MyModule", + detectChunkByInitialLines: 1, + expectedChunks: [ + "public static MyModule.MyValue fullyQualifiedType(" ] ) }