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


source to share





All Articles