Reputation: 9542
Our system will go through a platform upgrade that includes the replacement of Java 1.4 with Java 6.
Ideally, we would like to use an automated tool to introduce generics and enumerations to the code wherever possible and then, obviously, we would review the changes. Is there any tool that you would recommend for this?
Upvotes: 5
Views: 265
Reputation: 718926
I'm not convinced it is necessarily a good idea to "generifying" an old codebase:
It won't improve performance, because the same class casts happen (behind the scenes) when you use generics as when you use raw types with explicit type casts.
It is unlikely to fix bugs. Significant bugs caused by casting to the wrong type have probably been found and fixed already.
So the only thing it would do is to make the code a bit more readable. And on the downside you have the effort of making the changes and testing, and the risk that you may introduce new bugs.
Upvotes: 1
Reputation: 54705
Michael is correct in that this cannot be done automatically. Given this you could consider a phased approach whereby you start by generifying your APIs / interfaces (e.g. between subsystems) by casting collections at this point to the correct type. You could also add assertions to verify that these casts were valid, which you could then later removed after testing.
Obviously the casting isn't ideal but it means you can update the API early on (assuming this is an API-based system) and then "correct" the internals later.
Upvotes: 1
Reputation: 346327
an automated tool to introduce generics and enumerations to the code wherever possible
This kind of tool is known as a "programmer". When it's available in fully automated form, you'll be out of a job (and probably spend your days as an amusing distraction to your new robotic overlords).
Seriously, this is way, way beyond what can be done automatically, especially the introduction of enumerations. The Generic type parameter for collections can perhaps be derived from context, but only for simple cases.
Upvotes: 6
Reputation: 66166
IntelliJ IDEA offers you special tool for generifying legacy collections.
Upvotes: 5