private void composeDescription(@NotNull CommonProblemDescriptor description,
                                  int i,
                                  @NotNull StringBuilder buf,
                                  @NotNull RefEntity refElement) {
    PsiElement expression = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getPsiElement() : null;
    StringBuilder anchor = new StringBuilder();
    VirtualFile vFile = null;

    if (expression != null) {
      vFile = (expression instanceof PsiFileSystemItem ? (PsiFileSystemItem) expression : expression.getContainingFile()).getVirtualFile();
      if (vFile instanceof VirtualFileWindow) vFile = ((VirtualFileWindow)vFile).getDelegate();

      anchor.append("<a href=\"");
      anchor.append(appendURL(vFile, "descr:" + i));

      anchor.append("\"><code>");
      anchor.append(StringUtil.escapeXmlEntities(ProblemDescriptorUtil.extractHighlightedText(description, expression).replaceAll("\\$", "\\\\\\$")));
      anchor.append("</code></a>");
    }
    else {
      anchor.append("<font style=\"font-weight:bold; color:#FF0000\";>");
      anchor.append(AnalysisBundle.message("inspection.export.results.invalidated.item"));
      anchor.append("</font>");
    }

    String descriptionTemplate = description.getDescriptionTemplate();
    if (XmlStringUtil.isWrappedInHtml(descriptionTemplate)) {
      descriptionTemplate = XmlStringUtil.stripHtml(descriptionTemplate);
    }
    else {
      descriptionTemplate = StringUtil.replace(descriptionTemplate, "<code>", "'");
      descriptionTemplate = StringUtil.replace(descriptionTemplate, "</code>", "'");
      descriptionTemplate = XmlStringUtil.escapeString(descriptionTemplate);
    }
    String res = descriptionTemplate.replace(ProblemDescriptorUtil.REF_REFERENCE, anchor.toString());
    int lineNumber = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getLineNumber() : -1;
    StringBuilder lineAnchor = new StringBuilder();
    if (expression != null && lineNumber >= 0) {
      Document doc = FileDocumentManager.getInstance().getDocument(vFile);
      if (doc != null && lineNumber < doc.getLineCount()) {
        lineNumber = Math.min(lineNumber, doc.getLineCount() - 1);
        lineAnchor.append(AnalysisBundle.message("inspection.export.results.at.line")).append(" ");
        lineAnchor.append("<a href=\"");
        int offset = doc.getLineStartOffset(lineNumber);
        offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), offset, " \t");
        lineAnchor.append(appendURL(vFile, String.valueOf(offset)));
        lineAnchor.append("\">");
        lineAnchor.append((lineNumber + 1));
        lineAnchor.append("</a>");
        if (!res.contains(ProblemDescriptorUtil.LOC_REFERENCE)) {
          res += " (" + ProblemDescriptorUtil.LOC_REFERENCE + ")";
        }
        res = res.replace(ProblemDescriptorUtil.LOC_REFERENCE, lineAnchor.toString());
      }
    }
    buf.append(res.replace("#end", "").replace("#treeend",""));
    composeAdditionalDescription(buf, refElement);
  }
private void composeDescription(@NotNull CommonProblemDescriptor description,
                                  int i,
                                  @NotNull StringBuilder buf,
                                  @NotNull RefEntity refElement)