StackUtilities { public static StackTraceElement myFrame() { final Thread me = currentThread(); StackTraceElement[] se = getAllStackTraces().get(me); for (int i = 0; i < se.length; i++) { String sClass = se[i].getClassName(); if (!sClass.equals(CLASS)) continue; String method = se[i].getMethodName(); if (!"myFrame".equals(method)) continue; if (i + 1 < se.length) return se[i + 1]; } throw new IllegalStateException("bad stack"); } private  StackUtilities(); static StackTraceElement callerFrame(); static StackTraceElement myFrame();  }
@Test public void test() { StackTraceElement myFrame = StackUtilities.myFrame(); assertEquals(53, myFrame.getLineNumber()); assertEquals(getClass().getName(), myFrame.getClassName()); assertEquals("StackUtilitiesTest.java", myFrame.getFileName()); assertEquals("test", myFrame.getMethodName()); }