@Override
  public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement e = descriptor.getPsiElement();
    if (e == null) return;

    XmlTag myTag = PsiTreeUtil.getParentOfType(e, XmlTag.class);
    if (myTag == null) return;
    Pair<PsiElement, PsiElement> pair = HtmlFormInputWithoutLabelInspection.getNearestText(myTag, myTextBeforeTag ? new HtmlFormInputWithoutLabelInspection.BackwardIterator() : new HtmlFormInputWithoutLabelInspection.ForwardIterator());
    if (pair == null) return;
    final PsiElement myLeft = pair.first;
    final PsiElement myRight = pair.second;

    StringBuilder sb = new StringBuilder("<a>");
    if (myTextBeforeTag) {
      for (PsiElement element = myLeft.getParent().getFirstChild();
           element != null && element != myLeft;
           element = element.getNextSibling()) {
        sb.append(element.getText());
      }
    }
    else {
      for (PsiElement element = myRight.getNextSibling();
           element != null;
           element = element.getNextSibling()) {
        sb.append(element.getText());
        if (element == element.getParent().getLastChild()) {
          break;
        }
      }
    }
    XmlTag tmpTag = CreateNewLabelAction.createElementFromText(project, myTag, sb.toString());
    PsiElement anchor = null;
    for (PsiElement element : tmpTag.getChildren()) {
      if (element instanceof XmlText || element instanceof PsiComment) {
        if (anchor == null) {
          anchor = myLeft.getParent().replace(element);
        } else {
          anchor = myLeft.addAfter(element, anchor);
        }
      }
    }

    String id = CreateNewLabelAction.getId(myTag);

    if (id != null) {
      StringBuilder builder = new StringBuilder("\n<label for=\"").append(id).append("\">");
      for (PsiElement element = myLeft; element != null; element = element.getNextSibling()) {
        builder.append(element.getText());
        if (element == myRight) {
          break;
        }
      }
      builder.append("</label>");
      XmlTag labelTag = CreateNewLabelAction.createElementFromText(project, myTag, builder.toString());
      if (myTextBeforeTag) {
        myTag.getParent().addBefore(labelTag, myTag);
      }
      else {
        myTag.getParent().addAfter(labelTag, myTag);
      }
    }
    else {
      StringBuilder builder = new StringBuilder("\n<label>\n");
      if (!myTextBeforeTag) {
        builder.append(myTag.getText());
        builder.append("\n");
      }
      for (PsiElement element = myLeft; element != null; element = element.getNextSibling()) {
        builder.append(element.getText());
        if (element == myRight) {
          break;
        }
      }
      if (myTextBeforeTag) {
        builder.append("\n");
        builder.append(myTag.getText());
      }
      builder.append("\n</label>");
      XmlTag tag = CreateNewLabelAction.createElementFromText(project, myTag, builder.toString());
      myTag.replace(tag);
    }
  }
@Override
  public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor)