Mirror - DSL for Reflection API

Subheadline: 
Mirror DSL is a simple DSL layer to make Java Reflection easier.

Mirror is a simple DSL layer over Java Reflection API, designed to make the use of this powerful tool easier. Nothing of those three thousand exceptions thrown at your face. Neither those completely unreadable lines of code.

Simplicity is really powerful too.

Dealing with Java Reflection API is painful. Ask anyone you know that uses reflection and he will tell you it's really unpleasant getting yourself around it. 

This project was created to bring light to a simple problem, usually name ReflectionUtil, which is on almost all projects that rely on reflection to do advanced tasks.

See more details in the project site: http://projetos.vidageek.net/mirror/mirror/

Location: 
Brazil
0

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Jacek replied on Fri, 2008/11/21 - 7:53am

Reflection is painful? I learned most of it in 1-2 days and have never had any issues with understanding it.

I actually find it very easy.  Sure, I had to write 3-4 util methods for some common tasks, but that's a given on any API.

 

David Green replied on Fri, 2008/11/21 - 2:12pm

nice project.  the idea of a DSL for reflection is good, however the language of a DSL must feel natural.  Your example:

Mirror.on(target).set().field(fieldName).withValue(value)

would feel better to me if it read like this:

Mirror.on(target).field(fieldName).set(value)

overall, good work. 

Ayman Al-Sairafi replied on Mon, 2008/11/24 - 3:22am

Good work. 

However I do not see an improvement in changing:

ReflectionUtil.setField(target, fielName, value);to Mirror.on(target).set().field(fieldName).withValue(value); as a big improvement.  But that's just my own opinion.  Also, does your library support caching?  Reflection can be very expensive, and caching the Field and Method objects will boost performance considerably.  

jonasabreu replied on Mon, 2008/11/24 - 12:27pm

Hello all, 

I'm Mirror's developer leader. Thanks for the feedback.

@Jacek

Reflection has simple comcepts, but it's not really pleasant to use (all those checked exceptions and modifiers). It can turn your code into something really cryptic.

@David 

One point we focused while developing was keeping Mirror's DSL as readable as possible. Right now, we are studying some changes to DSL, in order to make it more practical.

@Ayman 

Thats exactly the point we are working on right now. Caching and different reflection providers (like directly analyzing bytecode using ASM). 

About using a DSL or a class full of static methods, I prefer the first one because it is more readable. Also, it's easier to test .Usually, a reflection util class will have all the code inside it (I have found ReflectionUtil classes with more that 800 lines - without comments). The way we designed it, we have better separation of responsabilities.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.