At work we do customizing of enterprise systems (that we do not control) that use javascript and rhino/nashorn engine as the primary scripting platform.
Using the rhino engine it is possible to access all java classes by their full qualified name from javascript code. I want to write my code in kotlin, compile it to js and run it in rhino.
As one may can imagine most of the apis we use in the javascript code are java classes provided by the enterprise system. We have the jars that contain the java types. It would be really nice if I could import the java classes into the kotlin code and have all calls to the java type automatically converted to “external” style calls so I do not have to create kotlin definitions for the existing java type.
The primary goal of this is to have autocompletion and buildtime type checking for the javatype calls.
This is what I tried, however this:
import the.enterprise.api.types.EnterpriseApi // compiler error
import the.enterprise.api.types.EnterpriseContext // compiler error
// serverApi will be defined as a global object
// by the enterprise systems rhino context
external val serverApi: EnterpriseApi
fun functionCalledByTheEnterpriseSystem(context: EnterpriseContext) {
serverApi.callApiFunction()
}
Does not compile:
.\App.kt: (3, 8): Unresolved reference: the
.\App.kt: (4, 8): Unresolved reference: the
.\App.kt: (6, 25): Unresolved reference: EnterpriseApi
.\App.kt: (8, 50): Unresolved reference: EnterpriseContext
Is it possible to do this with todays kotlin2js compiler?