CallerFinder { @NullableDecl public static StackTraceElement findCallerOf(Class<?> target, Throwable throwable, int skip) { checkNotNull(target, "target"); checkNotNull(throwable, "throwable"); if (skip < 0) { throw new IllegalArgumentException("skip count cannot be negative: " + skip); } StackTraceElement[] stack = (stackGetter != null) ? null : throwable.getStackTrace(); boolean foundCaller = false; try { for (int index = skip; ; index++) { StackTraceElement element = (stackGetter != null) ? stackGetter.getStackTraceElement(throwable, index) : stack[index]; if (target.getName().equals(element.getClassName())) { foundCaller = true; } else if (foundCaller) { return element; } } } catch (Exception e) { return null; } }  @NullableDecl static StackTraceElement findCallerOf(Class<?> target, Throwable throwable, int skip); static StackTraceElement[] getStackForCallerOf(
      Class<?> target, Throwable throwable, int maxDepth, int skip);  }
@Test public void testFindCallerOf() { LoggerCode library = new LoggerCode(2); UserCode code = new UserCode(library); code.invokeUserCode(); assertThat(library.caller.getClassName()).isEqualTo(UserCode.class.getName()); assertThat(library.caller.getMethodName()).isEqualTo("loggingMethod"); }