mkrussel
08/30/2022, 2:29 PMUtilsKt.foo()
.
My plan was to create a plugin for Dokka to extend the HTML plugin to add another code block section that would show the function declaration in Swift. I’m not sure how to begin. I’m guessing I want to change the ContentModel in some extension point.mkrussel
08/30/2022, 8:50 PMSignatureProvider
and then create additional ContentGroups for function signatures.Ignat Beresnev
08/31/2022, 12:15 PMIgnat Beresnev
08/31/2022, 12:20 PMmkrussel
08/31/2022, 12:26 PMfoo
in a file called Utils.kt
, Swift will see the function as UtilsKt.foo
just like Java.
There are a few differences between the two. From Swift the property names are required and are part of the signature, but those are already in the documentation.
How extension functions work also depends on the type of the receiver. For most extension methods, Swift callers can call them on the object just like Kotlin devs. But there are a few types (primitives, Strings, collections, functions, an Objective-C objects) that they need to fallback and call them the same way that Java would. Double.foo()
in Utils.kt
would become UtilsKt.foo(receiver: Double
.
The last difference is that Kotlin native adds _
to the end of some of the names when building the final framework. This is based on all the code getting merged, so I’m not sure if Dokka would be able to determine when and how many _
will get added.
For my use case, I’m converting a large library that was implementing in Swift and Java to a new Kotlin library. I expect the teams that use it to not be using Kotlin multiplatform, so I need it to still be easy to use for the iOS devs. The java callers have a similar problem, but I’m going with the assumption that they will or can switch to Kotlin. I’m also assuming that the iOS devs will be using Swift and not Objective-C where the names are changed even more.mkrussel
08/31/2022, 12:28 PM@Swift
isn’t really an annotation, just a way to draw the Swift user eyes to it. I’ve been debating whether I want to repeat all the annotations from the main function declaration.Ignat Beresnev
08/31/2022, 12:49 PMThe java callers have a similar problem, but I’m going with the assumption that they will or can switch to Kotlin.Yeah, it seems to be less of a problem in Java. From personal experience, in migrating codebases Java code is considered to be legacy and no new code is written in it, so there's really no need to call Kotlin code from java, and you can always re-write/convert it to Kotlin if problems arise But with Swift it makes sense in the long run
Ignat Beresnev
08/31/2022, 12:52 PMmkrussel
08/31/2022, 12:55 PMIgnat Beresnev
08/31/2022, 1:03 PMmkrussel
08/31/2022, 1:03 PMIgnat Beresnev
08/31/2022, 1:07 PMDClass.sources
would be useful? Not sure what the path is going to look like, but it might end in .swift
You could, but I wouldn't recommend relying too much on anything related to DeclarationDescriptor
in your plugin, I'd say it's internal compiler business and you'll have a bad time if/when the compiler changes, there's no guarantees from our end. It'll probably be removed in the future
But looking at path
variable from the base interface might helpmkrussel
08/31/2022, 1:13 PM