List of usage examples for java.lang StackTraceElement getMethodName
public String getMethodName()
From source file:com.kth.common.utils.etc.LogUtil.java
/** ? , ?? ? ??. */ private static String getClassLineNumber(final Class<?> clazz) { StackTraceElement[] elements = Thread.currentThread().getStackTrace(); if (elements != null) { for (StackTraceElement e : elements) { if ((clazz.getName()).equals(e.getClassName()) || (clazz.getSimpleName()).equals(e.getClassName())) { return e.getClassName() + "(" + e.getMethodName() + ":" + e.getLineNumber() + ")"; }// w w w . j ava 2s .c o m } } return ""; }
From source file:adalid.core.XS1.java
static boolean checkAccess() { String method;//from ww w . j av a2 s. com String caller = null; final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stack) { method = element.getClassName() + "." + element.getMethodName(); if (caller == null) { if (method.startsWith(ROOT_PACKAGE) && !method.startsWith(THIS_CLASS)) { caller = method; } } else if (method.startsWith(ROOT_PACKAGE)) { break; } else { String message = "illegal invocation of \"" + StringUtils.substringAfterLast(caller, ".") + "\""; message += " at " + method + "(" + element.getFileName() + ":" + element.getLineNumber() + ")"; throw new IllegalAccessRuntimeException(message); } } return caller != null; }
From source file:com.eucalyptus.entities.EntityWrapper.java
public static StackTraceElement getMyStackTraceElement() { int i = 0;//from w ww . jav a2s . c om for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) { if ((i++ < 2) || ste.getClassName().matches(".*EntityWrapper.*") || ste.getClassName().matches(".*TxHandle.*") || ste.getMethodName().equals("getEntityWrapper")) { continue; } else { return ste; } } throw new RuntimeException("BUG: Reached bottom of stack trace without finding any relevent frames."); }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * INTERNAL method that checks if the stack trace that just crashed is conflictive. This is true in the following scenarios: * - The application has crashed while initializing (handleBindApplication is in the stack) * - The error activity has crashed (activityClass is in the stack) * * @param throwable The throwable from which the stack trace will be checked * @param activityClass The activity class to launch when the app crashes * @return true if this stack trace is conflictive and the activity must not be launched, false otherwise *//*from w ww . j a v a 2 s. c om*/ private static boolean isStackTraceLikelyConflictive(Throwable throwable, Class<? extends Activity> activityClass) { do { StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement element : stackTrace) { if ((element.getClassName().equals("android.app.ActivityThread") && element.getMethodName().equals("handleBindApplication")) || element.getClassName().equals(activityClass.getName())) { return true; } } } while ((throwable = throwable.getCause()) != null); return false; }
From source file:datafu.hourglass.jobs.StagedOutputJob.java
/** * Gets the class for the caller./*from w w w . ja v a 2 s . c o m*/ * * @return caller class */ private static Class<?> getCallersClass() { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); boolean foundSelf = false; for (StackTraceElement element : stack) { if (foundSelf && !StagedOutputJob.class.getName().equals(element.getClassName())) { try { return Class.forName(element.getClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } else if (StagedOutputJob.class.getName().equals(element.getClassName()) && "getCallersClass".equals(element.getMethodName())) { foundSelf = true; } } return StagedOutputJob.class; }
From source file:com.egt.core.aplicacion.Bitacora.java
private static StackTraceElement getCallingMethodStackTraceElement() { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (StackTraceElement trace : stack) { if (trace.getClassName().startsWith(PREFIJO_PAQUETE)) { if (trace.getClassName().equals(Bitacora.class.getName())) { continue; } else if (trace.getMethodName().equals(METODO_TRACKING)) { continue; } else { return trace; }/*from w ww.j a v a 2 s. co m*/ } } return null; }
From source file:com.codepunk.codepunklib.util.log.FormattingLogger.java
/** * Returns the concrete information from the given {@link StackTraceElement} that is represented * by the given Placeholder./*from w ww. java 2 s . c om*/ * @param element The {@link StackTraceElement}. * @param placeholder The {@link Placeholder} to replace. * @return The information represented by the Placeholder. */ private static Object getFromElement(StackTraceElement element, Placeholder placeholder) { try { switch (placeholder) { case FILE_NAME: return element.getFileName(); case HASH_CODE: return element.hashCode(); case LINE_NUMBER: return element.getLineNumber(); case METHOD_NAME: return element.getMethodName(); case PACKAGE: { return getClass(element).getPackage().getName(); } case CLASS_NAME: case SIMPLE_CLASS_NAME: default: { String name; Class cls = getClass(element); do { if (cls == null) { name = UNKNOWN_CLASS_NAME; } else if (placeholder == Placeholder.CLASS_NAME) { name = cls.getName(); } else { name = cls.getSimpleName(); } } while (TextUtils.isEmpty(name)); return name; } } } catch (ClassNotFoundException e) { return UNKNOWN_CLASS_NAME; } }
From source file:Main.java
public void doit() { StackTraceElement e = Thread.currentThread().getStackTrace()[3]; System.out.println(e.getMethodName()); }
From source file:com.google.gdt.eclipse.designer.model.widgets.support.GwtState.java
/** * Extracts from stack trace name of class and method of test which creates this {@link GwtState}. *//*from w ww . j av a 2 s .com*/ private static String findTestQualifiedName() { for (StackTraceElement element : Thread.currentThread().getStackTrace()) { String methodName = element.getMethodName(); if (methodName.startsWith("test_")) { return element.getClassName() + "." + methodName; } } return "noTestMethod"; }
From source file:com.att.aro.core.util.Util.java
/** * Returns package.Class::methodName of method enclosing call to this method * //from w w w . j av a2 s . co m * @return */ public static String getMethod() { StackTraceElement traceElement = Thread.currentThread().getStackTrace()[2]; String name = null; // traceElement.getClassName() + "::" + traceElement.getMethodName(); name = ((traceElement.getFileName()).split("\\."))[0] + "::" + traceElement.getMethodName() + "(...)"; return name; }