该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

groovy2kotlin

An utility converting Groovy sources to Kotlin language.

Started Nov 2019 by zencd in order to convert a project of mine because I've not found any existing tools (and it's easy to write one by myself). The result of translation isn't 100% Kotlin-correct usually and user is required to review the result, but a significant amount of work can be saved for free.

The policy:

  • Don't loose any piece of code;
  • Produced code could be partially invalid in syntax/linking;
  • But it is acceptable since an operator can easily review such errors;
  • Silent behavioural changes are highly undesirable;
  • But they are still possible because Groovy can do unpredictable things in runtime;
  • Nevertheless do the best to emit valid, readable code;
  • Prefer val over var when possible;
  • Prefer emitting non-optionals;
  • Prefer emitting non-mutables;
  • No runtime dependencies.

The current implementation's passes:

  • One or multiple modules are parsed into AST by the Groovy itself;
  • All types (including dependent libs) gets resolved as strictly as possible;
  • AST traversed to resolve types of locals and expressions;
  • Inferring optionals;
  • Kotlin source code generated finally.

Feel free to submit a bug, ticket and do all the github things.

Requirements

  • JDK 1.8 (for running the tool)
  • Groovy 2.5.8 (for running the tool + input language level)
  • Kotlin 1.3.60 (produced code level)

Others may be supported but was not tested.

Usage

See here

Structure

  • Gtk.toKotlinAsSingleString() - converts a Groovy script text into Kotlin
  • BulkProcessor - converts a directory recursively
  • GroovyToKotlin - the translator engine
  • test-data/input-output-tests/ - a set of input/output tests showing how the things gets translated

Example

demo comparison

Todo

See here

空文件

简介

把groovy语言转换为kotlin语言 展开 收起
Groovy
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化