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 {
34
34
mutable = newValue * 2
35
35
}
36
36
}
37
+ public let warm : Bool = false
37
38
38
39
public static func method( ) {
39
40
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() {
45
45
MySwiftClass myClass = MySwiftClass .init (10 , 5 , arena );
46
46
MySwiftClass myClass2 = MySwiftClass .init (arena );
47
47
48
+ System .out .println ("myClass.isWarm: " + myClass .isWarm ());
49
+
48
50
try {
49
51
myClass .throwingFunction ();
50
52
} catch (Exception e ) {
Original file line number Diff line number Diff line change @@ -24,30 +24,12 @@ extension String {
24
24
}
25
25
26
26
/// Returns whether the string is of the format `isX`
27
- private var hasJavaBooleanNamingConvention : Bool {
27
+ var hasJavaBooleanNamingConvention : Bool {
28
28
guard self . hasPrefix ( " is " ) , self . count > 2 else {
29
29
return false
30
30
}
31
31
32
32
let thirdCharacterIndex = self . index ( self . startIndex, offsetBy: 2 )
33
33
return self [ thirdCharacterIndex] . isUppercase
34
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
35
}
Original file line number Diff line number Diff line change @@ -126,10 +126,9 @@ 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
130
129
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
133
132
case . function, . initializer: decl. name
134
133
}
135
134
Original file line number Diff line number Diff line change @@ -154,3 +154,27 @@ extension ImportedFunc: Hashable {
154
154
return lhs === rhs
155
155
}
156
156
}
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 {
38
38
let parentName = decl. parentType? . asNominalType? . nominalTypeDecl. qualifiedName ?? swiftModuleName
39
39
40
40
// Name.
41
- let returnsBoolean = translatedFunctionSignature. resultType == . boolean
42
41
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
45
44
case . function, . initializer: decl. name
46
45
}
47
46
You can’t perform that action at this time.
0 commit comments