@Transformation: Code Transformation Annotation

DZone 's Guide to

@Transformation: Code Transformation Annotation

· Java Zone ·
Free Resource

When marking code as deprecated, wouldn't it be cool if you could provide instructions for how the code should be correctly fixed? Jaroslav Tulach and Jan Lahoda from the NetBeans Team have started a new open source project at https://lang.dev.java.net/ for exactly that purpose.

To gain an instant understanding of what their project entails, look at this code:

public class Component extends Object {
displayName="Use setVisible(true)",
@Constraint(variable="$0", type=Window.class),
public void show() {

What you should see in the above code is... new annotations that supplement the @Deprecated annotation with additional annotations that provide the corrected code. Why is this useful? The project's page presents the problem statement thusly:

Using @Deprecated annotation is good hint to help your API users recognize that some part of your API is obsolete and shall no longer be used. However will your users really migrate? Will they invest their time to beautify their code without really making it work better? Usually the users have plenty other and more important things to do. The only chance for removal of uses of @Deprecated code is to make the rewrite process as automatic as possible.

In other words, if you don't do something to HELP your users upgrade, there's a good chance that they won't do so, since there are no feature benefits to be gained from migrating deprecated code. One simply achieves compliance, which is not typically the top of the list in a busy development schedule.

The @Transformation annotation is intended to be processed by an IDE, as follows for the code above, here in the case of NetBeans IDE:

 And here is another example, this time for a deprecated NetBeans API class:

Of course, the above show how the new annotations are processed in NetBeans IDE. It would be very cool if plugins were to be created for the other IDEs to process these annotations too. And that's why Jaroslav and Jan are wondering whether... anyone out there from IntelliJ IDEA or Eclipse would like to create similar support for those IDEs too? The related library of annotations is really small and manageable, as can be seen here:

If interested in being involved in this project in any way, please join at https://lang.dev.java.net/!


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}