Example usage for java.lang StackTraceElement getClassName

List of usage examples for java.lang StackTraceElement getClassName

Introduction

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

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class 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("class name : ");
    System.out.print(e.getClassName());
}

From source file:com.taobao.android.apatch.ApkPatch.java

public static void main(String[] args) throws IOException, PatchException {

    String baseDir = "/Users/lilong/Downloads/tpatch/";
    File from = new File(baseDir + "classes.dex");
    File to = new File(baseDir + "classes1.dex");

    File out = new File(baseDir);
    // FileUtils.cleanDirectory(out);

    String keystore = "/Users/seker/programs/debugsign/seker.keystore";
    String password = "12345678";
    String alias = "seker.keystore";
    String entry = "12345678";
    String name = "main";
    //        APatchTool.mappingFile = new File("/Users/lilong/Downloads/mapping.txt/target/proguard/full-mapping.txt");
    ApkPatch apkPatch = new ApkPatch(from, to, name, out);
    apkPatch.setDiffFile(new File(baseDir, "diff.txt"));
    StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
    for (StackTraceElement stackTraceElement : stackTraceElements) {
        System.out.println(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
    }/* ww w  .jav a2 s .  c om*/
    apkPatch.doPatch();
}

From source file:Main.java

public static void method_end() {
    Throwable t = new Throwable();
    StackTraceElement e = t.getStackTrace()[2];
    Log.d(e.getClassName(), e.getMethodName() + ": end");
}

From source file:Main.java

public static void method_start() {
    Throwable t = new Throwable();
    StackTraceElement e = t.getStackTrace()[2];
    Log.d(e.getClassName(), e.getMethodName() + ": start");
}

From source file:Main.java

public static boolean isCallingFrom(String className) {
    StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
    for (StackTraceElement element : stackTraceElements) {
        if (element.getClassName().contains(className)) {
            return true;
        }/*from  w  w w  .j  av  a2 s .com*/
    }
    return false;
}

From source file:Main.java

private static String formatStackTraceElement(StackTraceElement ste) {
    return compressClassName(ste.getClassName()) + "." + ste.getMethodName() + (ste.isNativeMethod()
            ? "(Native Method)"
            : (ste.getFileName() != null && ste.getLineNumber() >= 0
                    ? "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")"
                    : (ste.getFileName() != null ? "(" + ste.getFileName() + ")" : "(Unknown Source)")));
}

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");
    }/*from   w  w  w . j  a  v a 2  s.  c o m*/
    return sb.toString();
}

From source file:Main.java

public static String convertStackTraceToString(StackTraceElement[] stackTraceElements) {
    StringBuilder message = new StringBuilder();
    int min = Math.min(stackTraceElements.length, 4);
    for (int i = 2; i < min; i++) {
        StackTraceElement element = stackTraceElements[i];
        message.append(element.getClassName()).append(": ").append(element.getMethodName()).append("\n");
    }// ww w. j a  v  a 2 s  . c o m
    return message.toString();
}

From source file:Main.java

@Nullable
private static StackTraceElement getCallOriginStackTraceElement() {
    StackTraceElement[] trace = new Exception("").getStackTrace();
    StackTraceElement origin = null;
    final int length = trace.length;
    for (int i = 0; i < length; i++) {
        StackTraceElement element = trace[i];
        String name = element.getClassName();
        if (name.equals("sun.reflect.NativeMethodAccessorImpl")) {
            origin = trace[i - 1];/*from  ww w  . j  ava2 s  .  c o  m*/
            break;
        }
    }
    return origin;
}

From source file:Main.java

private static String caller(int i) {
    StackTraceElement elem = new Throwable().getStackTrace()[i];
    return elem.getClassName() + "." + elem.getMethodName();
}