Example usage for java.lang StackTraceElement getMethodName

List of usage examples for java.lang StackTraceElement getMethodName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getMethodName.

Prototype

public String getMethodName() 

Source Link

Document

Returns the name of the method containing the execution point represented by this stack trace element.

Usage

From source file:Main.java

private static String generateVerboseTag(StackTraceElement caller) {
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;//w  ww .ja  v  a2  s . c  o m
}

From source file:Main.java

private static String generateTag(StackTraceElement caller) {
    String tag = "%s.%s(Line:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*w  w w  .j av  a  2 s .  c  o  m*/
}

From source file:org.eclipse.scanning.example.detector.RandomLineDevice.java

protected static final String getMethodName(StackTraceElement ste[]) {

    String methodName = "";
    boolean flag = false;

    for (StackTraceElement s : ste) {

        if (flag) {

            methodName = s.getMethodName();
            break;
        }/*  w w  w.j a  v  a2s .co  m*/
        flag = s.getMethodName().equals("getStackTrace");
    }
    return methodName;
}

From source file:Main.java

private static String generateTag() {
    StackTraceElement caller = new Throwable().getStackTrace()[2];
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;// w  ww. j  a v  a 2 s  .  c o  m
}

From source file:Main.java

public static void openFeedback(Activity activity) {
    try {/*from   w  ww.ja  va  2  s. c  om*/
        throw new Exception();
    } catch (Exception e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication().getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}

From source file:com.squarespace.gibson.GibsonUtils.java

private static void append(MessageDigest md, StackTraceElement element) {
    if (element != null) {
        append(md, element.getClassName());
        append(md, element.getMethodName());
        append(md, element.getFileName());
        append(md, element.getLineNumber());
    }/*from   w  w w.  ja v  a 2  s .co m*/
}

From source file:Main.java

public static boolean invokeIn(StackTraceElement[] stackTraceElements, Class<?> cla, String methodName) {
    if (stackTraceElements == null || stackTraceElements.length == 0) {
        return false;
    }//from  w  ww.ja v a2 s . c  om

    String targetClassName = cla.getName();
    StackTraceElement element;
    String elementClassName;
    String elementMethodName;
    for (StackTraceElement stackTraceElement : stackTraceElements) {
        element = stackTraceElement;

        elementClassName = element.getClassName();
        elementMethodName = element.getMethodName();
        if (targetClassName.equals(elementClassName) && methodName.equals(elementMethodName)) {
            return true;
        }
    }

    return false;
}

From source file:org.apache.tajo.exception.ExceptionUtil.java

/**
 * Return the string about the exception point; e.g.,)
 * <code>org.apache.tajo.storage.mysql.JdbcTablespace::createTable</code>
 *
 * @return A string representing the class and method names at which the exception occurs.
 *///from  w w  w.ja  v  a 2 s.c  o m
public static String getExceptionPoint() {
    StackTraceElement stack = Thread.currentThread().getStackTrace()[3];
    return stack.getClassName() + "::" + stack.getMethodName();
}

From source file:tachyon.util.io.PathUtils.java

/**
 * Creates a unique path based off the caller.
 *
 * @return unique path based off the caller
 *///from w  w  w  . ja  v a  2 s.co  m
public static final String uniqPath() {
    StackTraceElement caller = new Throwable().getStackTrace()[1];
    long time = System.nanoTime();
    return "/" + caller.getClassName() + "/" + caller.getMethodName() + "/" + time;
}

From source file:com.cmsz.cloudplatform.utils.StringUtils.java

public static String getExceptionStackInfo(Throwable e) {
    StringBuffer sb = new StringBuffer();

    sb.append(e.toString()).append("\n");
    StackTraceElement[] elemnents = e.getStackTrace();
    for (StackTraceElement element : elemnents) {
        sb.append(element.getClassName()).append(".");
        sb.append(element.getMethodName()).append("(");
        sb.append(element.getFileName()).append(":");
        sb.append(element.getLineNumber()).append(")");
        sb.append("\n");
    }/*from  www  . j  a  va2 s. c o  m*/

    return sb.toString();
}