This method shows the last 3 points of the method call hierarchy in the order they were called, ignoring the last 2 methods, which include the following method. This is very useful to catch the hierarchy of methods in a software module, where there are multiple access paths to the same location.
private static String getRecentSteps() {
String recentSteps = "";
StackTraceElement[] traceElements = Thread.currentThread().getStackTrace();
final int maxStepCount = 3;
final int skipCount = 2;
for (int i = Math.min(maxStepCount + skipCount, traceElements.length) - 1; i >= skipCount; i--) {
String className = traceElements[i].getClassName().substring(traceElements[i].getClassName().lastIndexOf(".") + 1);
recentSteps += " >> " + className + "." + traceElements[i].getMethodName() + "()";
}
return recentSteps;
}
source
share