Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 684
Vincent D. Avatar asked Apr 19 '16 16:04

Vincent D.


2 Answers

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.

like image 170
RabbitHole Avatar answered Nov 12 '22 14:11

RabbitHole


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

like image 25
AndroidMechanic - Viral Patel Avatar answered Nov 12 '22 12:11

AndroidMechanic - Viral Patel