private static void writeFragments(List<? extends PsiFragment> psiFragments,
                                     XMLStreamWriter writer,
                                     @NotNull Project project,
                                     boolean shouldWriteOffsets) throws XMLStreamException {
    final PathMacroManager macroManager = PathMacroManager.getInstance(project);
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);

    for (PsiFragment fragment : psiFragments) {
      final PsiFile psiFile = fragment.getFile();
      final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : null;
      if (virtualFile != null) {
        writer.writeStartElement("fragment");
        writer.writeAttribute("file", macroManager.collapsePath(virtualFile.getUrl()));
        if (shouldWriteOffsets) {
          final Document document = documentManager.getDocument(psiFile);
          LOG.assertTrue(document != null);
          int startOffset = fragment.getStartOffset();
          final int line = document.getLineNumber(startOffset);
          writer.writeAttribute("line", String.valueOf(line));
          final int lineStartOffset = document.getLineStartOffset(line);
          if (Strings.isEmptyOrSpaces(document.getText().substring(lineStartOffset, startOffset))) {
            startOffset = lineStartOffset;
          }
          writer.writeAttribute("start", String.valueOf(startOffset));
          writer.writeAttribute("end", String.valueOf(fragment.getEndOffset()));
          if (fragment.containsMultipleFragments()) {
            final int[][] offsets = fragment.getOffsets();
            for (int[] offset : offsets) {
              writer.writeStartElement("offset");
              writer.writeAttribute("start", String.valueOf(offset[0]));
              writer.writeAttribute("end", String.valueOf(offset[1]));
              writer.writeEndElement();
            }
          }
        }
        writer.writeEndElement();
      }
    }
  }
private static void writeFragments(List<? extends PsiFragment> psiFragments,
                                     XMLStreamWriter writer,
                                     @NotNull Project project,
                                     boolean shouldWriteOffsets)