Issue
I have enums like:
public static enum Command
{
login,
register,
logout,
newMessage
}
When formatting the file, the output becomes:
public static enum Command
{
login, register, logout, newMessage
}
Solution
The answer by @wjans worked fine for normal enums, but not for enums with arguments. To expand on his answer a bit, here's the settings that provided the most sensible formatting for me in Eclipse Juno:
Window>Preferences>Java>Code Style>Formatter- Click
Edit - Select the
Line Wrappingtab - Select the
enumdeclaration treenode - Set
Line wrapping policytoWrap all elements, every element on a new line (...)so it now says 3 of 3 in the parenthesis. - Uncheck
Force split, even if line shorter than maximum line width (...)so it now says 3 of 3 in the parenthesis. - Select the
Constantstreenode - Check
Force split, even if line shorter than maximum line width
This sets the 3 subnodes for the enum treenode to the same wrapping policy, and the same force split policy except for the Constants treenode, so your enums with arguments will be formatted each on their own line. The arguments will only wrap if they exceed maximum line width.
Examples:
@wjans
enum Example {
CANCELLED,
RUNNING,
WAITING,
FINISHED
}
enum Example {
GREEN(
0,
255,
0),
RED(
255,
0,
0)
}
Solution described above:
enum Example {
CANCELLED,
RUNNING,
WAITING,
FINISHED
}
enum Example {
GREEN(0, 255, 0),
RED(255, 0, 0)
}
Answered By - PolyTekPatrick
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.