Android Studio, where is the style to modify the line return on the "foreach" command
Asked Answered
P

3

7

I can't figure how to Android Studio handle the styling of the foreach live template by putting it on two line like this:

 for ( :
   ) {

   }
  • In the Editor -> Live templates -> Android -> foreach we can unselect Reformat according to style and it stays on one line but it looks like a temporary fix.

I want to find where (according to style) is, to be able to modify it. Thanks

Pich answered 19/4, 2016 at 16:27 Comment(2)
Android 3.1.2 and I can't believe this bug is still around.Identification
2019 and still lives on. So freaking annoyingSlut
S
12

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$) {
    $cursor$
}

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

for ($i$:
     $data$) {
    $cursor$
}

That's why live template works like that.

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

Stuffed answered 7/7, 2016 at 2:56 Comment(1)
Damn, half a year passed and this is still not fixed?Together
S
1

The solution for me was simply going to the given place

Editor -> Live templates -> Android -> foreach

and unchecking Reformat according to style

Slut answered 28/3, 2019 at 19:29 Comment(0)
L
0

You can modify it at the very same path you mentioned in the question.

Editor -> Live templates -> Android -> foreach

select foreach and at the bottom you see a textarea with the formatting/style. Modify it as you wish and click Apply

enter image description here

Update

The style you are referring to is i think the code style.

Can be found at

Editor -> Code Styles

Check this screenshot"

enter image description here

Lilylilyan answered 19/4, 2016 at 16:47 Comment(5)
Thanks it's already what I have done and I had to untick the Reformat according style that was messing the formatting. The problem is that I want to find where is this according to style. Where is that style.Pich
I modified the title for a better understanding of the question, thanks for your answerPich
see the updated answer. is that what you are looking for?Lilylilyan
Yes it should be in Wraping and Braces but the foreach is not there and I have already tried to tick/untick most of the new line on boxes without any effect. So I suppose it's in another one. Looks an easy answer but I have already spent a cumulated ~10hours on this. Can be a bug in Android Studio / Intelli JPich
Yeah this answer doesn't solve the problem at all. It's just pointing to places to look, without having tested the answer first to see if it actually works, or failed to understand the question/problem in the first place.Neap

© 2022 - 2024 — McMap. All rights reserved.