Skip to content
Snippets Groups Projects
Commit ca27b986 authored by brinn's avatar brinn
Browse files

add: method getMethodOnStack()

SVN: 536
parent 870b8d35
No related branches found
No related tags found
No related merge requests found
......@@ -74,13 +74,28 @@ public final class ClassUtils
* Returns <code>null</code> if none could be found.
* </p>
*/
public final static Method getCurrentMethod()
{
return getMethodOnStack(2);
}
/**
* Returns the <code>Method</code> on the stack of <var>level</var>.
* <p>
* <code>level=0</code> is this method itself, <code>level=1</code> is the method that called it and so forth.
* @return <code>null</code> if none could be found.
* </p>
*/
// TODO 2007-06-14 Christian Ribeaud: 'method.getName()' is not specific enough. You have to used kind of
// or part of 'Method.toGenericString()'.
public final static Method getCurrentMethod()
public final static Method getMethodOnStack(int level)
{
StackTraceElement[] elements = new Throwable().getStackTrace();
// Index 0 is *this* method
StackTraceElement element = elements[1];
if (elements.length <= level)
{
return null;
}
StackTraceElement element = elements[level];
String methodName = element.getMethodName();
try
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment