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:de.micromata.genome.util.runtime.AssertUtils.java

/**
 * Gets the code line./*from   www.ja v a  2s  .  c om*/
 *
 * @param se the se
 * @return the code line
 */
public static String getCodeLine(final StackTraceElement se) {
    if (se == null) {
        return "<stack not found>";
    }
    final String fname = se.getFileName();
    final int cl = se.getLineNumber();
    final String clsName = se.getClassName();
    final String codeLine = getCodeLine(clsName, fname, cl);
    return StringUtils.trim(codeLine);
}

From source file:org.kuali.kfs.module.tem.web.JstlFunctions.java

/**
 * Get the stack trace from a <code>{@link Throwable}</code> and create a log message from it for tracing purposes
 *
 * @param thrownObj/*from   w  ww  .jav a2 s.c o m*/
 * @return String log message
 */
private static String buildTraceMessage(Throwable thrownObj) {
    StackTraceElement stackTraceElement = thrownObj.getStackTrace()[0];
    return new StringBuilder(stackTraceElement.getClassName()).append("#")
            .append(stackTraceElement.getMethodName()).append(":").append(stackTraceElement.getLineNumber())
            .append(" ").append(thrownObj.getClass().getSimpleName()).append("\n")
            .append(thrownObj.getMessage()).toString();
}

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  ww  .j a v a  2s  . c o m
}

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

public static Stacktrace.StackTrace convertStacktrace(Throwable t) {
    Stacktrace.StackTrace.Builder builder = Stacktrace.StackTrace.newBuilder();
    if (t != null) {
        for (StackTraceElement element : t.getStackTrace()) {
            builder.addElement(Stacktrace.StackTrace.Element.newBuilder()
                    .setFilename(element.getFileName() == null ? "(Unknown Source)" : element.getFileName())
                    .setFunction(element.getClassName() + "::" + element.getMethodName())
                    .setLine(element.getLineNumber()));
        }//from  w  w  w .  j  a v  a2s  . co m
    }
    return builder.build();
}

From source file:org.apache.flink.api.java.Utils.java

public static String getCallLocationName(int depth) {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

    if (stackTrace.length < depth) {
        return "<unknown>";
    }//from  w w w . j  a va  2s  . co m

    StackTraceElement elem = stackTrace[depth];

    return String.format("%s(%s:%d)", elem.getMethodName(), elem.getFileName(), elem.getLineNumber());
}

From source file:com.momock.util.Logger.java

static String getSourceInfo(StackTraceElement trace) {
    return trace.getFileName() + "(" + trace.getLineNumber() + ")";
}

From source file:Main.java

public static String getLogInfo(StackTraceElement stackTraceElement) {
    StringBuilder logInfoStringBuilder = new StringBuilder();
    String threadName = Thread.currentThread().getName();
    long threadID = Thread.currentThread().getId();
    String fileName = stackTraceElement.getFileName();
    String className = stackTraceElement.getClassName();
    String methodName = stackTraceElement.getMethodName();
    int lineNumber = stackTraceElement.getLineNumber();
    logInfoStringBuilder.append("[ ");
    logInfoStringBuilder.append("threadID=" + threadID).append(SEPARATOR);
    logInfoStringBuilder.append("threadName=" + threadName).append(SEPARATOR);
    logInfoStringBuilder.append("fileName=" + fileName).append(SEPARATOR);
    logInfoStringBuilder.append("className=" + className).append(SEPARATOR);
    logInfoStringBuilder.append("methodName=" + methodName).append(SEPARATOR);
    logInfoStringBuilder.append("lineNumber=" + lineNumber);
    logInfoStringBuilder.append(" ] ");
    return logInfoStringBuilder.toString();
}

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  w w w. ja v a  2  s .  c  om*/

    return sb.toString();
}

From source file:grails.util.GrailsUtil.java

public static void printSanitizedStackTrace(Throwable t, PrintWriter p, StackTraceFilterer stackTraceFilterer) {
    t = stackTraceFilterer.filter(t);//from  w  w  w. j  a va 2s  .  c om

    StackTraceElement[] trace = t.getStackTrace();
    for (StackTraceElement stackTraceElement : trace) {
        p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":"
                + stackTraceElement.getLineNumber() + ")");
    }
}

From source file:com.simiacryptus.util.lang.CodeUtil.java

/**
 * Gets heapCopy text.//from   ww  w . j ava  2  s  . c  o  m
 *
 * @param callingFrame the calling frame
 * @return the heapCopy text
 * @throws IOException the io exception
 */
public static String getInnerText(@javax.annotation.Nonnull final StackTraceElement callingFrame)
        throws IOException {
    try {
        @javax.annotation.Nonnull
        final File file = com.simiacryptus.util.lang.CodeUtil.findFile(callingFrame);
        assert null != file;
        final int start = callingFrame.getLineNumber() - 1;
        final List<String> allLines = Files.readAllLines(file.toPath());
        final String txt = allLines.get(start);
        @javax.annotation.Nonnull
        final String indent = com.simiacryptus.util.lang.CodeUtil.getIndent(txt);
        @javax.annotation.Nonnull
        final ArrayList<String> lines = new ArrayList<>();
        for (int i = start + 1; i < allLines.size()
                && (com.simiacryptus.util.lang.CodeUtil.getIndent(allLines.get(i)).length() > indent.length()
                        || allLines.get(i).trim().isEmpty()); i++) {
            final String line = allLines.get(i);
            lines.add(line.substring(Math.min(indent.length(), line.length())));
        }
        return lines.stream().collect(Collectors.joining("\n"));
    } catch (@javax.annotation.Nonnull final Throwable e) {
        return "";
    }
}