Replacement for deprecated items in java
I am currently on a task, where I need to fix the deprecated items in the ex开发者_如何学Cisting projects. I mean I have to replace the deprecated items with the corresponding replacing items as given in javadocs,
Eg: java.util.Date.setSeconds(int)
: Instead of this deprecated method, we need to use Calendar.set(Calendar.SECOND, int seconds)
.
I need to automate this using java code in eclipse IDE, by giving a project name in the workspace as input.
Kindly suggest me in doing this.
Thanks in advance.
I would go with the search & replace functionality of your IDE, by utilizing regex. (your parameter values should be captured with regex)
There isn't any specific utility to replace deprecated code, because it is not always that case that there is a straightforward replacement. Sometimes there is not replacement, and in other cases there is a completely different approach.
If the project is not really big probably easiest way is to do this by hand. It also handles the situations where there is no direct replacement.
Alternative (and definitely more interesting) way would be to write an eclipse plugin that extends eclipses JDT. Also if you are on Java 6 one possibility is to use Java compiler API.
精彩评论