Bug 48126

Summary: [rename] Create template method from existing code [refactoring]
Product: [Eclipse Project] JDT Reporter: Dirk Baeumer <dirk_baeumer>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: n.a.edgar
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Dirk Baeumer CLA 2003-12-04 18:27:04 EST
Form the news group

I am trying to change the setUp method in my test suite so that it performs
some standard behaviour and delegates to a new method, uiSetUp.  I have my
own abstract superclass for the tests: UITestCase.  I want to change
existing subclasses (about 35 of them) from overriding setUp to overriding
uiSetUp.
Likewise for tearDown.

For example, the old code is:

public abstract class UITestCase extends TestCase {
  // setUp is not overridden from JUnit's TestCase class

}

public class ConcreteUITestCase extends UITestCase {
   protected void setUp() {
       // do some test-specific setup (most implementations don't currently
call super)
   }
}

The new way should be:

public abstract class UITestCase extends TestCase {
  protected final void setUp() {
     // do some standard setup, common to all tests, which can't be
overridden)
     uiSetUp();
  }

  protected void uiSetUp() {
     // do nothing by default
  }
}

public class ConcreteUITestCase extends UITestCase {
   public void uiSetUp() {
       // do some test-specific setup
   }
}

I tried simply renaming setUp to uiSetUp in UITestCase, but it won't let me
do that without starting at the highest declaration of setUp in TestCase.

Can any of the existing refactorings help with this change?

Thanks,
Nick
Comment 1 Dirk Baeumer CLA 2003-12-04 18:27:44 EST
Unfortunatelly not. The rename refactoring is semantic preserving. 
So if you rename setup it renames all methods in the hierarchy with 
the same signature and all references to them.

The refactoring you are requesting is something like: "convert method into
template method and create delegate with existing signature". I will open
a feature request.  
Comment 2 Martin Aeschlimann CLA 2006-06-12 06:13:58 EDT
We have now rename method and keep delegate. I guess the refactoring could allow the rename of all method in source (and keep the one in binary), if you choose not to rename all references.