protected static StackTraceElement getTraceElementAt ( int level ) { if ( level < 0 ) { return null ; } try { final StackTraceElement [ ] stackTrace = Thread . currentThread ( ) . getStackTrace ( ) ; int j = - 1 ; boolean found = false ; Class < ? > type ; for ( int i = 0 ; i < stackTrace . length ; ++ i ) { if ( found ) { if ( ( i - j ) == level ) { return stackTrace [ i ] ; } } else { type = loadClass ( stackTrace [ i ] . getClassName ( ) ) ; if ( type != null && Caller . class . isAssignableFrom ( type ) ) { j = i + 1 ; } else if ( j >= 0 ) { // First ocurrence of a class in the stack, after the // inner invocation of StackTraceCaller found = true ; if ( ( i - j ) == level ) { return stackTrace [ i ] ; } } } } } catch ( AssertionError e ) { throw e ; } catch ( Throwable exception ) { // } return null ; }
Replies the stack trace element for the given level .