Java: De-deprecated-ing Tools

Go To StackoverFlow.com

5

Once a method is marked as deprecated, are there any tools which replace these methods with non-deprecated workarounds ?

2009-06-16 08:26
by Ande TURNER
That must be the most complicated title I have ever seen : - Boris Callens 2009-06-16 08:27
... and I was trying to be concise. do - Ande TURNER 2009-06-16 08:29


4

Automated tools could only reasonably handle cases where there's a new preferred method or class to use to accomplish exactly the same task. Any case where a method is deprecated because of defective design (think anything dealing with date's in Java) or because a "better" way is now supported (think AWT to Swing or SWT) requires far to much thought to be automated.

In short, no there are no such tools. I doubt there ever will be any in the future as well.

2009-06-16 08:38
by Kevin Montrose


12

If you would like to do this automatically - no.

The tool is called a programmer.


The reason is that the tools would need to profoundly understand both the deprecation, the 'un-deprecation' , your program and the target programming language.

For instance, java.util.Date.setMonth is deprecated in favour of Calendar.set(Calendar.MONTH, int month).

That is a non-trivial change to apply, since it requires replacing object instantiations, method calls, taking into account synchronisation. Actually nightmarish to do automatically.

2009-06-16 08:29
by Robert Munteanu
Although a funny response, it's not really taking the question seriously - - krosenvold 2009-06-16 08:31
@krosenvold: I'm almost always half tongue-in-cheek, it's my way of presenting arguments. I did not poke fun at the question, and I stand by my opinion. And thanks for the +1 Funny/-2 Not serious mod :-), but especially for leaving a comment - Robert Munteanu 2009-06-16 08:37
Your recent edit is nice - krosenvold 2009-06-16 09:49
I agree with this response =) If the original implementation of a class/method is considered so poor that it can't be fixed without breaking legacy code, then the change must be nontrivial.

In other words, if you can't search/replace your way out of the problem, you probably have to do it by hand anyway - mikek 2009-06-16 16:00



2

Usually, you should use something like regexps, ANTLR or JavaCC for implementing your own tool.

Besides, some IDEs offers relatively higher-level tools for facilitating this. In IntelliJ IDEA these are "Structural Search and Replace" and "Migrate" refactoring.

2009-06-16 09:06
by Rorick


1

I can't see how this would work at the moment. Typically at least some thought needs to go into changing the client code. Ideally the deprecated method will include a comment saying, "Use method X instead, passing in null as the final parameter" or something similar, but only in the simplest cases could this be fully automated. Often there'll be something like "If you need to deal with null entries, use X. Otherwise, use Y."

(In addition, even in the simplest cases, there's no current way of representing the transformation in a machine-readable format - basically the appropriate protocol hasn't been defined as far as I'm aware.)

It's a nice idea, but I suspect that to implement it in a useful way would introduce more complexity than it would remove. Additionally, I'd be very wary of a tool doing this for me completely automatically - I'd probably want to preview every change anyway. At that point, it usually wouldn't save much time over doing it manually to start with.

2009-06-16 08:31
by Jon Skeet