Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Java Development User Guide
Previous Page Home Next Page

Extracting a new method

In this section, you will improve the code of the constructor of junit.framework.TestSuite. To make the intent of the code clearer, you will extract the code that collects test cases from base classes into a new method called collectTestMethods.

  1. In the junit.framework/TestSuite.java file, select the following range of code inside the TestSuite(Class) constructor:

    Class superClass= theClass;
    Vector names= new Vector();
    while(Test.class.isAssignableFrom(superClass)) {
        Method[] methods= superClass.getDeclaredMethods();
        for (int i= 0; i < methods.length; i++) {
            addTestMethod(methods[i],names, constructor);
        }
        superClass= superClass.getSuperclass();
    }

  2. From the selection's context menu in the editor, select Refactor > Extract Method....

    Context menu extract method

  3. In the Method Name field, type collectInheritedTests.

    Extract method wizard data input page

  4. To preview the changes, press Preview>.The preview page displays the changes that will be made. Press OK to extract the method.

    Extract method preview page

  5. Go to the extracted method by selecting it in the Outline view.

    Extracted method

Related concepts

Java editor
Refactoring support

Related reference

Java Preferences


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire