Refactoring Listeners

Hi,

I am trying to write a plugin that needs to be notified when a refactoring of the class has happened. Using RefactoringElementListener I can intercept Rename refactorings but they do not receive any nptifications for Extract Superclass refactoring. Is there are any way to intercept such refactorings?

Many Thanks,

Misha

9 comments
Comment actions Permalink

No, there is no way you can intercept it now. Probably there is some other way you can do it. What plugin are you implementing?

0
Comment actions Permalink

We are DBMS vendors, our product is called Cache. We are now coming out with a Java Persistence framework for our database along EJB3 Persistence lines, though slightly different.

I am implementing a plugin to integrate Cache to Java IDE. We create database shema based on a set of given Java classes. One piece of functionality is to refactor database schema when Java classes are refactored while preserving data in the database. We now support 4 refactorings:

- Rename property (rename corresponding column)
- Push down a property into subclass (move column to corresponding table)
- Pull up properties to to a subclass (move column to corresponding table)
- Extract superclass (create corresponding table, set up relationships and pull up some properties).

All 4 work for NetBeans. For IDEA so far I was able only to enable the first one.

I would appreciate any help you can offer.

0
Comment actions Permalink

Hi Eugene,

Eugene Vigdorchik wrote:

No, there is no way you can intercept it now. Probably there is some
other way you can do it. What plugin are you implementing?


The possibility to listen to all refactoring events would also be
mightily useful for a "Refactoring Script" plugin...

Bas

0
Comment actions Permalink

Bas,
I'm afraid having ALL refactorings sending events requires much more work, and won't be implemented in 6.0

0
Comment actions Permalink

Hello Eugene,

Eugene Vigdorchik wrote:

Bas, I'm afraid having ALL refactorings sending events requires much
more work, and won't be implemented in 6.0


Perhaps in the next version then. At least there is enough now for a
proof of concept plugin. Should I submit a JIRA request?

Thanks,
Bas

0
Comment actions Permalink

The desired refactorings now broadcast memberMoved event. The subscription is through RefactoringElementListenerManager.

0
Comment actions Permalink

Hi Eugene,

I understand how pull/push properties will broadcast memberMoved event. I still have a question about extract superclass. This also changes class declaration itself. Will this change be broadcasted?

Thanks,

Misha

0
Comment actions Permalink

No, if I understand correctly, you can update your model by getting memberMoved event and analyzing the target of the move is not known to you. Or am I wrong?

0
Comment actions Permalink

You are of course right. But it would be more convenient if I can see actual addition of a superclass event. I can think of several reasons why this may be useful:

- Distinguish from "Move" refactoring that moves static fields/methods. Of course I can infer it from the context but it would be too much guesswork altogether.

- Ideally I am interested in what annotations to move/copy to superclass. It is probably not yet supported feature but may be useful in the future.

- When I extracting superclass I have an option to move implemented interfaces to superclass declaration. It may be pretty important to me.

- In general, changing of declaration of class C from "extends A" to "extends B" has important consequences for database schema. It will cause significant changes to schema, possibly irreversible (well short of transaction roll-back or journal restoration). Such drastic actions is better to base on the concrete fact rather than on a inferring logic.

Thanks,

Misha

0

Please sign in to leave a comment.