Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 458763 - [typing] Method declared inside an enum declaration is not indented
Summary: [typing] Method declared inside an enum declaration is not indented
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.5 M7   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-29 12:37 EST by Rob Lewis CLA
Modified: 2015-04-28 05:12 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 Rob Lewis CLA 2015-01-29 12:37:03 EST
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
Comment 1 Rob Lewis CLA 2015-01-29 12:38:50 EST
Actually, after I hit "Submit" for this report, all the indents disappeared. You'll have to take my word for it.
Comment 2 Noopur Gupta CLA 2015-03-04 03:51:00 EST
(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'.
Comment 3 Rob Lewis CLA 2015-03-05 11:42:56 EST
I am not quite clear whether you are agreeing that this is an error, or saying that it is behaving as it should.
Comment 4 Noopur Gupta CLA 2015-03-25 08:29:11 EDT
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.
Comment 5 Noopur Gupta CLA 2015-04-28 05:12:05 EDT
Fixed with bug 400670 comment #12.
Comment 6 Noopur Gupta CLA 2015-04-28 05:12:56 EDT
Verified with 4.5.I20150427-0800.