Use Field Instead of Literal Refactoring Specification
Author:
Hugues Ferland
$Id: usefieldinsteadofliteral.html,v 1.2 2005/11/09 04:13:26 hferland Exp $ (see full
CVS history)
This refactoring goal is to provide an easy way to
replace occurences of a literal in a class (or in
classes) by a class field (static final) created or
not at the same time.
Pre-Conditions
No pre-condition. It should be possible to enter every
parameters in the refactoring dialog.
Pre-Checks
No pre-check.
Parameters
- The literal to replace (the type must be unambiguous). Default to the
currently selected literal if any.
- The name of the field to create/use. No default.
- The name can be fully qualified to create/use the field in
a specific class.
- The name can be the field name alone to create/use the field in the
currently selected class, if any.
- Access
- If the field does not exist, the user choose one from "private",
"protected", default or "public".
Defaults to "private" if the field is to be created in
the current class, "public" if in another class.
- If the field already exist, this parameter is disabled.
- Classes to apply the modification to. Default to the current class if any.
Fast Parameters Check
- Error: The field already exist but is not "static final".
- Error: The field does not exist, and the class where to create it is
not in one of the openned project.
- Error: The field does not exist, and the class where to create the
field is read only.
- Error: The field is not fully qualified, and no class is currently
selected.
Parameters Check
No specific checks
Changes To Be Made
- If the field does not exist, create it in the specified class.
- For every selected class, find every occurence of the literal and
replace them with a reference to the specified field.
Checks During Changes Preparation
- Only classes that has access to the field can be refactored.
Refactoring UI
Menu item:
Use field instead of literal
Action title:
- If a literal is under current cursor position
- Use field instead of ...
- If no literal is under current cursor position
- Use field instead of literal
+-----------------------------------------------+
| Literal : [ ] |
| Field : [ ] |
| Access : [ public |v] |
| | protected | |
| | default | |
| | private | |
| +----------------+ |
| Apply refactoring to : |
| +-------------------------------------------+ |
| | ( ) All opened projects | |
| | (o) Project: [Project 1 [v] | |
| | ( ) Package: [org.netbeans [v] | |
| | ( ) Class: <currently selected class> | |
| +-------------------------------------------+ |
| |
+-----------------------------------------------+
NOTES
- When the access is changed, elements of the "apply refactoring to"
options should be enabled/disabled accordingly.
- Even though we may start the refactoring when the cursor is on a literal,
the literal may still be changed from the original selected one. In which
case, the original literal will not be modified.
- If the specified field already exist (and is "static final", the Access
field will be disabled and changed to reflect the current access of the
field.