Search code examples
javaandroidbroadcastreceiverantlrgrammar

How to get the java Class to which a method belongs given the method signature?


I am using ANTLR on the Java8 grammar to parse some Android code, and I'm searching for method invocations having the signature abortBroadcast(). However, I need to check if abortBroadcast() is the method from BroadcastReceiver class, not some method from another class. Is there any way I can get the Class to which the abortBroadcast() method belongs?


Solution

  • Use Thread.currentThread().getStackTrace() to get stack trace - there you can find all function calls in current thread. And for every element call getMethodName() to find your abortBroadcast(), the getClassName() will show you class.