Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 497368

Summary: [pull up] Pull Up refactoring to interface generates broken code
Product: [Eclipse Project] JDT Reporter: Carsten Reckord <reckord>
Component: UIAssignee: Noopur Gupta <noopur_gupta>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: noopur_gupta, patrice_kerremans, zorzella
Version: 4.6   
Target Milestone: 4.7 M1   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/77384
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a2db02a5370121790fc04dfd719f54f39ad664e0
Whiteboard:

Description Carsten Reckord CLA 2016-07-06 04:45:03 EDT
Create an interface IFoo and implementing classes Foo, FooImpl1, FooImpl2. In Foo, define a method as follows:

	public void log(Level level, String message, String... parameters) {
		String formattedMessage = MessageFormat.format(message, (Object[])parameters);
		System.out.println("Logging "+message+" with "+Arrays.asList(parameters));
		LogManager.getLogManager().getLogger(Foo.class.getName()).log(level, formattedMessage);
	}

Use the Pull Up refactoring to pull the method up into interface IFoo. In the wizard, select "Create necessary method stubs ..."

Expected outcome:
1. The result is compile-error free
2. The method is added to IFoo along with imports needed for the method signature
3. The method is added to all non-abstract implementors along with imports needed for the method signature
4. The method in implementors looks the same as when using the "Add unimplemented methods" hotfix to create it, including
- task marker //TODO auto-generated method stub
- @Override annotation

The method stub should look something like this:

	//import for java.util.logging.Level
	
	@Override
	public void log(Level level, String message, String... parameters) {
		// TODO Auto-generated method stub
		
	}

Actual outcome:
1. All implementors (except Foo) have compile errors
2. IFoo gets additional, unnecessary imports for classes used in the method body of the original implementation in Foo
3. Imports needed for the method signature are not added to implementors
4. The method in implementors lacks both the //TODO marker and the @Override annotation

The method stub actually looks like this:

	//no import for java.util.logging.Level

	public void log(Level level, String message, String... parameters) {
	}
Comment 1 Noopur Gupta CLA 2016-07-15 07:52:36 EDT
*** Bug 444002 has been marked as a duplicate of this bug. ***
Comment 2 Noopur Gupta CLA 2016-07-15 08:03:24 EDT
*** Bug 35167 has been marked as a duplicate of this bug. ***
Comment 3 Eclipse Genie CLA 2016-07-15 08:10:07 EDT
New Gerrit change created: https://git.eclipse.org/r/77384
Comment 5 Noopur Gupta CLA 2016-07-18 04:19:12 EDT
Fixed the issues in PullUpRefactoringProcessor and released the changes with tests. 

Didn't use StubUtility2 as Pull Up refactoring uses MemberVisibilityAdjustor and ImportRewriteUtil#addImports also based on different cases.