Bug 48126 - [rename] Create template method from existing code [refactoring]
Summary: [rename] Create template method from existing code [refactoring]
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-04 18:27 EST by Dirk Baeumer CLA
Modified: 2006-06-12 06:13 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 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.