Sunday, September 6, 2009

Paranamer 2.1 released

Paranamer gives you a String array of parameter names for a Java method:

Method doFoo = Foo.class.getMethod("doFoo",
String.class, String.class);

String[] paramNames
= paranamer.lookupParameterNames(doFoo);

It is very embeddable and can either retrieve this parameter information from a class' debug tables, or from an added static field (added by QDox and ASM).

If you are writing a Java IDE, as web-framework, a SOAP transport, a DI Framework (etc), you are going to want to depend on Paranamer (and maybe consume the 27K or less of bytecode into your jar using JarJar or Maven's Shade).

This release updated QDox and ASM dependencies and added a NullParanamer implementation (NullObject pattern).

See the project site.

1 comment:

Clinton Begin said...

Paul! Nice to see you're still quite active in OSS. I also saw the new release of QDox, congrats.

You know what's really sad about the whole parameter name thing? Sun could easily implement this by piggybacking on Annotations.

Consider that you could annotate a method's parameters with:

void blah(@ParamName("id") String id);

And retrieve it with method.getParameterAnnotations().

Now consider if the Java Compiler did this automatically... simply by adding runtime annotations containing the name of every method parameter.

You could retrieve them the same way, or it would be nice if they simply added a convenience method like: method.getParameterNames()

There's a lot of ways to do it, but this one would be backward compatible. Not sure about any performance implications regarding adding so many annotations to every class... but any time I ask why annotations suck so bad in Java, the answer I get is "so that they perform well"... so I'd hate to hear that this would be a performance burden. :-)

Cheers,
Clinton