Example usage for java.lang StackTraceElement getLineNumber

List of usage examples for java.lang StackTraceElement getLineNumber

Introduction

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

Prototype

public int getLineNumber() 

Source Link

Document

Returns the line number of the source line containing the execution point represented by this stack trace element.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    System.out.print("line number : ");
    System.out.print(e.getLineNumber());
}

From source file:Main.java

public static int _LINE_() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getLineNumber();
}

From source file:Main.java

public static int getLine(int N) {
    StackTraceElement ste = Thread.currentThread().getStackTrace()[N];
    return ste.getLineNumber();
}

From source file:Main.java

public static String getLineInfo() {
    StackTraceElement ste = new Throwable().getStackTrace()[1];
    return ste.getFileName() + ": Line " + ste.getLineNumber();
}

From source file:Main.java

public static String getLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getLineNumber()).append(" | ")
            .append(traceElement.getMethodName()).append("]");
    return toStringBuffer.toString();
}

From source file:Main.java

public static String dumpStack(Thread t) {
    StringBuilder sb = new StringBuilder();
    sb.append(t.getName() + "[" + t.getId() + "] - " + t.getState() + ":\n");
    for (StackTraceElement ste : t.getStackTrace()) {
        sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":"
                + ste.getLineNumber() + ")\n");
    }//  w ww .ja v a 2  s  . c o m
    return sb.toString();
}

From source file:Main.java

private static String rebuildMsg(StackTraceElement stackTraceElement, String msg) {
    StringBuffer sb = new StringBuffer();
    sb.append(stackTraceElement.getFileName());
    sb.append(" (");
    sb.append(stackTraceElement.getLineNumber());
    sb.append(") ");
    sb.append(stackTraceElement.getMethodName());
    sb.append(": ");
    sb.append(msg);//from   w ww .  j  a v a2 s. c om
    return sb.toString();
}

From source file:Main.java

public static String getFileLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("]");
    return toStringBuffer.toString();
}

From source file:Main.java

public static void debugWhere(String tag, String msg) {
    Log.d(tag, msg + " --- stack trace begins: ");
    StackTraceElement elements[] = Thread.currentThread().getStackTrace();
    // skip first 3 element, they are not related to the caller
    for (int i = 3, n = elements.length; i < n; ++i) {
        StackTraceElement st = elements[i];
        String message = String.format("    at %s.%s(%s:%s)", st.getClassName(), st.getMethodName(),
                st.getFileName(), st.getLineNumber());
        Log.d(tag, message);//from   w  w w . jav  a  2  s .c o  m
    }
    Log.d(tag, msg + " --- stack trace ends.");
}

From source file:Main.java

private static String getTag(Exception exception) {
    StackTraceElement traceElement = ((exception).getStackTrace())[1];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("()").append("]");
    String TAG = toStringBuffer.toString();
    return TAG;/*w w  w .j  av a  2 s .c o m*/
}