How to add a newline to the PSI tree?


#1

I've tried

``

element.addAfter(JetPsiFactory.createNewLine(project), anotherElement);

but it doesn’t seem to work. IDEA seems to insist on formatting inserted elements a certain way.


#2

First question: why don't you like the way the code is formatted automatically?


#3

Fair question. I guess I'm just used to the Java style of putting a newline between function declarations, but IDEA won't let me do that.


#4

So it creates code like this:

``

fun foo() {}
fun bar() {}

Right? It’s a fair point that it doesn’t look very pretty, but the problem is most likely not in your code, but in Kotlin’s formatter. Feel free to fix it and submit a pull request