Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have intellij automatically format code and add types to variables/returns/parameters

I have code like this everywhere

val someName = 10
var someOtherName = "hello"
def add(a, b) = a + b

I prefer to have the types coded in (rather than the compiler figuring it out) in most of the code. It would be great if IntelliJ had some auto-format option to just add the types, so that the above becomes:

val someName: Int = 10
var someOtherName: String = "hello"
def add(a: Int, b: Int): Int = a + b

Does a tool exist?

like image 317
MintyAnt Avatar asked Nov 01 '22 04:11

MintyAnt


1 Answers

Quoting the comment from Yadu Krishnan:

Do you want to add it in all the existing code ? If it is required only in some cases, you can manually do it by using the key combination "alt + enter" after the method/variable name. Then it will ask suggestion to add the method/variable type.

It should be Yadu Krishnan to write this answer, if he does, please accept his response. I'm only making this one to become clearer that there is a solution, that worked in my case at least

like image 189
pedrorijo91 Avatar answered Nov 04 '22 09:11

pedrorijo91