cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

Convert Anonymous Inner Class to Nested Class Refactoring Specification

$Id: convertanonymoustonested.html,v 1.1 2005/03/15 13:58:11 dprusa Exp $ (see full CVS history)

Refactoring feature that allows to convert an anonymous inner class to a nested class.
Implementation of this refactoring is tracked in issue 56437.

Pre-Conditions

  1. Anonymous class residing in an editable source code base must be selected.

Pre-Checks

No specific checks.

Parameters

  1. Name of the nested class to be created.
  2. Modifiers (accessibility, static/instance class) the nested class should be created with. If the anonymous class resides in a static context, the nested class is forced to be static.

Fast Parameters Check

  1. Error: No anonymous class selected to convert to nested class.

Parameters Check

  1. Error: The selected nested class name clashes, there is already a nested class of this name.
  2. Warning: The nested class will hide nested class in a supertype, i.e. there is already an accessible nested class of the same name in a supertype.

Changes To Be Made

  1. Create the nested class in the outer class of the anonymous class. The class contains the same members and the anonymous class. In addition a proper constructor is required to be added whenever the anonymous class is instantiated by non-default constructor. In this case, the added constructor has the same number of parameters as the used constructor and in its body, the instatiation is delegated to supertype.
  2. Replace the instantiation of the anonymous class (including definition of the class) by an instantiation of the nested class.

Checks During Changes Preparation

No specific checks.

Refactoring UI

Menu item: Convert Anonymous to Nested...
Action title: Convert Anonymous to Nested - Name of Super type (e.g. Runnable)

The panel should display a text field for editing the name of the nested class. The name is preset to be of the form "MyClassName", where "ClassName" is the name of the super type which is extended by the anonymous class. The remaining part of the panel should contain a combo box for selecting accessibility modifier ("private" should be default) and a checkbox for selecting whether the nested class should be static or not (the default value corresponds to the context the anonymous class is defined in and it cannot be changed if the context is static).

------------------------------------------
|                    ------------------- |
| Inner Class Name: | newMethod        | |
|                    ------------------- |
|                    ____________        |
| Access:           | public [v]|        |
|                    ------------        |
| |X| Declare Static                     |
|                                        |
| Constructor Parameters:                |
| -----------------------  ------------- |
| | Name      | Type    |  | Move Up   | |
| |---------------------|  ------------- |
| | param_1   | int     |  ------------- | 
| | param_2   | char    |  | Move Down | |
| |           |         |  ------------- |
| -----------------------                |
------------------------------------------
Companion
Projects:
MySQL Database Server   GlassFish Community: an Open Source Application Server   Open Solaris  Open JDK: an Open SourceJDK   Mobile & Embedded Community     Sponsored by 
Sponsored by Sun Microsystems