org.alicebot.server.core.util
Class StackParser

java.lang.Object
  extended by org.alicebot.server.core.util.StackParser

public class StackParser
extends java.lang.Object

Parses the stack trace. This code was adapted from a Usenet post by Simeon Fitch.

Author:
Simeon Fitch sfitch@swri.org
See Also:
reference

Method Summary
static java.lang.String getStackMethod(int level)
          Gets the name of the method in the stack the given number of levels down (not including call to getMethodInStack).
static java.lang.String getStackMethod(java.lang.Throwable throwable, int level)
          Gets the name of the method in the stack the given number of levels down (not including call to getMethodInStack).
static java.lang.String getStackMethodBefore(java.lang.String search, boolean prettify)
          Gets the name of the most recent method in the stack that does not include the given search string.
static java.lang.String getStackString(java.lang.Throwable throwable)
          Creates a string containing the stack backtrace of the given Throwable object.
static java.util.StringTokenizer getStackTraceFor(java.lang.Throwable throwable)
          Returns the backtrace of a given throwable as an enumeration of lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStackMethod

public static java.lang.String getStackMethod(java.lang.Throwable throwable,
                                              int level)
Gets the name of the method in the stack the given number of levels down (not including call to getMethodInStack).

Parameters:
throwable - throwable from which to get stack trace
level - number of stack frames to go down.
Returns:
method name if found, null otherwise

getStackMethod

public static java.lang.String getStackMethod(int level)
Gets the name of the method in the stack the given number of levels down (not including call to getMethodInStack).

Parameters:
level - Number of stack frames to go.
Returns:
Method name if found, null otherwise.

getStackMethodBefore

public static java.lang.String getStackMethodBefore(java.lang.String search,
                                                    boolean prettify)
Gets the name of the most recent method in the stack that does not include the given search string. If prettify is true, also removes whatever looks like a package name from the result.

Parameters:
search - the string which, if found in the method name, disqualifies it

getStackString

public static java.lang.String getStackString(java.lang.Throwable throwable)
Creates a string containing the stack backtrace of the given Throwable object.

Parameters:
throwable - source of backtrace
Returns:
String containing backtrace

getStackTraceFor

public static java.util.StringTokenizer getStackTraceFor(java.lang.Throwable throwable)
Returns the backtrace of a given throwable as an enumeration of lines.