Android Studio, where is the style for changing the return of the string in the "foreach" command

I can not understand how Android Studio handles the style of the foreach template by putting it on two lines as follows:

  for ( : ) { } 
  • In Editor -> Live templates -> Android -> foreach we can cancel the Reformat according to the style , and it remains on the same line, but looks like a temporary fix.

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

+7
source share
3 answers

I think this is a bug related to the Reform by Style option.

As you know, to prevent incorrect packaging, disable the "Reform according to style" option for the Live foreach template.

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

Here is my explanation:

There are styles for the for for () statement in

Code Style> Java> Wrapper and Braces> 'for expression ()'

This makes a wrapper when using "live templates" with the "Reformat Style" option. This is not about code style rules, because it does not end when the foreach loop is already typed.

After some testing with the template text and applying Code Style, I realized that the WHEN Code Style problem is applied. The option "Convert to style" is applied before interpreting the text of the template, therefore the code style for "for ()" is applied to the text below and is wrapped.

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

Enter the text of the template in the editor and 'Reformat Code', it will look as follows.

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

This is why a live template works like this.

This is just a bug, and you can use a temporary fix until the bug is fixed.

+10
source

You can change it along the same path that you talked about in the question.

 Editor -> Live templates -> Android -> foreach 

select foreach , and at the bottom you will see a text box with formatting / style. Change it as you like and click Apply

enter image description here

Update

The style you're talking about is a code style.

Can be found in

 Editor -> Code Styles 

Install this screenshot

enter image description here

+1
source

Solution for me just to go to this place

Editor → Live templates → Android → foreach

and uncheck the reformat Reformat according to style

0
source

Source: https://habr.com/ru/post/1247449/


All Articles