Пример #1
0
    public static void printSite(Site s, StringBuilder out) {
      if (s == null) {
        out.append("(null)");
        return;
      }
      StackTraceElement[] st = s.site();

      int interestingSitesPrinted = 0;
      for (int i = s.offset; i < st.length; i++) {
        StackTraceElement e = st[i];
        String fileName = e.getFileName();
        if (THIS_FILE_NAME.equals(fileName)) {
          continue;
        }
        out.append(" " + e.getMethodName() + "(" + e.getFileName() + ":" + e.getLineNumber() + ")");
        interestingSitesPrinted++;
        if (interestingSitesPrinted <= SITES_TO_PRINT) {
          continue;
        }
        if (fileName == null || "View.java".equals(fileName)) {
          continue;
        }
        String methodName = e.getMethodName();
        if (skipMethods.contains(methodName)) {
          continue;
        }
        break;
      }
    }
Пример #2
0
 private static boolean isStackElementDebugClassFile(StackTraceElement element) {
   StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
   if (stackTraceElements == null) return false;
   String name = stackTraceElements[0].getFileName();
   if (name == null) return false;
   //noinspection SimplifiableIfStatement
   if (element == null || element.getFileName() == null) return false;
   return element.getFileName().equals(name);
 }
Пример #3
0
 /**
  * Gets an approximate source code location for a node if possible.
  *
  * @return a file name and source line number in stack trace format (e.g. "String.java:32") if an
  *     approximate source location is found, null otherwise
  */
 public static String approxSourceLocation(Node node) {
   StackTraceElement[] stackTraceElements = approxSourceStackTraceElement(node);
   if (stackTraceElements != null && stackTraceElements.length > 0) {
     StackTraceElement top = stackTraceElements[0];
     if (top.getFileName() != null && top.getLineNumber() >= 0) {
       return top.getFileName() + ":" + top.getLineNumber();
     }
   }
   return null;
 }
  /** Checks all of the methods in gen for consistency */
  public static void checkMgens(final ClassGen gen) {

    if (skip_checks) return;

    Method[] methods = gen.getMethods();
    for (int i = 0; i < methods.length; i++) {
      Method method = methods[i];
      // System.out.println ("Checking method " + method + " in class "
      // + gen.getClassName());
      checkMgen(new MethodGen(method, gen.getClassName(), gen.getConstantPool()));
    }

    if (false) {
      Throwable t = new Throwable();
      t.fillInStackTrace();
      StackTraceElement[] ste = t.getStackTrace();
      StackTraceElement caller = ste[1];
      System.out.printf(
          "%s.%s (%s line %d)",
          caller.getClassName(),
          caller.getMethodName(),
          caller.getFileName(),
          caller.getLineNumber());
      for (int ii = 2; ii < ste.length; ii++)
        System.out.printf(" [%s line %d]", ste[ii].getFileName(), ste[ii].getLineNumber());
      System.out.printf("\n");
      dump_methods(gen);
    }
  }
Пример #5
0
  /**
   * This method duplicates the functionality of ExceptionUtils.describeStackLevels which is no
   * longer supported in Rice.
   *
   * @param fromLevel
   * @param toLevel
   * @return
   */
  public static String getMethodPath(int fromLevel, int toLevel) {
    StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
    // increase the levels to avoid including the method that called this.
    fromLevel = fromLevel + 1;
    toLevel = toLevel + 1;

    if (fromLevel <= 0) {
      throw new IllegalArgumentException("invalid fromLevel (" + fromLevel + " < 0)");
    }
    if (fromLevel > toLevel) {
      throw new IllegalArgumentException(
          "invalid levels (fromLevel " + fromLevel + " > toLevel " + toLevel + ")");
    }
    if (toLevel >= stackTraceElements.length) {
      throw new IllegalArgumentException(
          "invalid toLevel (" + toLevel + " >= " + stackTraceElements.length + ")");
    }

    StringBuffer result = new StringBuffer();
    int elementIndex = 0;
    for (StackTraceElement element : stackTraceElements) {
      if (elementIndex >= fromLevel && elementIndex >= toLevel) {
        if (result.length() > 0) {
          result.append(" from ");
        }
        result.append(element.getClassName()).append(".");
        result.append(element.getMethodName()).append("(");
        result.append(element.getFileName()).append(":");
        result.append(element.getLineNumber()).append(")");
      }
      elementIndex++;
    }
    return result.toString();
  }
Пример #6
0
 public static void printElement(Site s, int index) {
   if (s == null || index >= s.site().length) {
     ps.print("(null)");
   } else {
     StackTraceElement e = s.site()[index];
     ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")");
   }
 }
Пример #7
0
 private static void printElementInfo(OutputStream stream, StackTraceElement element) {
   print(stream, element.getClassName());
   print(stream, ":");
   print(stream, element.getMethodName());
   print(stream, " ");
   print(stream, "(");
   print(stream, element.getFileName());
   print(stream, ":");
   print(stream, element.getLineNumber());
   print(stream, ")");
   printNewLine(stream);
 }
Пример #8
0
 protected String getTitle(Throwable t) {
   String message = t.getMessage();
   String tit = message;
   if (tit == null) {
     StackTraceElement el = t.getStackTrace()[0];
     tit =
         t.getClass().getName().substring(t.getClass().getPackage().getName().length() + 1)
             + " "
             + el.getFileName()
             + ":"
             + el.getLineNumber();
   }
   return tit;
 }
Пример #9
0
 private static void printThrowable(OutputStream stream, Throwable throwable) {
   printBytes(stream, ("Exception " + throwable.toString()).getBytes());
   printNewLine(stream);
   StackTraceElement[] stackTraceElements = throwable.getStackTrace();
   for (int i = stackTraceElements.length - 1; i >= 0; i--) {
     StackTraceElement element = stackTraceElements[i];
     printBytes(stream, element.getFileName().getBytes());
     printBytes(stream, ":".getBytes());
     printBytes(stream, String.valueOf(element.getLineNumber()).getBytes());
     printNewLine(stream);
   }
   if (throwable.getCause() != null) {
     printBytes(stream, "Caused by:\n".getBytes());
     printThrowable(stream, throwable.getCause());
   }
 }
Пример #10
0
 public static void printElements(Site s, int index, int nelems) {
   if (s == null || index >= s.site().length) {
     ps.print("(null)");
   } else {
     for (int i = 0; i < nelems; i++) {
       int j = index + i;
       if (j >= s.site().length) {
         break;
       }
       if (i > 0) {
         ps.print(", ");
       }
       StackTraceElement e = s.site()[j];
       ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")");
     }
   }
 }
Пример #11
0
  protected static boolean wasCalledDuringClassLoading() {
    if (LOCK.isHeldByCurrentThread()) return true;
    LOCK.lock();

    try {
      StackTrace st = new StackTrace(new Throwable());
      int n = st.getDepth();

      for (int i = 3; i < n; i++) {
        StackTraceElement ste = st.getElement(i);

        if ("ClassLoader.java".equals(ste.getFileName())
            && "loadClass".equals(ste.getMethodName())) {
          return true;
        }
      }

      return false;
    } finally {
      LOCK.unlock();
    }
  }