Bug 79795 - Code formatter doesn't handle enums well.
Summary: Code formatter doesn't handle enums well.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-30 12:28 EST by Dirk Baeumer CLA
Modified: 2004-12-15 13:13 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2004-11-30 12:28:47 EST
 
Comment 1 Dirk Baeumer CLA 2004-11-30 12:29:31 EST
package object_in;

public enum TestEnumRead {
	TEST;
	public String field;

	public void foo() {
		String s = field;
	}
}

formatting it produces

package object_in;

public enum TestEnumRead {
	TEST
        ;
	public String field;

	public void foo() {
		String s = field;
	}
}
Comment 2 Olivier Thomann CLA 2004-11-30 18:29:16 EST
And?
Comment 3 Olivier Thomann CLA 2004-11-30 18:36:50 EST
Do you expect the semi-colon to remain on the same line than the 'TEST' ?

This would be ok, when you have only one or two constants, but when you have few
constants with bodies, you easily miss the semi-colon if it is not moved on the
next line.
It tried to see how to do this through options, but I could not see an obvious
pattern.

There are no java conventions for formatting the new 1.5 constructs. So any
suggestions are welcome as long as we can infer options out of them.
Comment 4 Dirk Baeumer CLA 2004-12-01 03:44:31 EST
Yes, I would expect having the semicolon on the same line as TEST. For me its
like a field declaration where I declare more than one field (e.g. String A, B, C;)
Comment 5 Olivier Thomann CLA 2004-12-01 10:25:42 EST
This is fine when you don't have a body, but once you have a body and a few
constants, it is easy to miss the semicolon.
Comment 6 Dirk Baeumer CLA 2004-12-01 12:17:21 EST
I consider anonymous enums a rare scenario. In this case I would expect the
following formatting

enum E {
  A {
    void foo() {
    }
  },
  B {
    void foo() {
    }
  };
}
Comment 7 Olivier Thomann CLA 2004-12-01 12:20:34 EST
Ok, I will change it to keep the semi-colon after the last constant. We might
want to revisit that in the future depending how this is accepted.
Comment 8 Olivier Thomann CLA 2004-12-01 16:15:42 EST
Fixed and released in HEAD.
Regression tests added and existing tests updated.
The rule is the following:
- the semi-colon is left behind the last constant (it is not on a new line).
- if enum constants have a body, the next constant is moved to the next line for
clarity.

Hope this is the expected behavior.
Comment 9 Frederic Fusier CLA 2004-12-15 13:13:26 EST
Verified for 3.1 M4 using build I200412142000.