Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] Extract Constant refactoring released

I released Extract Constant refactoring.
It was developed and submitted to us by Rory Lucyshyn-Wright (Rory_Lucyshyn-Wright(at)oti.com)
(since he's not a committer - i will maintain the code for now (using his patches <g> ))

naturally, he also wrote tests for it. :)

It's quality stuff - use it and enjoy.

a.

below is a description of the feature -  from Rory:
-------------------------------------------------------------

Yesterday, the new Extract Constant Refactoring was released.
In its current form, this refactoring operates as follows:

The user highlights an expression in the editor, then invokes the refactoring. After the user is prompted for relevant information,
a static final field is added to the innermost type declaration containing the selection. The selected expression becomes the
initializer for this field, and, within a certain scope, all occurrences of this expression are replaced by a reference to the field
(Matching is AST-based). The scope used for this replacement aims to be a largest possible subsection the of the type to which the
field was added.

Checks are performed on the selected expression. The expression must be an expression which can occur within a static initializer in
the type. The expression may, in general, reference non-static and non-final fields, including fields on instances of supertypes,
and if it does, the user will be "warned" by means of an "information" message on the first page of the wizard.

The newly created constant declaration is located as early as possible within the type in question, but such that it occurs after
the declaration of any static fields upon which the expression depends, if these are members of the same type. Thus, the scope in
which replacement occurs includes all non-static member declarations in the type in question, together with all the static methods
of the type, as well as the set of static field declarations and static initializers positioned syntactically after the location of
the new field.

The user can, by overriding a default choose to only replace the selected occurrence of the expression. Also, the user can choose to
make the constant public, protected, or package visible, instead of the default, private.

Rory Lucyshyn-Wright




Back to the top