File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515public enum EnumWithValueCases {
1616 case firstCase( UInt )
17+ case secondCase
1718}
Original file line number Diff line number Diff line change @@ -28,4 +28,8 @@ enum JNICaching {
2828 static func cacheMemberName( for enumCase: ImportedEnumCase ) -> String {
2929 " \( enumCase. enumType. nominalTypeDecl. name. firstCharacterLowercased) \( enumCase. name. firstCharacterUppercased) Cache "
3030 }
31+
32+ static func cacheMemberName( for translatedEnumCase: JNISwift2JavaGenerator . TranslatedEnumCase ) -> String {
33+ cacheMemberName ( for: translatedEnumCase. original)
34+ }
3135}
Original file line number Diff line number Diff line change @@ -506,10 +506,10 @@ extension JNISwift2JavaGenerator {
506506 // Print record
507507 printer. printBraceBlock ( " public record \( caseName) ( \( members. joined ( separator: " , " ) ) ) implements Case " ) {
508508 printer in
509- let nativeParameters = zip ( translatedCase. translatedValues, translatedCase. parameterConversions) . flatMap {
509+ let nativeParameters = zip ( translatedCase. translatedValues, translatedCase. parameterConversions) . map {
510510 value,
511511 conversion in
512- [ " \( conversion. native. javaType) \( value. parameter. name) " ]
512+ " \( conversion. native. javaType) \( value. parameter. name) "
513513 }
514514
515515 printer. print ( " record _NativeParameters( \( nativeParameters. joined ( separator: " , " ) ) ) {} " )
Original file line number Diff line number Diff line change @@ -174,11 +174,17 @@ extension JNISwift2JavaGenerator {
174174 }
175175
176176 private func printJNICache( _ printer: inout CodePrinter, _ type: ImportedNominalType) {
177+ let targetCases = type. cases
178+ . compactMap ( translatedEnumCase ( for: ) )
179+ . filter { !$0. translatedValues. isEmpty }
180+ if targetCases. isEmpty {
181+ return
182+ }
183+
177184 printer. printBraceBlock ( " enum \( JNICaching . cacheName ( for: type) ) " ) { printer in
178- for enumCase in type. cases {
179- guard let translatedCase = translatedEnumCase ( for: enumCase) else { continue }
185+ for translatedCase in targetCases {
180186 printer. print (
181- " static let \( JNICaching . cacheMemberName ( for: enumCase ) ) = \( renderEnumCaseCacheInit ( translatedCase) ) "
187+ " static let \( JNICaching . cacheMemberName ( for: translatedCase ) ) = \( renderEnumCaseCacheInit ( translatedCase) ) "
182188 )
183189 }
184190 }
Original file line number Diff line number Diff line change @@ -305,6 +305,12 @@ struct JNIEnumTests {
305305 . swift,
306306 detectChunkByInitialLines: 1 ,
307307 expectedChunks: [
308+ """
309+ enum _JNI_MyEnum {
310+ static let myEnumSecondCache = _JNIMethodIDCache(className: " com/example/swift/MyEnum$Second$_NativeParameters " , methods: [.init(name: " <init> " , signature: " (Ljava/lang/String;)V " )])
311+ static let myEnumThirdCache = _JNIMethodIDCache(className: " com/example/swift/MyEnum$Third$_NativeParameters " , methods: [.init(name: " <init> " , signature: " (JI)V " )])
312+ }
313+ """ ,
308314 """
309315 @_cdecl( " Java_com_example_swift_MyEnum__00024getAsSecond__J " )
310316 public func Java_com_example_swift_MyEnum__00024getAsSecond__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) -> jobject? {
@@ -335,6 +341,36 @@ struct JNIEnumTests {
335341 return environment.interface.NewObjectA(environment, class$, constructorID$, newObjectArgs$)
336342 }
337343 """ ,
344+ ] ,
345+ notExpectedChunks: [
346+ " public func Java_com_example_swift_MyEnum__00024getAsFirst__J( "
347+ ]
348+ )
349+ }
350+
351+ @Test
352+ func nonGeneratesGetAsCase_swift( ) throws {
353+ try assertOutput (
354+ input: """
355+ public enum MyEnum {
356+ case first
357+ case second
358+ }
359+ """ ,
360+ . jni,
361+ . swift,
362+ detectChunkByInitialLines: 1 ,
363+ expectedChunks: [ ] ,
364+ notExpectedChunks: [
365+ """
366+ enum _JNI_MyEnum
367+ """ ,
368+ """
369+ public func Java_com_example_swift_MyEnum__00024getAsFirst__J( "
370+ """ ,
371+ """
372+ public func Java_com_example_swift_MyEnum__00024getAsSecond__J(
373+ """ ,
338374 ]
339375 )
340376 }
You can’t perform that action at this time.
0 commit comments