Android Studio, where is the style to modify the line return on the “foreach” command

I think it’s a bug related with ‘Reformat according to style’ option.

As you know, to prevent wrong wrapping, turn off ‘Reformat according to style” option for ‘foreach’ Live Template.

Editor > Live Templates > Android > foreach > Reformat according to style

Here is my explanation:

There are styles for ‘for()’ statement in

Code Style > Java > Wrapping and Braces > ‘for()’ statement

It makes wrapping when using ‘Live Templates’ with ‘Reformat according to style’ option. It’s not about Code Style rule because it doesn’t wrap when already typed foreach loop.

After some testing with template text and applying Code Style, I figured out the problem is WHEN Code Style applied. ‘Reformat according to style’ option is applied BEFORE template text interpreted, so Code Style for ‘for()’ applied to below text and it wraps.

for ($i$ : $data$) {

Type that template text in editor and ‘Reformat Code’, it wraps like this.

for ($i$:
     $data$) {

That’s why live template works like that.

It’s just a bug and you can use the temporary fix until bug fixed.

Leave a Comment