# groovy2kotlin **Repository Path**: btxd/groovy2kotlin ## Basic Information - **Project Name**: groovy2kotlin - **Description**: 把groovy语言转换为kotlin语言 - **Primary Language**: Groovy - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-07-22 - **Last Updated**: 2024-07-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # groovy2kotlin An utility converting [Groovy](http://groovy-lang.org/) sources to [Kotlin](https://kotlinlang.org/) language. Started Nov 2019 by [zencd](https://github.com/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](USAGE.md) ## 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](demo2.png) ## Todo [See here](TODO.md)