Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
getCurrentMethodName (wasn't quite working might need it to be static)
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