Reputation: 86449
I would like to replace one annotation type with another, throughout a large codebase.
This requires updating import
statements and the annotations themselves.
Is there a mechanism to do this in the Eclipse IDE other than possibly naive textual search/replace?
For example:
import edu.umd.cs.findbugs.annotations.NonNull;
...
public @NonNull Integer
foo( @NonNull Integer arg0 ) { ... }
Needs to be updated to:
import javax.annotation.Nonnull;
...
public @Nonnull Integer
foo( @Nonnull Integer arg0 ) { ... }
Upvotes: 4
Views: 252
Reputation: 5569
It's easy in Eclipse.
edu.umd.cs.findbugs.annotations.NonNull
and click the Search button.javax.annotation.Nonnull
in the With: box and click OKThe above would replace the import
s, then you'd go through these steps again to replace the @NotNull
uses.
If you prefer to use the refactoring tool, there is a way to go about this. But it's pretty involved, especially if you don't have access to the source code of the identifier you wish to move away from.
edu.umd.cs.findbugs.annotations.NonNull
from a jar file. Ideally you'd have access to the source code, but you could also stub out the annotation. In any case, you'd remove the third-party jar file from your project and replace it with source code in your project, then get a clean build.Refactor->Rename...
it to the target name then Refactor->Move...
it to the target package. You might have to create the package in your project first.Upvotes: 2