package com.intellij.html.impl;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.impl.schema.AnyXmlElementDescriptor;
import com.intellij.xml.impl.schema.XmlNSDescriptorImpl;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class RelaxedHtmlFromSchemaNSDescriptor extends XmlNSDescriptorImpl {
  private static final Logger LOG = Logger.getInstance("#com.intellij.html.impl.RelaxedHtmlFromSchemaNSDescriptor");
  private static final Key<Boolean> TEMP_DEBUG_KEY = Key.create("IDEADEV-26043");

  public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
    XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);

    if (elementDescriptor == null && !tag.getNamespace().equals(XmlUtil.XHTML_URI)) {
      final Boolean data = tag.getUserData(TEMP_DEBUG_KEY);
      if (data != null && !data.booleanValue()) {
        LOG.error("Looks like we got an infinite loop for tag: " + tag.getText() + " and file: " + tag.getContainingFile().getText());
      }

      tag.putUserData(TEMP_DEBUG_KEY, data == null);
      return new AnyXmlElementDescriptor(null, tag.getNSDescriptor(tag.getNamespace(), true));
    }

    return elementDescriptor;
  }

  protected XmlElementDescriptor createElementDescriptor(final XmlTag tag) {
    return new RelaxedHtmlFromSchemaElementDescriptor(tag);
  }

  @NotNull
  public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable final XmlDocument doc) {
    return ArrayUtil.mergeArrays(super.getRootElementsDescriptors(doc), HtmlUtil.getCustomTagDescriptors(doc), XmlElementDescriptor.class);
  }
}

@@ -632,208 +632,8 @@
 l %7B%0A
-  private static final Logger LOG = Logger.getInstance(%22#com.intellij.html.impl.RelaxedHtmlFromSchemaNSDescriptor%22);%0A  private static final Key%3CBoolean%3E TEMP_DEBUG_KEY = Key.create(%22IDEADEV-26043%22);%0A%0A
   pu
@@ -871,315 +871,8 @@
 ) %7B%0A
-      final Boolean data = tag.getUserData(TEMP_DEBUG_KEY);%0A      if (data != null && !data.booleanValue()) %7B%0A        LOG.error(%22Looks like we got an infinite loop for tag: %22 + tag.getText() + %22 and file: %22 + tag.getContainingFile().getText());%0A      %7D%0A%0A      tag.putUserData(TEMP_DEBUG_KEY, data == null);%0A
     

fix stress