Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339980 - [move method] Move method adds enum name to case statements
Summary: [move method] Move method adds enum name to case statements
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-15 04:52 EDT by Didier Loiseau CLA
Modified: 2012-04-29 09:53 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Didier Loiseau CLA 2011-03-15 04:52:49 EDT
Build Identifier: 20100617-1415

When using the "Move..." refactoring on a method containing a switch over some enum value, the cases values will be prefixed with their enum name.

Reproducible: Always

Steps to Reproduce:
1. Create a class with the below code
2. Trigger "Move..." refactoring on someMethod
3. Choose to move the method to someField
4. The resulting code does not compile because each case statement contains the enum name ("case MyEnum.FOO:" instead of just "case FOO:")

public class MoveMethodWithEnum {
	OtherClass someField;

	enum MyEnum {
		FOO, BAR
	}

	void someMethod(MyEnum fooBar) {
		switch (fooBar) {
		case FOO:
			System.out.println("foo");
			break;
		case BAR:
			System.out.println("bar");
		}
	}
}

class OtherClass {

}
Comment 1 Dani Megert CLA 2011-03-15 05:39:18 EDT
Same in 3.7 M6.
Comment 2 Raksha Vasisht CLA 2011-10-18 04:48:53 EDT
Fixed in HEAD. 

commit	fc4f451f07054d44cce5ca22fbae4e09d91c35d4
Comment 3 Markus Keller CLA 2011-10-18 09:17:44 EDT
The fix doesn't make sense and it doesn't work when I copy the 2 classes from comment 0 and paste them into a package p. The missing imports may be a special problem because of the secondary class in the same CU, but it also doesn't work if OtherClass gets its own CU.

The problem is that the SwitchCase expression must not be qualified if the switch operates on an Enum. Use Checks.isEnumCase(ASTNode).
Comment 4 Markus Keller CLA 2011-10-21 07:05:33 EDT
Reverted the commit for the build input.

Commit df8029575a70827bf3da5400c0957a31fce97355
Comment 5 Raksha Vasisht CLA 2012-01-23 12:39:47 EST
Moving to M6...
Comment 6 Markus Keller CLA 2012-04-29 09:53:20 EDT
Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=b0c3b403fb971af242b9d5ac876b884f271b259f
and added Raksha's tests with next commit.