Exemplo n.º 1
0
 @Override
 protected Integer parse(String argument) throws NumberFormatException, CmdLineException {
   int value = Integer.parseInt(argument);
   Range range = setter.asAnnotatedElement().getAnnotation(Range.class);
   if (range != null && value != Math.min(Math.max(value, range.min()), range.max())) {
     throw new NumberFormatException();
   }
   return value;
 }
Exemplo n.º 2
0
 private void printScriptFrames(StringBuilder sb, Realm realm, Throwable e, int level) {
   final String indent = Strings.repeat('\t', level);
   final int maxDepth = options.stacktraceDepth;
   int depth = 0;
   StackTraceElement[] stackTrace = StackTraces.scriptStackTrace(e);
   for (; depth < Math.min(stackTrace.length, maxDepth); ++depth) {
     StackTraceElement element = stackTrace[depth];
     String methodName = element.getMethodName();
     String fileName = element.getFileName();
     int lineNumber = element.getLineNumber();
     sb.append(indent)
         .append("at ")
         .append(methodName)
         .append(" (")
         .append(fileName)
         .append(':')
         .append(lineNumber)
         .append(")\n");
   }
   if (depth < stackTrace.length) {
     int skipped = stackTrace.length - depth;
     sb.append("\t.. ").append(skipped).append(" frames omitted\n");
   }
   if (e.getSuppressed().length > 0 && level == 1) {
     Throwable suppressed = e.getSuppressed()[0];
     String message;
     if (suppressed instanceof ScriptException) {
       message = ((ScriptException) suppressed).getMessage(realm.defaultContext());
     } else {
       message = Objects.toString(suppressed.getMessage(), suppressed.getClass().getSimpleName());
     }
     sb.append(indent).append(formatMessage("suppressed_exception", message)).append('\n');
     printScriptFrames(sb, realm, suppressed, level + 1);
   }
 }
Exemplo n.º 3
0
  private void handleException(ParserExceptionWithSource exception) {
    ParserException e = exception.getCause();
    String sourceCode = exception.getSourceCode();
    int lineOffset = exception.getSource().getLine();

    String sourceInfo = String.format("%s:%d:%d", e.getFile(), e.getLine(), e.getColumn());
    int start = skipLines(sourceCode, e.getLine() - lineOffset);
    int end = nextLineTerminator(sourceCode, start);
    String offendingLine = sourceCode.substring(start, end);
    String marker = Strings.repeat('.', Math.max(e.getColumn() - 1, 0)) + '^';

    console.printf("%s %s: %s%n", sourceInfo, e.getType(), e.getFormattedMessage());
    console.printf("%s %s%n", sourceInfo, offendingLine);
    console.printf("%s %s%n", sourceInfo, marker);
    printStackTrace(e);
  }
Exemplo n.º 4
0
 private static void printStackTrace(PrintWriter writer, Throwable e, int maxDepth) {
   final int depth = Math.max(maxDepth, 0);
   new TruncatedThrowable(e, depth).printStackTrace(writer);
 }
Exemplo n.º 5
0
 private static void printStackTrace(PrintStream stream, Throwable e, int maxDepth) {
   final int depth = Math.max(maxDepth, 0);
   new TruncatedThrowable(e, depth).printStackTrace(stream);
 }