Let's Swing!
A globally warmed, Swing focused blog in the Participation Age.
I've definitely moved this blog to my personal site!

Extending javac with annotations...

miércoles octubre 26, 2005 | Java Swing | Permalink | Comentarios [4]

Oh, my. This is so sweeeet. Imagine you can plug-in your annotation processor within javac. And then recompile the generated code. This is impressive.

The possibilities of this feature are immense. Take for instance EJB 3.0. You annotate your EJBs and your Web Services. Then some source code (remote interfaces, home interfaces, WSDL, etc.) is generated for you by annotation processors. And then this generated source code is compiled too.

For we enjoying Swing things may be easier, too. We may end up writing things like this:


@actionPerformed( ActionListener="myButtonActionPerformed" )
JButton myButton;

...

@ActionListener("myButtonActionPerformed")
private void whatever( ActionEvent actionEvent )
{
  ...
}

This, we could annotate listeners and then recursively generate new source files and class files, generating and adding anonymous action listeners at compile time.

Quite impressive, indeed. Now, don't you think annotations are the Next Big Thing in Java?

Cheers,
Antonio

Comentarios:

I think they sound cool and all, but not using them as of yet, the verdicts still out for me. To much 1.4 code to deal with as of yet... I really need to make time to try them at home.

Enviado por Jeffrey Olson en octubre 26, 2005 a las 07:27 PM CEST #

That sounds horrible. I've been using 1.5 for a few months now, and we're using annotations for several things, both spec defined (JAXB2) and our own custom validation framework. However, I dont like the idea of the example you give above - I'd like to know when the listener is attached. If we were to go down that route I'd prefer to see a way of identifying methods, eg:
@actionPerformed( ActionListener=#whatever(ActionEvent) )
JButton myButton;

...

private void whatever( ActionEvent actionEvent )
{
  ...
}

Enviado por Dmitri Colebatch en octubre 27, 2005 a las 01:10 AM CEST #

Java 5 ships with APT, and for one reason or another, noone ever seems to talk about it or consider it to be a viable option. Have you looked at APT?

Enviado por R.J. en octubre 27, 2005 a las 05:14 AM CEST #

What is it you'd do with APT? To me code generation is a hack. If it can be generated, then we shouldn't need to generate it. Whatever looks at the generated code should instead look at whatever it is the code generator would look at. There are exceptions to this of course, generating stubs in a different language is probably the most obvious. But as a general rule you shouldn't need to generate code, and if you do I'd argue that its only because the language hasn't kept up (look at XDoclet and EJB3).

Enviado por Dmitri Colebatch en octubre 27, 2005 a las 05:46 AM CEST #

Enviar un comentario:

Los comentarios han sido deshabilitados.

Categories


Search


Recent entries


Sites I find interesing

Aggregators
Swing focused
Software architecture related @ blogs.sun.com

Calendar

« diciembre 2009
lunmarmiéjueviesábdom
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Hoy

Navigation


Visits

Locations of visitors to this page