Is there a way to replace all uses of one annotation with another in IntelliJ IDEA?

We are currently using JCIP annotations to check for concurrency and wanted to try switching to JSR 305 annotations for the same purpose. We'll do the same later to switch from JetBrains annotations to JSR 305 equivalents, which will be a little more difficult because they are more used.

I tried several ways to do this.

If I find and replace using naive text substitution, the imports end up out of order. In almost all cases, this breaks code style due to the import order. In some situations IDEA cannot seem to see that they are out of order and will not prompt me to fix it, so I would have to manually go through all the files, in which case I could also do all the work manually.

I tried Replace Structurally and found the whole feature to be as unusable as always. He couldn't even find the annotation.

I ended up trying to remove the @ from what I was looking for and found annotations (this is a bit ironic, although the point of this function is to find things structurally, when you actually try to find a bit of structure, it suddenly finds nothing .) Then he replaced them with a fully qualified version of the new annotation, although I told her to shorten the names. Worse, it doesn't identify those names as being unnecessarily fully qualified, so it doesn't offer an automatic fix for this, which means I can't automatically run it across all files. (It also shows that the new annotation, as a syntax error, which I can only assume is a bug.)

I also tried the Migrate function adding all the old and cool names to it and telling it to move. I found this had the same effect as Replace Structurally - it didnโ€™t do the imports, leaving me fixing them all by hand.

Maybe there is another way to do this?

+3
intellij-idea automated-refactoring structural-search


source to share


No one has answered this question yet

Check out similar questions:

442
Correct way to add external jars (lib / *. Jar) to IntelliJ IDEA project
437
Can IntelliJ IDEA encapsulate all the functionality of WebStorm and PHPStorm through plugins?
391
How can I see JavaDoc in IntelliJ IDEA?
304
What is a shortcut in IntelliJ IDEA for finding method / functions?
290
What are the most useful Intellij IDEA keyboard shortcuts?
270
IntelliJ IDEA generating serialVersionUID
265
Force Intellij IDEA re-read all maven dependencies
198
How to search all files of a project in IntelliJ Idea?
7
How to do search and replace structurally in Intellij
4
IDEA 10.0.3 replaces fully qualified declarations when refactoring



All Articles
Loading...
X
Show
Funny
Dev
Pics