Skip to content

Commit cc4a702

Browse files
authored
Add type name to macro generated native function name (#674)
1 parent ab9e0a1 commit cc4a702

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

Sources/SwiftJavaMacros/ImplementsJavaMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ extension JavaImplementationMacro: PeerMacro {
213213
@used
214214
#endif
215215
@_cdecl(\(literal: cName))
216-
public func \(context.makeUniqueName(swiftName))(\(raw: cParameters.map{ $0.description }.joined(separator: ", ")))\(raw: cReturnType) {
216+
public func \(context.makeUniqueName("\(swiftTypeName)_\(swiftName)"))(\(raw: cParameters.map{ $0.description }.joined(separator: ", ")))\(raw: cReturnType) {
217217
\(body)
218218
}
219219
"""

Tests/SwiftJavaMacrosTests/JavaImplementationMacroTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class JavaImplementationMacroTests: XCTestCase {
4848
@used
4949
#endif
5050
@_cdecl("Java_org_swift_example_Hello_1World_test_1method")
51-
public func __macro_local_11test_methodfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
51+
public func __macro_local_22HelloWorld_test_methodfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
5252
let obj = HelloWorld(javaThis: thisObj, environment: environment!)
5353
return obj.test_method()
5454
.getJNILocalRefValue(in: environment)
@@ -81,7 +81,7 @@ class JavaImplementationMacroTests: XCTestCase {
8181
@used
8282
#endif
8383
@_cdecl("Java_com_example_test_MyClass_simpleMethod")
84-
public func __macro_local_12simpleMethodfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
84+
public func __macro_local_20MyClass_simpleMethodfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
8585
let obj = MyClass(javaThis: thisObj, environment: environment!)
8686
return obj.simpleMethod()
8787
.getJNILocalRefValue(in: environment)
@@ -114,7 +114,7 @@ class JavaImplementationMacroTests: XCTestCase {
114114
@used
115115
#endif
116116
@_cdecl("Java_org_example_Utils_static_1helper")
117-
public func __macro_local_13static_helperfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> String.JNIType {
117+
public func __macro_local_19Utils_static_helperfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> String.JNIType {
118118
return Utils.static_helper(environment: environment)
119119
.getJNILocalRefValue(in: environment)
120120
}
@@ -154,7 +154,7 @@ class JavaImplementationMacroTests: XCTestCase {
154154
@used
155155
#endif
156156
@_cdecl("Java_test_Class_1With_1Underscores_method_1one")
157-
public func __macro_local_10method_onefMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
157+
public func __macro_local_31ClassWithUnderscores_method_onefMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
158158
let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!)
159159
return obj.method_one()
160160
.getJNILocalRefValue(in: environment)
@@ -164,7 +164,7 @@ class JavaImplementationMacroTests: XCTestCase {
164164
@used
165165
#endif
166166
@_cdecl("Java_test_Class_1With_1Underscores_method_1two")
167-
public func __macro_local_10method_twofMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
167+
public func __macro_local_31ClassWithUnderscores_method_twofMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) -> Int32.JNIType {
168168
let obj = ClassWithUnderscores(javaThis: thisObj, environment: environment!)
169169
return obj.method_two()
170170
.getJNILocalRefValue(in: environment)
@@ -205,7 +205,7 @@ class JavaImplementationMacroTests: XCTestCase {
205205
@used
206206
#endif
207207
@_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024size")
208-
public func __macro_local_5_sizefMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType {
208+
public func __macro_local_28SwiftDictionaryMapJava__sizefMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, pointer: Int64.JNIType) -> Int32.JNIType {
209209
return SwiftDictionaryMapJava._size(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!))
210210
.getJNILocalRefValue(in: environment)
211211
}
@@ -214,7 +214,7 @@ class JavaImplementationMacroTests: XCTestCase {
214214
@used
215215
#endif
216216
@_cdecl("Java_org_swift_swiftkit_core_collections_SwiftDictionaryMap__00024destroy")
217-
public func __macro_local_8_destroyfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, pointer: Int64.JNIType) {
217+
public func __macro_local_31SwiftDictionaryMapJava__destroyfMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, pointer: Int64.JNIType) {
218218
return SwiftDictionaryMapJava._destroy(environment: environment, pointer: Int64(fromJNI: pointer, in: environment!))
219219
}
220220
""",
@@ -245,7 +245,7 @@ class JavaImplementationMacroTests: XCTestCase {
245245
@used
246246
#endif
247247
@_cdecl("Java_org_example_Processor_process_1data")
248-
public func __macro_local_12process_datafMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) {
248+
public func __macro_local_22Processor_process_datafMu_(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject) {
249249
let obj = Processor(javaThis: thisObj, environment: environment!)
250250
return obj.process_data()
251251
}

0 commit comments

Comments
 (0)