Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java code formatter rules is ignored #1640

Closed
CarlPer opened this issue Oct 1, 2020 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1675
Closed

Java code formatter rules is ignored #1640

CarlPer opened this issue Oct 1, 2020 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1675
Assignees

Comments

@CarlPer
Copy link

CarlPer commented Oct 1, 2020

This rule is ignored when formatting:
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert"/>

Environment
  • Operating System: Windows 10 Enterprise v.1909
  • JDK version: Amazon Corretto jdk1.8.0_252
  • Visual Studio Code version: 1.49.2
  • Java extension version: 0.68.0
Steps To Reproduce
  1. Format : List fromJson = new Gson().fromJson("String", new TypeToken<List>() {}.getType());
Current Result
List<String> fromJson = new Gson().fromJson("String", new TypeToken<List<String>>() {
}.getType());
Expected Result
List<String> fromJson = new Gson().fromJson("String", new TypeToken<List<String>>() {}.getType());
Additional Informations
@testforstephen
Copy link
Collaborator

@CsCherrYY Could you please take a look at this formatting issue?

@CsCherrYY
Copy link
Contributor

Hi, @CarlPer , it seems a formatter version bug. The formatter version of template in vscode-java is 13. And the current version of eclipse is 21. There are some differences between the two versions so your settings may be ignored. We are trying to add a formatter version updater into the language server, and it will make effect at the next jdt version.
Now you can simply replace this setting by <setting id="org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line" value="one_line_if_empty"/> to solve this problem as a workaround.

@achaphiv
Copy link

achaphiv commented Feb 25, 2021

For anyone else who stumbles onto this issue, I had to add more config:

<setting id="org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line" value="one_line_if_empty" />
<setting id="org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line" value="one_line_if_empty" />
<setting id="org.eclipse.jdt.core.formatter.keep_method_body_on_one_line" value="one_line_if_empty" />

to support:

class Foo {
  Foo() {}
}

and

class Bar {}

@rgrunber
Copy link
Member

rgrunber commented Mar 17, 2021

https://github.com/eclipse/eclipse.jdt.ui/blob/master/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/preferences/formatter/ProfileVersionerCore.java#L32 mentions the current version as well as a utility method to update older settings to any version.

Update : Ah, I see you found the option as well.

@CsCherrYY
Copy link
Contributor

@rgrunber Yes. eclipse-jdtls/eclipse.jdt.ls@704e50b uses the utility you mentioned to check if there is any need to update the profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants