01: package org.drools.repository;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.PrintWriter;
05: import java.util.StringTokenizer;
06:
07: public class StackUtil {
08:
09: /**
10: * Return the name of the routine that called getCurrentMethodName
11: *
12: * @author Johan Känngård, http://dev.kanngard.net
13: * (found on the net in 2000, donŽt remember where...)
14: */
15: public static String getCurrentMethodName() {
16: ByteArrayOutputStream baos = new ByteArrayOutputStream();
17: PrintWriter pw = new PrintWriter(baos);
18: (new Throwable()).printStackTrace(pw);
19: pw.flush();
20: String stackTrace = baos.toString();
21: pw.close();
22:
23: StringTokenizer tok = new StringTokenizer(stackTrace, "\n");
24: String l = tok.nextToken(); // 'java.lang.Throwable'
25: l = tok.nextToken(); // 'at ...getCurrentMethodName'
26: l = tok.nextToken(); // 'at ...<caller to getCurrentRoutine>'
27: // Parse line 3
28: tok = new StringTokenizer(l.trim(), " <(");
29: String t = tok.nextToken(); // 'at'
30: t = tok.nextToken(); // '...<caller to getCurrentRoutine>'
31: return t;
32: }
33:
34: }
|