private static XmlTag getTag(Editor editor, PsiFile file) {
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = file.findElementAt(offset);
    PsiElement parent = element != null ? element.getParent() : null;
    if (parent instanceof XmlTag) return (XmlTag)parent;
    if (parent instanceof XmlAttribute) return null;

    element = file.findElementAt(offset - 1);
    parent = element != null ? element.getParent() : null;
    if (parent instanceof XmlTag) return (XmlTag)parent;
    return null;
  }
private static XmlTag getTag(Editor editor, PsiFile file)