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:kilim.Task.java

/**
 * The generated code calls Fiber.upEx, which in turn calls
 * this to find out out where the current method is w.r.t
 * the closest _runExecute method. /*from  w w  w .j a v  a2s  . c  o  m*/
 * @return the number of stack frames above _runExecute(), not including
 * this method
 */
public int getStackDepth() {
    StackTraceElement[] stes;
    stes = new Exception().getStackTrace();
    int len = stes.length;
    for (int i = 0; i < len; i++) {
        StackTraceElement ste = stes[i];
        if (ste.getMethodName().equals("_runExecute")) {
            // discounting WorkerThread.run, Task._runExecute, and Scheduler.getStackDepth
            return i - 1;
        }
    }
    throw new AssertionError("Expected task to be run by WorkerThread");
}

From source file:org.stenerud.kscrash.KSCrash.java

/** Report a Java exception.
 *
 * @param exception The exception./*  w  w w.j av a 2s.co  m*/
 */
public void reportJavaException(Throwable exception) {
    try {
        JSONArray array = new JSONArray();
        for (StackTraceElement element : exception.getStackTrace()) {
            JSONObject object = new JSONObject();
            object.put("file", element.getFileName());
            object.put("line", element.getLineNumber());
            object.put("class", element.getClassName());
            object.put("method", element.getMethodName());
            object.put("native", element.isNativeMethod());
            array.put(object);
        }
        reportUserException(exception.getClass().getName(), exception.getMessage(), "java",
                exception.getStackTrace()[0].getFileName(), exception.getStackTrace()[0].getLineNumber(), array,
                false, false);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:op.tools.SYSTools.java

public static String getThrowableAsHTML(Throwable exc) {
    String html = "";
    StackTraceElement[] stacktrace = exc.getStackTrace();

    html += SYSConst.html_h1("mail.errormail.attachment.line1");
    html += SYSConst.html_h2(exc.getClass().getName());
    html += SYSConst.html_paragraph(exc.getMessage());

    if (OPDE.getMainframe().getCurrentResident() != null) {
        html += SYSConst.html_h3("ResID: " + OPDE.getMainframe().getCurrentResident().getRID());
    }/* ww w  .j ava 2  s .  c o m*/

    html += SYSConst.html_h3(OPDE.getMainframe().getCurrentVisiblePanel().getInternalClassID());

    String table = SYSConst.html_table_th("mail.errormail.attachment.tab.col1")
            + SYSConst.html_table_th("mail.errormail.attachment.tab.col2")
            + SYSConst.html_table_th("mail.errormail.attachment.tab.col3")
            + SYSConst.html_table_th("mail.errormail.attachment.tab.col4");

    for (int exception = 0; exception < stacktrace.length; exception++) {
        StackTraceElement element = stacktrace[exception];
        table += SYSConst.html_table_tr(SYSConst.html_table_td(element.getMethodName())
                + SYSConst.html_table_td(Integer.toString(element.getLineNumber()))
                + SYSConst.html_table_td(element.getClassName())
                + SYSConst.html_table_td(element.getFileName()));
    }

    html += SYSConst.html_table(table, "1");

    // Possible Cause
    if (exc.getCause() != null) {
        html += SYSConst.html_h3("Caused by: " + exc.getCause().getMessage());
        StackTraceElement[] stacktrace1 = exc.getCause().getStackTrace();
        String table1 = SYSConst.html_table_th("mail.errormail.attachment.tab.col1")
                + SYSConst.html_table_th("mail.errormail.attachment.tab.col2")
                + SYSConst.html_table_th("mail.errormail.attachment.tab.col3")
                + SYSConst.html_table_th("mail.errormail.attachment.tab.col4");

        for (int exception = 0; exception < stacktrace1.length; exception++) {
            StackTraceElement element = stacktrace1[exception];
            table1 += SYSConst.html_table_tr(SYSConst.html_table_td(element.getMethodName())
                    + SYSConst.html_table_td(Integer.toString(element.getLineNumber()))
                    + SYSConst.html_table_td(element.getClassName())
                    + SYSConst.html_table_td(element.getFileName()));
        }

        html += SYSConst.html_table(table1, "1");
    }

    return html;
}

From source file:org.jtrfp.trcl.TriangleList.java

private void setupVertex(int vIndex, int gpuTVIndex, int triangleIndex, TextureDescription td)
        throws ExecutionException, InterruptedException {
    final int numFrames = getPrimitives().length;
    final Triangle t = triangleAt(0, triangleIndex);
    final Vector3D pos = t.getVertices()[vIndex].getPosition();
    final TriangleVertexWindow vw = (TriangleVertexWindow) getMemoryWindow();
    ////////////////////// V E R T E X //////////////////////////////
    if (numFrames == 1) {
        vw.x.set(gpuTVIndex, (short) applyScale(pos.getX()));
        vw.y.set(gpuTVIndex, (short) applyScale(pos.getY()));
        vw.z.set(gpuTVIndex, (short) applyScale(pos.getZ()));
        final Vector3D normal = t.getVertices()[vIndex].getNormal();
        vw.normX.set(gpuTVIndex, (byte) (normal.getX() * 127));
        vw.normY.set(gpuTVIndex, (byte) (normal.getY() * 127));
        vw.normZ.set(gpuTVIndex, (byte) (normal.getZ() * 127));
    } else {/*from  ww  w.  j ava2  s  .  com*/
        float[] xFrames = new float[numFrames];
        float[] yFrames = new float[numFrames];
        float[] zFrames = new float[numFrames];
        float[] nxFrames = new float[numFrames];
        float[] nyFrames = new float[numFrames];
        float[] nzFrames = new float[numFrames];
        for (int i = 0; i < numFrames; i++) {
            xFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getX());
        }
        xyzAnimator.addFrames(xFrames);

        for (int i = 0; i < numFrames; i++) {
            yFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getY());
        }
        xyzAnimator.addFrames(yFrames);

        for (int i = 0; i < numFrames; i++) {
            zFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getZ());
        }
        xyzAnimator.addFrames(zFrames);

        for (int i = 0; i < numFrames; i++) {
            nxFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getX() * 127);
        }
        xyzAnimator.addFrames(nxFrames);

        for (int i = 0; i < numFrames; i++) {
            nyFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getY() * 127);
        }
        xyzAnimator.addFrames(nyFrames);

        for (int i = 0; i < numFrames; i++) {
            nzFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getZ() * 127);
        }
        xyzAnimator.addFrames(nzFrames);
    } //end else(frames!=1)
      //////////////// T E X T U R E ///////////////////////////
    if (td == null) {
        System.err.println("Stack trace of triangle creation below. NullPointerException follows.");
        for (StackTraceElement el : t.getCreationStackTrace()) {
            System.err.println("\tat " + el.getClassName() + "." + el.getMethodName() + "(" + el.getFileName()
                    + ":" + el.getLineNumber() + ")");
        } //end for(stackTrace)
        throw new NullPointerException("Texture for triangle in " + debugName + " intolerably null.");
    }
    if (td instanceof Texture) {// Static texture
        final int sideScalar = ((Texture) td).getSideLength() - 1;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            uvAnimator.setDebugName(debugName + ".uvAnimator");
            for (int i = 0; i < numFrames; i++) {
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final int textureID = ((Texture) td).getTexturePage();
        vw.textureIDLo.set(gpuTVIndex, (byte) (textureID & 0xFF));
        vw.textureIDMid.set(gpuTVIndex, (byte) ((textureID >> 8) & 0xFF));
        vw.textureIDHi.set(gpuTVIndex, (byte) ((textureID >> 16) & 0xFF));
    } // end if(Texture)
    if (td instanceof AnimatedTexture) {//Animated texture
        final AnimatedTexture at = (AnimatedTexture) td;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            for (int i = 0; i < numFrames; i++) {
                final int sideScalar = at.getFrames()[i].getSideLength() - 1;
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            final int sideScalar = at.getFrames()[0].getSideLength() - 1;
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final TexturePageAnimator texturePageAnimator = new TexturePageAnimator(at, vw, gpuTVIndex);
        texturePageAnimator.setDebugName(debugName + ".texturePageAnimator");
        getModel().addTickableAnimator(texturePageAnimator);
    } //end if(animated texture)
}

From source file:ch.oakmountain.tpa.cli.TpaIT.java

private String getOutputDirName() {
    StackTraceElement[] st = Thread.currentThread().getStackTrace();
    for (StackTraceElement stackTraceElement : st) {
        if (stackTraceElement.getMethodName().startsWith("integration")) {
            String suffix = getModelTypeSuffix();
            return "output" + File.separator + stackTraceElement.getMethodName() + "_" + suffix;
        }/*from   ww  w  .ja  v a2s  .c om*/
    }
    return null;
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.trace.MsgTraceReporter.java

protected Boolean shouldSendTrace(String topic, boolean count) {
    TraceCommandDeserializer.TopicTraceCommand topicTraceConfig = traceConfig.get(topic);
    if (topicTraceConfig == null) {
        topicTraceConfig = traceConfig.get(TraceCommandDeserializer.MASTER_CONFIG);
    }// w w w.java2s  .c o  m

    boolean send = (topic == null || topicTraceConfig == null) ? false : topicTraceConfig.match(topic, count);
    StackTraceElement callMethodTrace = Utils.getStackFrame(2);

    LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(KafkaStreamConstants.RESOURCE_BUNDLE_NAME),
            "MsgTraceReporter.should.trace", callMethodTrace.getMethodName(), topic, count, topicTraceConfig,
            send);

    return send;
}

From source file:de.vandermeer.skb.base.message.Message5WH.java

/**
 * Builder method: sets the Where? part of the message.
 * Three values are taken from the stack trace: class name and method name for the location of Where?
 * and line number for the the line. If the stack trace is null or class name and method are empty, nothing will be
 * set. A line number of 0 will be ignored.
 * @param ste source for the Where? part
 * @return this to allow concatenation//from  ww  w .  j a v  a 2  s .  c  o m
 */
public Message5WH setWhere(StackTraceElement ste) {
    if (ste != null) {
        String cn = ste.getClassName();
        String mn = ste.getMethodName();
        int line = ste.getLineNumber();
        //StackTraceElement requires Class and Method set to !null but allows for "", we cope with null but not "" in ST4
        if (!"".equals(cn) || !"".equals(mn)) {
            this.where = this.stg.getInstanceOf("where");
            if (!"".equals(cn)) {
                this.where.add("location", ste.getClassName());
            }
            if (!"".equals(mn)) {
                this.where.add("location", ste.getMethodName());
            }
            if (line > 0) {
                this.where.add("line", ste.getLineNumber());
            }
            //no column information in a stack trace
        }
    }
    return this;
}

From source file:org.usapi.common.USAPIException.java

private StackTraceElement getCaller() {
    StackTraceElement ste[] = Thread.currentThread().getStackTrace();
    StackTraceElement candidate = null;
    // if browser (chrome?) hangs stacktrace can seemingly not have expected contents (invoke0), so
    // providing default value
    StackTraceElement caller = new StackTraceElement("UNKNOWN_CLASS", "UNKNOWN_METHOD", "UNKNOWN_FILE", -1);
    for (int ndx = 0; ndx < ste.length; ndx++) {
        candidate = ste[ndx];// w  w  w  .  j  a  v  a  2s .  c o  m
        if (candidate.getClassName().equals("sun.reflect.NativeMethodAccessorImpl")
                && candidate.getMethodName().equals("invoke0")) {
            // no worries about index out of bounds here, the match is guaranteed to 
            // happen anywhere between index 5-8,  total stack depth ~20
            caller = ste[ndx - 1];
            break;
        }
    }
    return caller;
}

From source file:com.moviejukebox.plugin.ScriptableScraperPlugin.java

public ScriptableScraperPlugin() {
    super();//from w ww. j  av  a  2  s  .c o m

    webBrowser = new WebBrowser();
    maxGenres = PropertiesUtil.getIntProperty("genres.max", DEFAULT_GENRES);
    maxDirectors = PropertiesUtil.getReplacedIntProperty("movie.director.maxCount",
            "plugin.people.maxCount.director", DEFAULT_DIRECTORS);
    maxWriters = PropertiesUtil.getReplacedIntProperty("movie.writer.maxCount", "plugin.people.maxCount.writer",
            DEFAULT_WRITERS);
    maxActors = PropertiesUtil.getReplacedIntProperty("movie.actor.maxCount", "plugin.people.maxCount.actor",
            DEFAULT_ACTORS);

    //        tvdb = new TheTvDBPlugin();
    final ScriptableScraperXMLReader xmlReader = new ScriptableScraperXMLReader();
    String xmlData = PropertiesUtil.getProperty("scriptablescraper.data", Movie.UNKNOWN);
    if (StringTools.isValidString(xmlData)) {
        File xmlFile = new File(xmlData);
        if (xmlFile.exists()) {
            ssData = new ScriptableScraper();
            ssData.setDebug(debug);
            if (xmlReader.parseXML(xmlFile, ssData)) {
                if (info) {
                    StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
                    StackTraceElement e = stacktrace[stacktrace.length - 8];
                    if ("updateMovieData".equals(e.getMethodName())) {
                        LOG.info("");
                        LOG.info("  -=[   ScriptableScraperPlugin   ]=-");
                        LOG.info("Plugin         : {} - {}", ssData.getName(), ssData.getDescription());
                        LOG.info("Plugin version : {} ({})", ssData.getVersion(), ssData.getPublished());
                        LOG.info("Plugin authors : {}", ssData.getAuthor());
                        LOG.info("Plugin language: {}", ssData.getLanguage());
                        LOG.info("");
                    }
                }
            } else {
                LOG.error("Reading error XML data file : {}", xmlData);
            }
        } else {
            LOG.error("File not found : {}", xmlData);
        }
    } else {
        LOG.error("Failed mandatory parameter scriptablescraper.data");
    }
}

From source file:org.apache.fineract.infrastructure.jobs.service.JobRegisterServiceImpl.java

private String getStackTraceAsString(final Throwable throwable) {
    final StackTraceElement[] stackTraceElements = throwable.getStackTrace();
    final StringBuffer sb = new StringBuffer(throwable.toString());
    for (final StackTraceElement element : stackTraceElements) {
        sb.append("\n \t at ").append(element.getClassName()).append(".").append(element.getMethodName())
                .append("(").append(element.getLineNumber()).append(")");
    }/*  www. j  a  v a2 s  .  c o m*/
    return sb.toString();
}