Reputation: 2724
In order to implement a feature in a project I'm working on, I've had to throw a checked exception from a method which is used, in cascade, by hundreds of other methods throughout tens of other classes in the whole project. Consequently, I have got to do some heavy refactoring which Intellij assists me in doing with pop-ups like this one:
Now, while this intellij feature is very helpful, having to go through the whole codebase is still taking a (to me) unbearable amount of time. The task is actually very repetitive:
e.printStackTrace()
call that gets automatically emitted with code of my own.So, the question is: is there any way to automate this process in IntelliJ?
Upvotes: 3
Views: 1332
Reputation: 91
In a general point of view IntellJ IDEA has a batch refactoring feature which can be accessed as follows:
I believe it depends on the inspection and the resolutions available for that.
Upvotes: 1
Reputation: 2678
The only automated way I've found for this is to use the refactoring. On the method that is to throw an exception, choose refactor->change signature. Add in the exception to the signature. Choose the option to propagate the exception and then choose refactor.
It should then add throws clauses to all the methods which call the function.
This works fine for a small number of methods. I haven't tried it with hundred of methods.
Unfortunately I couldn't get the code analysis, which has a "fix all" option, to report this error. If it did report the error then that would've been a simpler way of fixing all the problems.
Upvotes: 2