I'm finding the JPA metamodel generator functionality really useful for avoiding bugs when column names change. It would be really cool if there was some more general-purpose metamodel generation tool that you could point at any class (or a number of packages) that would generate similar metamodel classes. This could then be used to create compile errors rather than runtime ones when things change:
public class SomeClass {
public int somePublicProperty;
public String someStringMethod() {
..
}
}
This might create a metamodel class like:
public class SomeClass_ {
public static final FieldAttribute<SomeClass,Integer> somePublicProperty;
public static final MethodAttribute<SomeClass,String> somePublicMethod;
}
where FieldAttribute and MethodAttribute have useful Attribute-like methods to assist with reflection calls (i.e. remove the need to have bare strings):
Object someClassInstance = ...
Integer value = SomeClass_.somePublicProperty.get( someClassInstance );
// rather than
Integer value = someClassInstance.getClass().getDeclaredField( "somePublicProperty" ).get( someClassInstance );
Is there anything like this currently available? There's a bit of support in Java 8 now we can do method references, but I'd like something a little bit more metamodel-like if it exists.