示例#1
0
  private static String buildMessage(List<ParseError> errors) {
    if (errors == null || errors.size() < 0) {
      throw new IllegalArgumentException(
          "Cannot build a CSSParseException without a list of errors");
    }

    StringBuilder sb = new StringBuilder();
    for (ParseError pe : errors) {
      Position pos = pe.getInputBuffer().getPosition(pe.getStartIndex());
      String message =
          pe.getErrorMessage() != null
              ? pe.getErrorMessage()
              : pe instanceof InvalidInputError
                  ? new DefaultInvalidInputErrorFormatter().format((InvalidInputError) pe)
                  : pe.getClass().getSimpleName();
      sb.append(message)
          .append(" (line ")
          .append(pos.line)
          .append(", column ")
          .append(pos.column)
          .append(")");
      sb.append('\n');
    }
    sb.setLength(sb.length() - 1);
    return sb.toString();
  }
示例#2
0
 // @SuppressWarnings("unchecked")
 protected AbcNode(
     Node node,
     InputBuffer parseInputBuffer,
     List<ParseError> parseErrors,
     AbcInputBuffer abcInputBuffer) {
   super(null);
   if (node != null) {
     this.label = node.getLabel();
     this.value = parseInputBuffer.extract(node.getStartIndex(), node.getEndIndex());
     Position pos = parseInputBuffer.getPosition(node.getStartIndex());
     int sourceStartIndex = abcInputBuffer.getIndex(pos);
     int sourceEndIndex = sourceStartIndex + value.length();
     setCharStreamPosition(
         new CharStreamPosition(pos.line, pos.column, sourceStartIndex, sourceEndIndex));
     this.childs = new ArrayList(node.getChildren().size());
     Iterator it = node.getChildren().iterator();
     while (it.hasNext()) {
       AbcNode abcn = new AbcNode((Node) it.next(), parseInputBuffer, parseErrors, abcInputBuffer);
       abcn.parent = this;
       childs.add(abcn);
     }
     if (!hasError() /*(childs.size() == 0)*/ && node.hasError()) {
       this.errors = new ArrayList();
       it = parseErrors.iterator();
       while (it.hasNext()) {
         ParseError pe = (ParseError) it.next();
         String peValue = pe.getInputBuffer().extract(pe.getStartIndex(), pe.getEndIndex());
         String peMsg = pe.getErrorMessage();
         Position pePos = pe.getInputBuffer().getPosition(pe.getStartIndex());
         int peIndex = abcInputBuffer.getIndex(pePos);
         CharStreamPosition csp =
             new CharStreamPosition(
                 pePos.line,
                 pePos.column,
                 peIndex,
                 peIndex + (peValue.length() > 0 ? peValue.length() : 1));
         // if ((pe.getStartIndex() >= node.getStartIndex())
         //		&& (pe.getStartIndex() </*=*/ node.getEndIndex())) {
         if ((peIndex >= sourceStartIndex)
             && ((peIndex < sourceEndIndex) || (sourceStartIndex == sourceEndIndex))) {
           errors.add(new AbcParseError(peMsg, peValue, csp));
         }
       }
     }
   } else {
     this.label = "AbcFile-Error";
     this.value = "";
     int nbL = parseInputBuffer.getLineCount();
     for (int i = 1; i <= nbL; i++) this.value += parseInputBuffer.extractLine(i) + "\n";
     this.childs = new ArrayList(0);
     setCharStreamPosition(new CharStreamPosition(1, 1, 0, 1));
     if (parseErrors != null) {
       this.errors = new ArrayList();
       Iterator it = parseErrors.iterator();
       while (it.hasNext()) {
         ParseError pe = (ParseError) it.next();
         errors.add(new AbcParseError(pe.getErrorMessage(), value, getCharStreamPosition()));
       }
     }
   }
 }