config/.vim/eclim/doc/vim/java/refactor.txt

171 lines
5.4 KiB
Plaintext
Raw Normal View History

*vim-java-refactor*
Refactoring
***********
Note: All the refactorings are performed externally with Eclipse and with
that comes a couple caveats (|vim-issues|). In the event that you
need to undo a refactoring, please see the |:JavaRefactorUndo| and
|:History| commands.
Warning: Refactoring support in eclim is very new, so it should probably be
considered alpha quality. Eclim uses the eclipse provided
refactoring apis, so it should be safe to use, but please do so with
caution. If something does go wrong and you need to revert a failed
refactoring, please first try the |:JavaRefactorUndo| command. If
that fails to revert the changes, you can then try using the
|:History| command for each file that was changed.Be sure to report
your experiences, good or bad, on the eclim-user
(http://groups.google.com/group/eclim-user) mailing list as well.
*:JavaRename*
Rename
======
The first refactoring that eclim supports is :JavaRename, which can be
used to rename various java elements.
Example:
>
package org.foo.bar;
public class Foo {
public void bar(){
}
}
<
To rename the class from 'Foo' to 'Bar' you simply position the cursor
over the class name 'Foo' and execute:
>
:JavaRename Bar
<
The result of which will the following prompt:
>
Rename "Foo" to "Bar"
([e]xecute / [p]review / [c]ancel):
<
This prompt give you three options:
1. execute: Execute the refactoring without previewing the changes to
be made. The current file and any other changed files open in the
current instance of vim will be reloaded.
2. preview: Preview the changes that the refactoring will perform.
This will open a scratch buffer with a list of changes to be made
along with a link at the bottom to execute the refactoring.
The contents of the preview window will vary depending on what you
are renaming.
If we are renaming 'Foo' to 'Bar' the contents would be like so:
>
other: Rename compilation unit 'Foo.java' to 'Bar.java'
|Execute Refactoring|
<
If we are renaming the method 'bar' to 'foo', the contents would
look like so:
>
|diff|: /home/someuser/workspace/test_java/src/org/foo/bar/Foo.java
|Execute Refactoring|
<
If the first instance, there is not much to preview. Since this
particular class is not referenced anywhere else, the only
operation eclipse will perform, is to rename the file from
'Foo.java' to 'Bar.java' which will also update the class name in
that file.
In the second instance eclipse provides a preview of the actual
changes to the file what will be performed. If the method were
referenced elsewhere, you would see an entry for each file that
would be modified by the refactoring. To actually for a vim diff
split of the changes that will be performed, simple position the
cursor on the diff entry and hit <enter>.
Once you are satisfied with changes that eclipse will perform, you
can then execute the refactoring by positioning the cursor over the
"|Execute Refactoring|" link and hit <enter>.
3. cancel: Cancel the refactoring (Hitting enter without typing a
choice or hitting Ctrl-C will also cancel the refactoring).
Package Renaming
Renaming a package is performed just like renaming any other element.
However, the name you supply to the :JavaRename command must be the
full package name that you are renaming the package to. For example.
In sample java file above, if you place the cursor on the 'org'
portion of the package declaration, you can rename 'org' to 'com' by
running :JavaRename com. If you want to rename the 'foo' package to
'baz' you can do so by running :JavaRename org.baz. Note that if you
were to only supply the name 'baz', the 'foo' package would be moved
to the same level as 'org' and then renamed.
Warning: When renaming a package, the associated directory will also be
renamed in the underlying file system. Eclim will do its best to
reload any files that have moved as a result of the directory
renaming and adjust your current working directory if necessary, but
only for the current vim session. If you have other vim sessions
open with files located in the directory that is renamed, then eclim
will be unable to reload those files in those sessions for you, so
you will have to do so manually. A best practice would be to close
any other vim sessions that might be affected by the renaming of a
package.
*:JavaRefactorUndo* *:JavaRefactorRedo*
Refactor Undo/Redo
==================
In the event that you need to undo a refactoring, eclim provides the
:JavaRefactorUndo command. When executed, the last refactoring will
be reverted. If you are unsure what the last refactoring was, the
:JavaRefactorUndoPeek command will provide a hint of the top most
refactoring on the undo stack. Unfortunately the hint doesn't provide
details beyond the type of refactoring that will be undone, but it can
still be helpful at times.
Eclim also provides the :JavaRefactorRedo and :JavaRefactorRedoPeek
commands which provide the redo counterpart to the undo commands.
Configuration
=============
Vim Variables
*g:EclimRefactorDiffOrientation*
- g:EclimRefactorDiffOrientation (Default: 'vertical') - Specifies the
orientation used when previewing a refactoring and performing a diff
split between the current file contents and the changes to be
performed by the refactoring. Possible values include 'vertical' or
'horizontal'.
vim:ft=eclimhelp