vendredi 25 mars 2016

Java: list fields used in a method

In Java, how can I get the Fields that are used in a method ?

Basically, this is the same questions as this one in .NET. I dont wan't to list the fields from a Class, but to list the fields that are used in a given method of the class.

Example:

public class A {
 int a;
 int b;

public int bob(){
 return a-b;
}

I want to get the fields like this:

Fields[] fields = FieldReader.(A.class.getMethod("bob"));

So that fields[0]=A.a and fields[1]=A.b

I didn't find any solution using standard Reflection. Do you think bytecode manipulation library such as ASM are a way to go ?





Aucun commentaire:

Enregistrer un commentaire