private StyledString getLineElementLabel(ICustomLineElement lineElement) {
    int lineNumber = lineElement.getLine();
    String lineNumberString = MessageFormat.format("{0}:", lineNumber);

    StyledString str = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);

    Match[] matches = lineElement.getMatches(fPage.getInput());
    Arrays.sort(matches, fMatchComparator);

    String content = lineElement.getContents();

    int pos = evaluateLineStart(matches, content, lineElement.getOffset());

    int length = content.length();

    int charsToCut =
        getCharsToCut(
            length, matches); // number of characters to leave away if the line is too long
    for (int i = 0; i < matches.length; i++) {
      ICustomMatch match = (ICustomMatch) matches[i];
      int start = Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0);
      // append gap between last match and the new one
      if (pos < start) {
        if (charsToCut > 0) {
          charsToCut = appendShortenedGap(content, pos, start, charsToCut, i == 0, str);
        } else {
          str.append(content.substring(pos, start));
        }
      }
      // append match
      int end =
          Math.min(
              match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(),
              lineElement.getLength());
      str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE);
      pos = end;
    }
    // append rest of the line
    if (charsToCut > 0) {
      appendShortenedGap(content, pos, length, charsToCut, false, str);
    } else {
      str.append(content.substring(pos));
    }
    return str;
  }