mercredi 14 janvier 2015

Java Reflection: Find method usage in custom AbstractProcessor

I'm newbie in reflection. Is there any way to detect where is an specific method invoked? For example:



public class MyClass {

public static void method(){//DO SOMETHING}

}

public class Test {

public test(){
MyClass.method();
}

}

public class MyProcessor extends AbstractProcessor {

public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

Method method = MyClass.class.getDeclaredMethod("method");

Class classWhereMethodIsInvoked = obtainClassWhereMethodIsInvoked(method);

}

public Class obtainClassWhereMethodIsInvoked(Method method) {
//here I want to search one class that invoke that method, in this case Test.class
}

}


is something like this possible or I am going crazy?






Aucun commentaire:

Enregistrer un commentaire