File tree Expand file tree Collapse file tree 7 files changed +418
-25
lines changed Expand file tree Collapse file tree 7 files changed +418
-25
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ public class MySwiftClass {
3434 mutable = newValue * 2
3535 }
3636 }
37+ public let warm : Bool = false
3738
3839 public static func method( ) {
3940 p ( " Hello from static method in a class! " )
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ static void examples() {
4545 MySwiftClass myClass = MySwiftClass .init (10 , 5 , arena );
4646 MySwiftClass myClass2 = MySwiftClass .init (arena );
4747
48+ System .out .println ("myClass.isWarm: " + myClass .isWarm ());
49+
4850 try {
4951 myClass .throwingFunction ();
5052 } catch (Exception e ) {
Original file line number Diff line number Diff line change @@ -24,30 +24,12 @@ extension String {
2424 }
2525
2626 /// Returns whether the string is of the format `isX`
27- private var hasJavaBooleanNamingConvention : Bool {
27+ var hasJavaBooleanNamingConvention : Bool {
2828 guard self . hasPrefix ( " is " ) , self . count > 2 else {
2929 return false
3030 }
3131
3232 let thirdCharacterIndex = self . index ( self . startIndex, offsetBy: 2 )
3333 return self [ thirdCharacterIndex] . isUppercase
3434 }
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- }
5335}
Original file line number Diff line number Diff line change @@ -126,10 +126,9 @@ extension FFMSwift2JavaGenerator {
126126 let loweredSignature = try lowering. lowerFunctionSignature ( decl. functionSignature)
127127
128128 // Name.
129- let returnsBoolean = decl. functionSignature. result. type. asNominalTypeDeclaration? . knownTypeKind == . bool
130129 let javaName = switch decl. apiKind {
131- case . getter: decl. name . javaGetterName ( isBoolean : returnsBoolean )
132- case . setter: decl. name . javaSetterName ( isBoolean : returnsBoolean )
130+ case . getter: decl. javaGetterName
131+ case . setter: decl. javaSetterName
133132 case . function, . initializer: decl. name
134133 }
135134
Original file line number Diff line number Diff line change @@ -154,3 +154,27 @@ extension ImportedFunc: Hashable {
154154 return lhs === rhs
155155 }
156156}
157+
158+ extension ImportedFunc {
159+ var javaGetterName : String {
160+ let returnsBoolean = self . functionSignature. result. type. asNominalTypeDeclaration? . knownTypeKind == . bool
161+
162+ if !returnsBoolean {
163+ return " get \( self . name. toCamelCase) "
164+ } else if !self . name. hasJavaBooleanNamingConvention {
165+ return " is \( self . name. toCamelCase) "
166+ } else {
167+ return self . name. toCamelCase
168+ }
169+ }
170+
171+ var javaSetterName : String {
172+ let firstParameterIsBoolean = self . functionSignature. parameters. first? . type. asNominalTypeDeclaration? . knownTypeKind == . bool
173+
174+ if !firstParameterIsBoolean || self . name. hasJavaBooleanNamingConvention {
175+ return " set \( self . name. toCamelCase) "
176+ } else {
177+ return " setIs \( self . name. toCamelCase) "
178+ }
179+ }
180+ }
Original file line number Diff line number Diff line change @@ -38,10 +38,9 @@ extension JNISwift2JavaGenerator {
3838 let parentName = decl. parentType? . asNominalType? . nominalTypeDecl. qualifiedName ?? swiftModuleName
3939
4040 // Name.
41- let returnsBoolean = translatedFunctionSignature. resultType == . boolean
4241 let javaName = switch decl. apiKind {
43- case . getter: decl. name . javaGetterName ( isBoolean : returnsBoolean )
44- case . setter: decl. name . javaSetterName ( isBoolean : returnsBoolean )
42+ case . getter: decl. javaGetterName
43+ case . setter: decl. javaSetterName
4544 case . function, . initializer: decl. name
4645 }
4746
You can’t perform that action at this time.
0 commit comments