从命令行运行Java到Kotlin转换器? [英] Run Java to Kotlin converter from the command line?

查看:122
本文介绍了从命令行运行Java到Kotlin转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用Intellij和Eclipse的Kotlin插件将Java文件转换为Kotlin。可以通过命令行在没有这两个IDE的情况下进行某种转换吗?

You can use the Kotlin plug-ins for Intellij and Eclipse to convert Java files to Kotlin. Can this conversion be done from the command line some how without either of these IDEs?

推荐答案

似乎有可能,但是有没有工具,只有代码。在Kotlin Github存储库中的 j2k模块中进行了测试,以下示例摘自测试(AbstractJavaToKotlinConverterSingleFileTest)

It seems that it's possible, but there's no tool for that, just code. There are tests in j2k module in Kotlin Github repository, the example below is taken from the tests (AbstractJavaToKotlinConverterSingleFileTest):

private fun fileToKotlin(text: String, settings: ConverterSettings, project: Project): String {
    val file = createJavaFile(text)
    val converter = JavaToKotlinConverter(project, settings,
                                          IdeaReferenceSearcher, IdeaResolverForConverter)
    return converter.filesToKotlin(listOf(file), J2kPostProcessor(formatCode = true)).results.single()
}

我想,您可以为该模块创建一个.jar并编写您的自己的 JavaToKotlinConverter 简单包装器,使其可以在文件上使用。

I suppose, you can make a .jar of that module and write your own simple wrapper for JavaToKotlinConverter to make it work on files.

这篇关于从命令行运行Java到Kotlin转换器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆