private void checkTagByDescriptor(final XmlTag tag) {
    String name = tag.getName();

    XmlElementDescriptor elementDescriptor;

    final PsiElement parent = tag.getParent();
    if (parent instanceof XmlTag) {
      XmlTag parentTag = (XmlTag) parent;

      elementDescriptor = XmlUtil.getDescriptorFromContext(tag);

      final XmlElementDescriptor parentDescriptor = parentTag.getDescriptor();

      if (parentDescriptor != null && elementDescriptor == null && shouldBeValidated(tag)) {
        if (tag instanceof HtmlTag) {
          // XmlEntitiesInspection inspection = getInspectionProfile(tag,
          // HtmlStyleLocalInspection.SHORT_NAME);
          // if (inspection != null /*&&
          // isAdditionallyDeclared(inspection.getAdditionalEntries(XmlEntitiesInspection.UNKNOWN_TAG), name)*/) {
          return;
          // }
        }

        addElementsForTag(
            tag,
            XmlErrorMessages.message("element.is.not.allowed.here", name),
            getTagProblemInfoType(tag),
            null);
        return;
      }

      if (elementDescriptor instanceof AnyXmlElementDescriptor || elementDescriptor == null) {
        elementDescriptor = tag.getDescriptor();
      }

      if (elementDescriptor == null) return;
    } else {
      // root tag
      elementDescriptor = tag.getDescriptor();

      if (elementDescriptor == null) {
        addElementsForTag(
            tag,
            XmlErrorMessages.message("element.must.be.declared", name),
            HighlightInfoType.WRONG_REF,
            null);
        return;
      }
    }

    checkRequiredAttributes(tag, name, elementDescriptor);

    if (elementDescriptor instanceof Validator) {
      //noinspection unchecked
      ((Validator<XmlTag>) elementDescriptor).validate(tag, this);
    }
  }
  private void reportOneTagProblem(
      final XmlTag tag,
      final String name,
      final String localizedMessage,
      final IntentionAction basicIntention,
      final HighlightDisplayKey key,
      final XmlEntitiesInspection inspection,
      final int type) {
    boolean htmlTag = false;

    if (tag instanceof HtmlTag) {
      htmlTag = true;
      if (isAdditionallyDeclared(inspection.getAdditionalEntries(type), name)) return;
    }

    final InspectionProfile profile =
        InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
    final IntentionAction intentionAction = inspection.getIntentionAction(name, type);
    if (htmlTag && profile.isToolEnabled(key, tag)) {
      addElementsForTagWithManyQuickFixes(
          tag,
          localizedMessage,
          isInjectedHtmlTagForWhichNoProblemsReporting((HtmlTag) tag)
              ? HighlightInfoType.INFORMATION
              : SeverityRegistrar.getInstance(tag.getProject())
                  .getHighlightInfoTypeBySeverity(profile.getErrorLevel(key, tag).getSeverity()),
          intentionAction,
          basicIntention);
    } else if (!htmlTag) {
      addElementsForTag(tag, localizedMessage, HighlightInfoType.ERROR, basicIntention);
    }
  }
 public void addMessage(PsiElement context, String message, int type) {
   if (message != null && message.length() > 0) {
     if (context instanceof XmlTag
         && XmlExtension.getExtension(context.getContainingFile())
             .shouldBeHighlightedAsTag((XmlTag) context)) {
       HighlightInfoType infoType =
           type == ERROR
               ? HighlightInfoType.ERROR
               : type == WARNING ? HighlightInfoType.WARNING : HighlightInfoType.WEAK_WARNING;
       addElementsForTag((XmlTag) context, message, infoType, null);
     } else {
       addToResults(
           HighlightInfo.createHighlightInfo(HighlightInfoType.WRONG_REF, context, message));
     }
   }
 }