fwcd / fwcd/kotlin-language-server

Improve Java-to-Kotlin converter

Open
#140 0 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

Although the J2K-converter already supports a range of Java constructs, there are still some missing PSI node types that currently cannot be converted. These include, but are not limited to:

* Anonymous classes
* Switch statements
* Synchronized statements
* Try-catch
* Throw statements
* Annotations (especially `@Override` -> `override`)

Implementing them is fairly straightforward, since they directly correspond to a method in [`JavaElementConverter`](https://github.com/fwcd/KotlinLanguageServer/blob/master/server/src/main/kotlin/org/javacs/kt/j2k/JavaElementConverter.kt):

https://github.com/fwcd/KotlinLanguageServer/blob/93e633951c089d713d7a8c07f18ea389cfa690fa/server/src/main/kotlin/org/javacs/kt/j2k/JavaElementConverter.kt#L76-L620

Additionally, there are some improvements to be made to the existing conversion methods:

* Supporting all [modifiers](https://www.w3schools.com/java/java_modifiers.asp) (such as `private`, `protected`, `transient`, `abstract`, ... - `static` and `final` currently the only supported ones)
* Note that these modifiers can be found in [PsiModifier](https://github.com/JetBrains/intellij-community/blob/master/java/java-psi-api/src/com/intellij/psi/PsiModifier.java)
* Automatically converting getters/setters to the "Kotlin style"
* `getSomething()`/`setSomething(...)`-style methods can be converted [using the same rules as the completions](https://github.com/fwcd/KotlinLanguageServer/blob/93e633951c089d713d7a8c07f18ea389cfa690fa/server/src/main/kotlin/org/javacs/kt/completion/Completions.kt#L120-L125)
* Some conversions, specifially those for which Kotlin maps a "platform type to a Java class" are tricky, since they follow no special rule
* Consider `java.util.Collection.size()` -> `(kotlin.collections.)Collection.size` (which is a property)
* Automatically converting classes with no fields to `object`s

This is not an exhaustive list and other improvements are welcomed.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with server/src/main/kotlin/org/javacs/kt/j2k/JavaElementConverter.kt and inspect the existing conversion methods for the listed PSI nodes and modifiers. Compare getter/setter conversion rules in server/src/main/kotlin/org/javacs/kt/completion/Completions.kt, then verify that the requested Java constructs, modifiers, accessors, and fieldless classes convert correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.