| Summary: | [pull up] Pull Up refactoring to interface generates broken code | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Carsten Reckord <reckord> |
| Component: | UI | Assignee: | 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: | |||
*** Bug 444002 has been marked as a duplicate of this bug. *** *** Bug 35167 has been marked as a duplicate of this bug. *** New Gerrit change created: https://git.eclipse.org/r/77384 Gerrit change https://git.eclipse.org/r/77384 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a2db02a5370121790fc04dfd719f54f39ad664e0 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. |
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) { }