Exemplo n.º 1
0
        public void pushIn(final String paraMessage, final StackTraceElement[] ste) {
          final StringBuilder sb = StringBuilderCacher.getFree();

          calendar.setTimeInMillis(System.currentTimeMillis());
          sb.append(calendar.get(Calendar.HOUR_OF_DAY));
          sb.append(":");
          sb.append(calendar.get(Calendar.MINUTE));
          sb.append(":");
          sb.append(calendar.get(Calendar.SECOND));
          sb.append(".");
          sb.append(calendar.get(Calendar.MILLISECOND));
          sb.append(" ");

          sb.append(paraMessage);

          final String tmp = sb.toString();
          StringBuilderCacher.cycle(sb);

          synchronized (exception) {
            exception.add(tmp);
            stacks.add(ste);
          }

          if (msbViewer == null) {
            msbViewer = new ExceptionViewer();
          }

          msbViewer.show();
        }
Exemplo n.º 2
0
  /**
   * 本方法测试用例为TestFormatCSS.java
   *
   * @param text
   */
  public static final String format(final String text) {
    // System.out.println("format content : \n" + jtaScript.getText());
    final char[] textChars = text.toCharArray();
    final StringBuilder sb = StringBuilderCacher.getFree();

    boolean isNewLine = false;
    boolean isIndent = false;

    final int charSize = textChars.length;
    char preChar = ' ';
    for (int i = 0; i < charSize; ) {
      final char oneChar = textChars[i];
      if (oneChar == ' ' || oneChar == '\t') {
        if (preChar == ' ' || preChar == '\t') {
          i++;
          continue;
        }
      }
      //			if (isIndent == false && (oneChar == ' ' || oneChar == '\t')) {
      //				i++;
      //				continue;
      //			}
      if (isNewLine == false && oneChar == '\n') {
        i++;
        continue;
      }
      //			if (isIndent && (oneChar == ' ' || oneChar == '\t')) {
      //				i++;
      //				continue;// 忽略{之后的空格和Tab
      //			}
      if (isNewLine && (oneChar == '\n' || oneChar == ' ' || oneChar == '\t')) {
        i++;
        continue; // 忽略\n之后的空格和Tab
      }

      if (isNewLine) {
        sb.append('\n');
        if (isIndent) {
          sb.append('\t');
          preChar = '\t';
        }

        final int oldI = i;
        i = appendRemMaybe(sb, textChars, i - 1, charSize, false);
        if (oldI != i) {
          continue; // 添加一个rem段
        }
        isNewLine = false;
      }

      if (oneChar == '{') {
        if (preChar == '\t' || preChar == ' ') {
          removeBackSpace(sb);
        }
        sb.append(' ');
        preChar = ' ';
        sb.append(oneChar);
        i = appendRemMaybe(sb, textChars, i, charSize, true);

        isNewLine = true;
        isIndent = true;
        continue;
      } else if (oneChar == '}') {
        char isNewLineChar = 0;
        if (preChar == '\t' || preChar == ' ') {
          isNewLineChar = removeBackSpace(sb);
        }
        // font-color:red \t} => font-color:red\n}
        //				removeBackSpace(sb);
        //				sb.append(oneChar);
        //				i = appendRemMaybe(sb, textChars, i, charSize);
        if (isNewLineChar != '\n') {
          sb.append('\n');
        }
        sb.append(oneChar);
        sb.append('\n');
        preChar = oneChar;
        isNewLine = true;
        isIndent = false;
        i++;
        continue;
      } else if (oneChar == '/') {
        if (preChar == '*') {
          isNewLine = true;
        }
      } else if (oneChar == ';') {
        if (preChar == '\t' || preChar == ' ') {
          removeBackSpace(sb);
        }
        preChar = 0;
        sb.append(oneChar);
        i = appendRemMaybe(sb, textChars, i, charSize, true);

        isNewLine = true;
        continue;
      } else if (oneChar == ':') {
        if (preChar == '\t' || preChar == ' ') {
          removeBackSpace(sb);
        }
        sb.append(oneChar);
        sb.append(' ');
        preChar = ' ';
        i = skipSpace(textChars, i, charSize);
        continue;
      }
      sb.append(oneChar);
      preChar = oneChar;
      i++;
    }

    final String out = sb.toString();
    StringBuilderCacher.cycle(sb);

    return out;
  }