Skip to content

Commit d06c172

Browse files
committed
fix boolean naming
1 parent a82196e commit d06c172

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

Sources/JExtractSwiftLib/Convenience/String+Extensions.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
extension String {
1616

17-
// TODO: naive implementation good enough for our simple case `methodMethodSomething` -> `MethodSomething`
18-
var toCamelCase: String {
17+
var firstCharacterUppercased: String {
1918
guard let f = first else {
2019
return self
2120
}

Sources/JExtractSwiftLib/ImportedDecls.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ extension ImportedFunc {
160160
let returnsBoolean = self.functionSignature.result.type.asNominalTypeDeclaration?.knownTypeKind == .bool
161161

162162
if !returnsBoolean {
163-
return "get\(self.name.toCamelCase)"
163+
return "get\(self.name.firstCharacterUppercased)"
164164
} else if !self.name.hasJavaBooleanNamingConvention {
165-
return "is\(self.name.toCamelCase)"
165+
return "is\(self.name.firstCharacterUppercased)"
166166
} else {
167-
return self.name.toCamelCase
167+
return self.name
168168
}
169169
}
170170

171171
var javaSetterName: String {
172-
"set\(self.name.toCamelCase)"
172+
"set\(self.name.firstCharacterUppercased)"
173173
}
174174
}

Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ struct JNIVariablesTests {
411411
}
412412

413413
@Test
414-
func boolean_swiftThunks() throws {
414+
func someBoolean_swiftThunks() throws {
415415
try assertOutput(
416416
input: membersSource,
417417
.jni,
@@ -450,4 +450,58 @@ struct JNIVariablesTests {
450450
]
451451
)
452452
}
453+
454+
@Test
455+
func isBoolean_javaBindings() throws {
456+
try assertOutput(
457+
input: membersSource,
458+
.jni,
459+
.java,
460+
detectChunkByInitialLines: 8,
461+
expectedChunks: [
462+
"""
463+
/**
464+
* Downcall to Swift:
465+
* {@snippet lang=swift :
466+
* public let isBoolean: Bool
467+
* }
468+
*/
469+
public boolean isBoolean() {
470+
long self$ = this.$memoryAddress();
471+
return MyClass.$isBoolean(self$);
472+
}
473+
""",
474+
"""
475+
private static native boolean $isBoolean(long selfPointer);
476+
""",
477+
]
478+
)
479+
}
480+
481+
@Test
482+
func isBoolean_swiftThunks() throws {
483+
try assertOutput(
484+
input: membersSource,
485+
.jni,
486+
.swift,
487+
detectChunkByInitialLines: 1,
488+
expectedChunks: [
489+
"""
490+
@_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J")
491+
func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) -> jboolean {
492+
guard let env$ = environment else {
493+
fatalError("Missing JNIEnv in downcall to \\(#function)")
494+
}
495+
assert(selfPointer != 0, "selfPointer memory address was null")
496+
let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$))
497+
guard let self$ = UnsafeMutablePointer<MyClass>(bitPattern: selfBits$) else {
498+
fatalError("self memory address was null in call to \\(#function)!")
499+
}
500+
let result = self$.pointee.isBoolean
501+
return result.getJNIValue(in: environment)
502+
}
503+
""",
504+
]
505+
)
506+
}
453507
}

0 commit comments

Comments
 (0)