Replace in Path and Java imports -- any way to get these to work together?

I'm updating a ton of code from hibernate 3.x up to 4.0 and need to do a ton of batch search/replace operations.

Doing a batch search/replace is easy, I use Replace in Path, and then click on All Files when the replace dialog comes up.

The problem I run into is that the newly inserted java code doesn't work correctly without an import, and the old import for the deleted code isn't removed. Normally I never edit import statements directly, I let the editor take care of that for me. In this case, if I perform the replace in an open file, and wait a second, the editor fixes up the imports for me and I can keep going. But in the batch case the files are never opened in an editor (as far as I can tell) and the import changes aren't made. So later on I get a compile error, I open the files in the editor, wait a second for the fix to take place, and then save the buffer.

It would be great if the Replace operation did this for me, even better if it made it all part of a single undo-able operation in case I want to back out my change.

Thanks!

5 comments
Comment actions Permalink

Hi.

Maybe main menu / Refactor / Migrate (don't be confused with Type Migration) can help you. It's a kind of type search/replace without checking for interface compatibility. (Type Migration is with this check.)

Regards,
Alexander.

0
Comment actions Permalink

Thanks for the suggestion, I'll give it a try next time.

0
Comment actions Permalink

This feature looks promising but I wasn't able to make it work for me. There isn't much documentation on it so maybe I'm just using it incorrectly.

The case I'm trying to fix is changing all uses of one class to another. In this case the import for the new class is most likely already present, and if the old import isn't deleted it's not the end of the world, since the API was deprecated and is not yet deleted. So this is an "easier" case.

So in the Migrate dialog I create a new migration map with a single Class migration type. I tried using both the fully qualified class name (org.hibernate.criterion.Expression) and just the class name (Expression) but in both case when I run the migration it says that there were "No Usages Found in the Project". Now, the Add dialog does say "Edit Class/Package Migration Description" so maybe this is just editing the name, and not the implementation of the migration.

To be more specific, here's what I have:


import org.hibernate.criterion.Expression;

import org.hibernate.criterion.Restrictions;


...

        if (instanceId != null) {             createAlias(c, "event", "event");             c.add(Expression.eq("event.instanceId", instanceId)).addOrder(                     Order.asc("dateEffective"));         }



And I want to replace "Expression" with "Restrictions" in this code. The code is all parsing fine and doesn't have an errors showing in the editor, I can navigate it using Show Usages, etc.
0
Comment actions Permalink

I've made a test module with 2 libraries in dependencies, one with a class like "devnet.pack1.Referred", another is "devnet.pack2.Referred".

Provided a source code with a reference to the first class, and class-to-class migration map, applied, and it works.

Do you see something different to your case here? What are 2 hibernate class names you are trying? Maybe some hibernate class is not in module dependencies?

Alexander.

0
Comment actions Permalink

Thank you for taking the time to try this out.

ache wrote:

I've made a test module with 2 libraries in dependencies, one with a class like "devnet.pack1.Referred", another is "devnet.pack2.Referred".

Provided a source code with a reference to the first class, and class-to-class migration map, applied, and it works.

Do you see something different to your case here? What are 2 hibernate class names you are trying? Maybe some hibernate class is not in module dependencies?

Alexander.


Both classes are in the dependency list for this module, as I said in my post the code parses fine and doesn't show any errors in the editor. Both classes are in the same package, "org.hibernate.criterion", and the class names are "Expression" and "Restrictions".

However, I did try and make a test project with a very small bit of code and it worked in that case, as long as I used the qualified class name. I'll have to do some more testing to see if I can figure out why it wasn't working in my larger project. I'm sure I'll have a few more changes of this nature to make before I'm done.

0

Please sign in to leave a comment.