Skip to content

Commit d26216c

Browse files
committed
Disable name mangling in Kotlin
1 parent 989db34 commit d26216c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spaghetti-kotlin-support/src/main/groovy/com/prezi/spaghetti/kotlin/KotlinInterfaceGeneratorVisitor.groovy

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.prezi.spaghetti.kotlin
22

33
import com.prezi.spaghetti.ast.InterfaceNode
4+
import com.prezi.spaghetti.ast.MethodNode
45

56
class KotlinInterfaceGeneratorVisitor extends AbstractKotlinMethodGeneratorVisitor {
67

@@ -20,6 +21,18 @@ ${methodDefinitions}
2021
"""
2122
}
2223

24+
@Override
25+
String visitMethodNode(MethodNode node) {
26+
def returnType = node.returnType.accept(this)
27+
returnType = wrapNullableTypeReference(returnType, node)
28+
def typeParams = node.typeParameters ? "<" + node.typeParameters*.name.join(", ") + "> " : ""
29+
def params = node.parameters*.accept(this).join(", ")
30+
31+
return \
32+
""" native fun ${typeParams}${node.name}(${params}):${returnType}
33+
"""
34+
}
35+
2336
private static String defineType(String typeName, Collection<?> superTypes) {
2437
def declaration = "trait ${typeName}"
2538
if (!superTypes.empty) {

spaghetti-kotlin-support/src/test/groovy/com/prezi/spaghetti/kotlin/KotlinInterfaceGeneratorVisitorTest.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class KotlinInterfaceGeneratorVisitorTest extends AstTestBase {
3636
/**
3737
* Does something.
3838
*/
39-
fun doSomething():Unit
40-
fun doSomethingElse(a:Int?, b:Int? = null):Array<String>?
41-
fun <T, U> hello(f:(X,()->Int)->U):Array<T>
39+
native fun doSomething():Unit
40+
native fun doSomethingElse(a:Int?, b:Int? = null):Array<String>?
41+
native fun <T, U> hello(f:(X,()->Int)->U):Array<T>
4242
4343
}
4444
"""

0 commit comments

Comments
 (0)