Specifically, I'm thinking about enums, in which a
comma-separated list of identifiers often spans
multiple lines. Currently, DrJava indents such
declarations as follows:
public enum MyEnum {
..MyEnumValue1,
....MyEnumValue2,
....MyEnumValue3
}
where clearly, the desirable indentation would be:
public enum MyEnum {
..MyEnumValue1,
..MyEnumValue2,
..MyEnumValue3
}
The reason, as I understand it, is that the reduced
model considers the list to be a single statement and
thus indents subsequent lines, as would be appropriate
for a list of variable declarations or an actual
multi-line statement. However, in this situation, it
is not a single statement but a list of essentially
independent values. I'm not sure if this is worth
correcting or what the best way to add logic for this
is, but it's pretty annoying for declaring enums with
members/longer constructors such that having multiple
lines is necessary.
As a side note, further members (fields, constructors,
or methods) are indented correctly -- since a semicolon
is required after the enums, DrJava effectively
considers the statement to be ended and restores the
single level of indentation. For example, the
following indentation shows the correct and incorrect
behavior:
public enum MyEnum {
..elt1("Some long string"), //
....elt2("Some other long string), // wrong,
indentation too deep
....elt3("The last string"); // still wrong
..private String _myString; // correct, since the list
was terminated by a semicolon
..MyEnum(String s) { //correct
...._myString = s; //still correct
..} // still good. You probably get the idea.
}
Logged In: YES
user_id=697810
Thanks to Moez's comment about anonymous inner enum/classes,
I have a slightly more distressing indentation behavior:
enum SomeEnum {
..SomeEnumOne() {
....int foo() { return 1; }
..},
....SomeOtherEnum() { // same as my previous "bad"
......int foo() { return 2; }
....},
......YetAnotherEnum() { // now it's worse
........int foo() { return 3; }
......},
........TheLastEnum() { // same problem, but worse again
..........int foo() { return 4; }
........};
........SomeEnum() {} // this is annoying
........int foo() { return 0; }
}
This is bad -- at each level, the comma causes the next
anonymous enum to be indented one extra level, and after the
terminating semicolon, the absurdly deep indent level is
preserved for further members.
I'm not sure if it will become common practice to make
anonymous enum classes, but this indentation behavior is
terrible regardless, so I'm bumping up the priority a bit.