Bug 184485 - Enum formatting broken?
Summary: Enum formatting broken?
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 165703
  Show dependency tree
 
Reported: 2007-04-27 13:27 EDT by Martin Aeschlimann CLA
Modified: 2015-09-03 03:47 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2007-04-27 13:27:05 EDT
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.
Comment 1 Olivier Thomann CLA 2007-04-27 13:46:46 EDT
I haven't changed anything for a long, long time.
I'll investigate.
Comment 2 Olivier Thomann CLA 2007-04-27 14:05:34 EDT
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.
Comment 3 Martin Aeschlimann CLA 2007-04-30 03:50:54 EDT
There are no enum constant arguments in my example. So do you think its a bug? 
Comment 4 Martin Aeschlimann CLA 2007-04-30 07:21:15 EDT
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());
}	
Comment 5 Olivier Thomann CLA 2007-04-30 11:19:48 EDT
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.
Comment 6 Martin Aeschlimann CLA 2007-04-30 12:18:21 EDT
'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.
Comment 7 Olivier Thomann CLA 2007-04-30 12:22:16 EDT
(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.
Comment 8 Olivier Thomann CLA 2007-05-03 20:56:17 EDT
Verify for 3.3M7 with I20070503-1400.