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
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public enum NamespaceEnum {
public enum Nested {
public static func something() {}
}

public struct NestedGenericType<T> {
public var value: Int
}
}
2 changes: 1 addition & 1 deletion Sources/JExtractSwiftLib/ImportedDecls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ package final class ImportedNominalType: ImportedDecl {
}

var swiftType: SwiftType {
.nominal(.init(nominalTypeDecl: swiftNominal))
swiftNominal.asSwiftType
}

/// Structured Java-facing type name — "FishBox" for specialized, "Box" for base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ extension JNISwift2JavaGenerator {
}

private func openerProtocolName(for type: SwiftNominalTypeDeclaration) -> String {
"_\(swiftModuleName)_\(type.name)_opener"
"_\(swiftModuleName)_\(type.flatName)_opener"
}

private func printOpenerProtocol(_ printer: inout CodePrinter, _ type: ImportedNominalType) {
Expand Down Expand Up @@ -969,7 +969,7 @@ extension JNISwift2JavaGenerator {
}
}
printer.println()
printer.printBraceBlock("extension \(type.swiftNominal.name): \(protocolName)") { printer in
printer.printBraceBlock("extension \(type.swiftNominal.qualifiedName): \(protocolName)") { printer in
for variable in type.variables {
if variable.isStatic { continue }
printFunctionDecl(&printer, decl: variable, skipMethodBody: false)
Expand Down
15 changes: 15 additions & 0 deletions Sources/JExtractSwiftLib/SwiftTypes/SwiftType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,18 @@ enum TypeTranslationError: Error {
/// Unknown nominal type.
case unknown(TypeSyntax, file: StaticString = #file, line: Int = #line)
}

extension SwiftNominalTypeDeclaration {
var asSwiftNominalType: SwiftNominalType {
let genericArguments = genericParameters.map { SwiftType.genericParameter($0) }
return SwiftNominalType(
parent: parent?.asSwiftNominalType,
nominalTypeDecl: self,
genericArguments: genericArguments.isEmpty ? nil : genericArguments
)
}

var asSwiftType: SwiftType {
.nominal(asSwiftNominalType)
}
}
36 changes: 34 additions & 2 deletions Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct JNIGenericTypeTests {
static func _get_description(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) -> jstring? {
assert(selfPointer != 0, "selfPointer memory address was null")
let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment))
let selfPointer$ = UnsafeMutablePointer<MyID>(bitPattern: selfPointerBits$)
let selfPointer$ = UnsafeMutablePointer<MyID<T>>(bitPattern: selfPointerBits$)
guard let selfPointer$ else {
fatalError("selfPointer memory address was null in call to \(#function)!")
}
Expand Down Expand Up @@ -239,7 +239,6 @@ struct JNIGenericTypeTests {
]
)


try assertOutput(
input: input,
.jni,
Expand All @@ -253,6 +252,39 @@ struct JNIGenericTypeTests {
)
}

@Test
func nestedGenericType() throws {
let input =
#"""
public enum Foo {
public struct Bar<T> {
public func work() {}
}
}
"""#

try assertOutput(
input: input,
.jni,
.swift,
detectChunkByInitialLines: 1,
expectedChunks: [
#"""
extension Foo.Bar: _SwiftModule_Foo_Bar_opener {
static func _work(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) {
...
let selfPointer$ = UnsafeMutablePointer<Foo.Bar<T>>(bitPattern: selfPointerBits$)
guard let selfPointer$ else {
fatalError("selfPointer memory address was null in call to \(#function)!")
}
selfPointer$.pointee.work()
}
}
"""#
],
)
}

@Test("Constrained extensions are ignored")
func constrainedExtensionsAreIgnored() throws {
let input =
Expand Down
Loading