Community
Participate
Working Groups
It seems that declarations of methods inside an enum declaration should be indented, as they are inside regular classes. In this example, the method "opposite()" is indented here in my bug report, but it is not indented in my actual code window in the Eclipse editor (and the very last line is not outdented below, though it should be): public enum Direction {NORTH, SOUTH, EAST, WEST; // note semicolon here public Direction opposite() { // method to return the opposite compass direction switch (this) { case NORTH: return SOUTH; case SOUTH: return NORTH; case EAST: return WEST; case WEST: return EAST; default: return null; } // switch } // opposite() } // enum Direction -- Configuration Details -- Product: Eclipse 4.4.1.20150109-0740 (org.eclipse.epp.package.java.product) Installed Features: org.eclipse.platform 4.4.0.v20140925-0400
Actually, after I hit "Submit" for this report, all the indents disappeared. You'll have to take my word for it.
(In reply to Rob Lewis from comment #0) > It seems that declarations of methods inside an enum declaration should be > indented, as they are inside regular classes. If you have a class similar to your example enum, then the method in that class is also not indented: ------------------------------------------------------ package p1; public class Direction { int NORTH, SOUTH, EAST, WEST; // note semicolon here public Direction opposite() { // method to return the opposite compass return null; } // opposite() } // class Direction ------------------------------------------------------ Select the above class and press Ctrl+I to indent. You can see that the above method will be indented incorrectly, similar to the example in your enum. It is because these methods are indented similar to their previous statement i.e. the type declarations in above examples. If you declare your enum constants or class fields in a new line after the type declaration, indentation works correctly. However, the above cases where enum constants or class fields are declared in the same line as the type declaration, should also be handled by 'correct indentation'.
I am not quite clear whether you are agreeing that this is an error, or saying that it is behaving as it should.
This issue for enum will be fixed with the patch for bug 400670 which includes the test case from comment #0. The example mentioned for class in comment #2 is not the usual way of coding where class fields are declared in the same line as the class declaration and is not covered in the fix.
Fixed with bug 400670 comment #12.
Verified with 4.5.I20150427-0800.