File tree Expand file tree Collapse file tree 4 files changed +36
-6
lines changed Expand file tree Collapse file tree 4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,32 @@ extension String {
22
22
23
23
return " \( f. uppercased ( ) ) \( String ( dropFirst ( ) ) ) "
24
24
}
25
- }
25
+
26
+ /// Returns whether the string is of the format `isX`
27
+ private var hasJavaBooleanNamingConvention : Bool {
28
+ guard self . hasPrefix ( " is " ) , self . count > 2 else {
29
+ return false
30
+ }
31
+
32
+ let thirdCharacterIndex = self . index ( self . startIndex, offsetBy: 2 )
33
+ return self [ thirdCharacterIndex] . isUppercase
34
+ }
35
+
36
+ func javaGetterName( isBoolean: Bool ) -> String {
37
+ if !isBoolean {
38
+ return " get \( self . toCamelCase) "
39
+ } else if !hasJavaBooleanNamingConvention {
40
+ return " is \( self . toCamelCase) "
41
+ } else {
42
+ return self . toCamelCase
43
+ }
44
+ }
45
+
46
+ func javaSetterName( isBoolean: Bool ) -> String {
47
+ if !isBoolean || !hasJavaBooleanNamingConvention {
48
+ return " set \( self . toCamelCase) "
49
+ } else {
50
+ return " setIs \( self . toCamelCase) "
51
+ }
52
+ }
53
+ }
Original file line number Diff line number Diff line change @@ -126,9 +126,10 @@ extension FFMSwift2JavaGenerator {
126
126
let loweredSignature = try lowering. lowerFunctionSignature ( decl. functionSignature)
127
127
128
128
// Name.
129
+ let returnsBoolean = decl. functionSignature. result. type. asNominalTypeDeclaration? . knownTypeKind == . bool
129
130
let javaName = switch decl. apiKind {
130
- case . getter: " get \( decl. name. toCamelCase ) "
131
- case . setter: " set \( decl. name. toCamelCase ) "
131
+ case . getter: decl. name. javaGetterName ( isBoolean : returnsBoolean )
132
+ case . setter: decl. name. javaSetterName ( isBoolean : returnsBoolean )
132
133
case . function, . initializer: decl. name
133
134
}
134
135
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ public final class ImportedFunc: ImportedDecl, CustomStringConvertible {
91
91
}
92
92
return false
93
93
}
94
-
94
+
95
95
/// If this function/method is member of a class/struct/protocol,
96
96
/// this will contain that declaration's imported name.
97
97
///
Original file line number Diff line number Diff line change @@ -38,9 +38,10 @@ extension JNISwift2JavaGenerator {
38
38
let parentName = decl. parentType? . asNominalType? . nominalTypeDecl. qualifiedName ?? swiftModuleName
39
39
40
40
// Name.
41
+ let returnsBoolean = translatedFunctionSignature. resultType == . boolean
41
42
let javaName = switch decl. apiKind {
42
- case . getter: " get \( decl. name. toCamelCase ) "
43
- case . setter: " set \( decl. name. toCamelCase ) "
43
+ case . getter: decl. name. javaGetterName ( isBoolean : returnsBoolean )
44
+ case . setter: decl. name. javaSetterName ( isBoolean : returnsBoolean )
44
45
case . function, . initializer: decl. name
45
46
}
46
47
You can’t perform that action at this time.
0 commit comments