I have a question regarding java reflection.
I need some kind of way to get the name of a specific field in a java class. Something that will work like this:
class X{
int x;
String getNameOfProperty(Object o){
....
}
}
Then, when calling
System.out.println(getNameOfProperty(x));
I would like to get “x”;
I have managed to get the fields of a class using
X.class.getDeclaredFields();
but then i don’t have any link between the property and the Field object associated with it.
You can use Abstract Syntax Tree for this purpose. For Eclipse you can find details here.
You can also use following
–ANTLR
–javaparser