Created
August 1, 2013 16:52
-
-
Save JefStat/6133172 to your computer and use it in GitHub Desktop.
getCurrentMethodName (wasn't quite working might need it to be static)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int getStackTraceIndexForObject(final Object object) | |
{ | |
// Finds out the index of "this code" in the returned stack trace - funny but it differs in JDK 1.5 and 1.6 | |
int i = 0; | |
for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) { | |
++i; | |
if (ste.getClassName().equals(object.getClass().getName())) { | |
break; | |
} | |
} | |
return i; | |
} | |
public static String getCurrentMethodName(final Object object) { | |
return Thread.currentThread().getStackTrace()[getStackTraceIndexForObject(object)].getMethodName(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment