Looking for a static import refactoring operation

Can somebody tell me if there is a refactoring operation that will
change a reference to a package qualified static to a reference to just
the static and add a static import?

For example, if I have this class

package com.foo;
import com.foo.Consts;
...
long x = Consts.SOME_CONSTANT;

I would like to highlight Consts.SOME_CONSTANT and refactor this to be:

package com.foo;
import com.foo.Consts;
static import com.foo.Consts.SOME_CONSTANT;
...
long x = SOME_CONSTANT;

I might have some syntax wrong here, but I hope it makes sense...

Cory

4 comments
Comment actions Permalink

There is no batch operation for doing this (nor should there be IMHO), but if you click on a qualified static reference and hit Alt-Enter you should be give you an option to change it to a static import. In fact, it will change it to a static * import, and shorten any other applicable references as well.

--Dave Griffith

0
Comment actions Permalink

Also there is a second intention available, that will insert single-member import and shorten references to members with that name only.

0
Comment actions Permalink

Eugene Vigdorchik wrote:

Also there is a second intention available, that will insert single-member import and shorten references to members with that name only.


Very cool. Exactly what I was looking for.

What distinguishes an intention from a refactor?

Cory

0
Comment actions Permalink

Intentions are generally local, and don't involve changing external references to the thing changed. They also don't normally involve any choices beyond whether or not to trigger it. Refactorings often have dialogs bound to them to allow choices to be made. They are also easier to learn about, since they show up in menus while intentions only show up if you select in the right place.

That's all just inside baseball. From a user's point of view, they are both refactorings.

Sixth and Red River Software
"Code with Grace and Verve"

0

Please sign in to leave a comment.