Community
Participate
Working Groups
20070427 Create the following code in a 5.0 project package a; public enum E { A, B, C } Open the project specific formatter page and change only one setting from the default: Line Wrapping > Enum declaration > Constants to 'Wrap all elements, every element on its own line' The formatter preview seems to work for the first snippet, but not for the second. Ehen I now try this with my code, nothing is formatted.
I haven't changed anything for a long, long time. I'll investigate.
It simply looks like the argument wrapping has precedence over the constant wrapping. If you set the arguments of the constant not to wrap, I guess you will get what you expect for the constant wrapping.
There are no enum constant arguments in my example. So do you think its a bug?
These are my test snippets. Maybe you can tell me what I have to change to have them work. public void testEnumConst() throws Exception { StringBuffer buf= new StringBuffer(); buf.append("public enum E {\n"); buf.append(" A, B, C\n"); buf.append("}\n"); String contents= buf.toString(); Map options= DefaultCodeFormatterConstants.getEclipseDefaultSettings(); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT ) ); JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options); TextEdit edit= ToolFactory.createCodeFormatter(options).format( CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, "\n"); Document doc= new Document(contents); edit.apply(doc); buf= new StringBuffer(); buf.append("public enum E {\n"); buf.append(" A,\n"); buf.append(" B,\n"); buf.append(" C\n"); buf.append("}\n"); String expected= buf.toString(); assertEquals(expected, doc.get().toString()); } public void testEnumConstArgs() throws Exception { StringBuffer buf= new StringBuffer(); buf.append("public enum E {\n"); buf.append(" A(1, 2), B(1, 2)\n"); buf.append("}\n"); String contents= buf.toString(); Map options= DefaultCodeFormatterConstants.getEclipseDefaultSettings(); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT ) ); JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options); TextEdit edit= ToolFactory.createCodeFormatter(options).format( CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, "\n"); Document doc= new Document(contents); edit.apply(doc); buf= new StringBuffer(); buf.append("public enum E {\n"); buf.append(" A(1,\n"); buf.append(" 2), B(1,\n"); buf.append(" 2)\n"); buf.append("}\n"); String expected= buf.toString(); assertEquals(expected, doc.get().toString()); }
You don't force the line wrapping, but you expect the line wrapping to be applied. Looks weird. Try with forcing the line wrapping and let me know what you get.
'Force split' solves the problem. Strange I thought I have tried that. I think we need to improve the UI here. I was sure that 'Wrap all elements, every element on its own line' really wraps all elements. But I guess it's only wrapping when they don't fit on a line.
(In reply to comment #6) >...I was sure that 'Wrap all elements, > every element on its own line' really wraps all elements. But I guess it's only > wrapping when they don't fit on a line. If force is not set, yes, they are wrapped only if they don't fit on a line.
Verify for 3.3M7 with I20070503-1400.