IntelliJ has a feature to convert Java to Kotlin. ...
# intellij
m
IntelliJ has a feature to convert Java to Kotlin. Out of curiosity: can that be run as a standalone tool? If yes, is there any doc? Thank you.
e
it's https://github.com/JetBrains/intellij-community/tree/master/plugins/kotlin/j2k and there isn't a supported way to run it outside of the IDE
I suppose you could poke around in the binary artifact https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide/org/jetbrains/kotlin/j2k-new/ and see if there a way to set up enough of the environment outside the IDE to get it to work
👍 1
someone made a hack, but it’s not been updated since 2021 https://github.com/ermattt/clij2k
e
not really sure what that particular repo helps with since you need to set up the IDE anyway to get it to work… but the approach of driving a headless IDE seems feasible
h
I did not look at the repo but running headless IntelliJ is basically what the Kotlin compiler as well as sqldelight do.
e
no, not really. they use data structures like PSI, which is a tiny subset of the IDE. but that repo literally installs an IntelliJ plugin and uses the IntelliJ intallation itself
h
I wouldn’t say tiny, the parser, project, modules, extension points and vFiles are the basic components of IntelliJ, but really running a headless instance is another thing. But it should be possible to extract the j2k plugin components and register them in a basic IntelliJ core environment.
e
yeah you'd have to set up the environment to look like a project… which is what I was getting at earlier 😛
h
Yeah, but this is easy, this is basically all you need plus registering the components: https://github.com/AlecStrong/sql-psi/blob/master/core/src/main/kotlin/com/alecstrong/sql/psi/core/SqlCoreEnvironment.kt Just ignore the name, the implementation is universal and could be further simplified.
c
Was anyone able to do J2K conversion through CLI? I tried running it as part of the inspection using https://github.com/ermattt/clij2k but it didn’t quite work.
h
I created the implementation, but it is still work in progress, mostly due to shaded IntelliJ dependencies: https://github.com/hfhbd/j2k
K 1
c
50 shades of IntelliJ 😄
😄 1