Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rearrange Kotlin code in the order?

First of all, I Google it, and find no answer to this. Also, I've found some questions here, but they dated 2016 and 2017. Now we have 2019.

I'm used to Java in Android Studio. When I override methods, IDE puts them in order - how they placed in parent class or implemented interface.

Also when I'm developing, for example, Repository pattern:

  • I create an interface.

  • Create classes which implements this interface

  • When I am adding functions in interface and then I override (ctrl+o, or alt+Enter on class name) them in my classes: In Java they placed at the same position as they defined in my interface, In Kotlin - the placed in top of the class (this is really bad!)

Also, code does not get reformatted automatically, for example: global vars placed on top, then goes constructors, etc.

So I'm asking.

It's just me? I've tried deleting all Android Studio settings, reinstalling, etc. It did nothing. Also, Googling did not take any results.

Is there any solution to all of this? Because I really liked kotlin, but this inconvenience is just very annoying.

like image 778
Serhii Pokrovskyi Avatar asked Nov 07 '22 20:11

Serhii Pokrovskyi


2 Answers

Maybe this plugin Kotlin Code Sorter can fulfill your request. But this plugin only distinguishes the property, class, constructor or function. That the differences are inside some topics likes private, lateinit, val or var can not be order.

enter image description here

like image 146
Fantasy Fang Avatar answered Nov 14 '22 22:11

Fantasy Fang


Android Studio/IntelliJ official doesn’t have support for the Kotlin code rearrangement.

like image 44
Vivek Patel Avatar answered Nov 14 '22 21:11

Vivek Patel