Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to keep simple getters/setters on the same line?(While otherwise keeping brace positions on NEXT line)
How to keep simple getters/setters on the same line? [message #1849691] Sat, 29 January 2022 23:14 Go to next message
Jack McKalling is currently offline Jack McKallingFriend
Messages: 15
Registered: January 2022
Location: Dreamland
Junior Member
Is it possible to have the formatter format code like this:

public int getNumber() { return 7; }
public void doSomething()
{
    System.out.println("Seven.");
}


I want to normally have braces positioned on the NEXT line, with the exception for simple getters and setters such as the above one, which I want entirely on a single line. I tried to achieve this by specifying (what I think are the relevant bits):

brace positions > method declaration = next line
new lines > keep braced code on one line > method declaration = never
new lines > keep braced code on one line > method declaration > keep simple getters and setters on one line = true
line wrapping > never join already wrapped lines = false
line wrapping > wrapping settings = method declarations > declaration = do not wrap

But the result is at best something like this:

public int getNumber()
{ return 7; }
public void doSomething()
{
    System.out.println("Seven.");
}

That is not what I consider "one line", so what is this about and how can I do it properly?

Note: I tried to change the brace position to "same line" too, and then it does put it on one line, but it also changes the opening brace for all methods instead of just for the simple getters/setters.
Re: How to keep simple getters/setters on the same line? [message #1849694 is a reply to message #1849691] Sun, 30 January 2022 07:27 Go to previous messageGo to next message
Sarika Sinha is currently offline Sarika SinhaFriend
Messages: 131
Registered: February 2010
Location: Bangalore, India
Senior Member
Hi,
Currently there is common setting for all methods, please raise an enhancement request to address the same under UI component : https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT


Sarika Sinha
JDT Programmer
Re: How to keep simple getters/setters on the same line? [message #1849695 is a reply to message #1849694] Sun, 30 January 2022 09:04 Go to previous messageGo to next message
Jack McKalling is currently offline Jack McKallingFriend
Messages: 15
Registered: January 2022
Location: Dreamland
Junior Member
Do you mean like https://bugs.eclipse.org/bugs/show_bug.cgi?id=205973 or https://bugs.eclipse.org/bugs/show_bug.cgi?id=540811 ?

Would my enhancement request not duplicate either of these two? Because I don't understand the difference between them but they both sound like what I'm asking for.
Re: How to keep simple getters/setters on the same line? [message #1849769 is a reply to message #1849695] Wed, 02 February 2022 04:11 Go to previous messageGo to next message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 128
Registered: July 2009
Senior Member
Jack McKalling wrote on Sun, 30 January 2022 04:04
Do you mean like https://bugs.eclipse.org/bugs/show_bug.cgi?id=205973 or https://bugs.eclipse.org/bugs/show_bug.cgi?id=540811 ?

Would my enhancement request not duplicate either of these two? Because I don't understand the difference between them but they both sound like what I'm asking for.


Apparently, the latter bug is what brought the behavior to what we see now. That is what introduced this option but has been closed now. Perhaps a fine-tune is require here, hence a new bug would help here.
Re: How to keep simple getters/setters on the same line? [message #1849786 is a reply to message #1849769] Wed, 02 February 2022 15:14 Go to previous message
Jack McKalling is currently offline Jack McKallingFriend
Messages: 15
Registered: January 2022
Location: Dreamland
Junior Member
All right, thank you both. I have reported it here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578537
Previous Topic:Custom Code Generation With Global Variables
Next Topic:[SOLVED] Content Assist doesn't suggest jdk.* classes
Goto Forum:
  


Current Time: Sat Apr 27 04:15:27 GMT 2024

Powered by FUDForum. Page generated in 0.04266 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top