Reputation: 41
I have been looking for answer for a long time in google, but unfortunately I haven't found anything. As in topic I am looking for tips to force VS code formatting java files like this:
if()
{
}
not this:
if(){
}
Upvotes: 4
Views: 3557
Reputation: 8411
I agree with Snurrig, but I want to add some information.
In fact, the "Language Support for Java(TM) by Red Hat" extension build in a format setting under 'formatters' folder. But it does not work in default, for example, even you delete it, the format of "Language Support for Java(TM) by Red Hat" still works. This is because the format rules build in the plugins. But you can set the format settings explicitly through 'java.format.settings.url' in settings.json file. So you can point to the settings XML file under "Python" extension -> 'formatters' folder. In this file, if you like you can replace all the 'end_of_line' to 'next_line'.
Upvotes: 0
Reputation: 827
There is a way. It just takes a little bit of setup.
Alt
+Shift
+F
, or if that's not working, right click and select Format Document
.File
> Preferences
> Settings
, and search for "java format url". Enter the path to the style file you just downloaded.
if (true) {
}
to this:
if (true)
{
}
you have to change the following line:
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
to this:
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="next_line"/>
2.
again and it should work.As a side note: VS Code are working on a better experience for editing these formatting options: Java formatter.
Upvotes: 6