public static List<DomElement> getDefinedChildren(
      @NotNull final DomElement parent, final boolean tags, final boolean attributes) {
    if (parent instanceof MergedObject) {
      final SmartList<DomElement> result = new SmartList<>();
      parent.acceptChildren(
          new DomElementVisitor() {
            @Override
            public void visitDomElement(final DomElement element) {
              if (hasXml(element)) {
                result.add(element);
              }
            }
          });
      return result;
    }

    ProgressManager.checkCanceled();

    if (parent instanceof GenericAttributeValue) return Collections.emptyList();

    if (parent instanceof DomFileElement) {
      final DomFileElement element = (DomFileElement) parent;
      return tags ? Arrays.asList(element.getRootElement()) : Collections.<DomElement>emptyList();
    }

    final XmlElement xmlElement = parent.getXmlElement();
    if (xmlElement instanceof XmlTag) {
      XmlTag tag = (XmlTag) xmlElement;
      final DomManager domManager = parent.getManager();
      final SmartList<DomElement> result = new SmartList<>();
      if (attributes) {
        for (final XmlAttribute attribute : tag.getAttributes()) {
          if (!attribute.isValid()) {
            LOG.error("Invalid attr: parent.valid=" + tag.isValid());
            continue;
          }
          GenericAttributeValue element = domManager.getDomElement(attribute);
          if (checkHasXml(attribute, element)) {
            ContainerUtil.addIfNotNull(result, element);
          }
        }
      }
      if (tags) {
        for (final XmlTag subTag : tag.getSubTags()) {
          if (!subTag.isValid()) {
            LOG.error("Invalid subtag: parent.valid=" + tag.isValid());
            continue;
          }
          DomElement element = domManager.getDomElement(subTag);
          if (checkHasXml(subTag, element)) {
            ContainerUtil.addIfNotNull(result, element);
          }
        }
      }
      return result;
    }
    return Collections.emptyList();
  }
 @Nullable
 public UsageType getUsageType(PsiElement element) {
   final PsiFile psiFile = element.getContainingFile();
   if (XMLLanguage.INSTANCE.equals(psiFile.getLanguage())
       && DomManager.getDomManager(element.getProject())
               .getFileElement((XmlFile) psiFile, DomElement.class)
           != null) {
     return DOM_USAGE_TYPE;
   }
   return null;
 }
  @Nullable
  public static DomElement getDomElement(@Nullable final PsiElement element) {
    if (element == null) return null;

    final Project project = element.getProject();
    final DomManager domManager = DomManager.getDomManager(project);
    final XmlAttribute attr = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (attr != null) {
      final GenericAttributeValue value = domManager.getDomElement(attr);
      if (value != null) return value;
    }

    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
    while (tag != null) {
      final DomElement domElement = domManager.getDomElement(tag);
      if (domElement != null) return domElement;

      tag = tag.getParentTag();
    }
    return null;
  }
  @NotNull
  public static <T extends DomElement> T getOriginalElement(@NotNull final T domElement) {
    final XmlElement psiElement = domElement.getXmlElement();
    if (psiElement == null) return domElement;

    final PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
    final TextRange range = psiElement.getTextRange();
    final PsiElement element = psiFile.findElementAt(range.getStartOffset());
    final int maxLength = range.getLength();
    final boolean isAttribute = psiElement instanceof XmlAttribute;
    final Class<? extends XmlElement> clazz = isAttribute ? XmlAttribute.class : XmlTag.class;
    final DomManager domManager = domElement.getManager();
    DomElement current = null;
    for (XmlElement next = PsiTreeUtil.getParentOfType(element, clazz, false);
        next != null && next.getTextLength() <= maxLength;
        next = PsiTreeUtil.getParentOfType(next, clazz, true)) {
      current =
          isAttribute
              ? domManager.getDomElement((XmlAttribute) next)
              : domManager.getDomElement((XmlTag) next);
      if (current != null && domElement.getClass() != current.getClass()) current = null;
    }
    return (T) current;
  }
 @Override
 @NotNull
 protected JComponent createCustomComponent() {
   new MnemonicHelper().register(getComponent());
   myComponent = myComponentFactory.create();
   DomUIFactory.getDomUIFactory().setupErrorOutdatingUserActivityWatcher(this, getDomElement());
   DomManager.getDomManager(getProject())
       .addDomEventListener(
           new DomEventListener() {
             @Override
             public void eventOccured(DomEvent event) {
               checkIsValid();
             }
           },
           this);
   Disposer.register(this, myComponent);
   return myComponent.getComponent();
 }
  @Nullable
  public static <T extends DomElement> T findDomElement(
      @Nullable final PsiElement element, final Class<T> beanClass, boolean strict) {
    if (element == null) return null;

    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, strict);
    DomElement domElement;

    while (tag != null) {
      domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);

      if (domElement != null) {
        return domElement.getParentOfType(beanClass, false);
      }
      tag = tag.getParentTag();
    }
    return null;
  }
  public <T extends DomElement> List<DomFileElement<T>> getFileElements(
      final Class<T> clazz, final Project project, @Nullable final GlobalSearchScope scope) {
    final Collection<VirtualFile> list =
        scope == null
            ? getDomFileCandidates(clazz, project)
            : getDomFileCandidates(clazz, project, scope);
    final ArrayList<DomFileElement<T>> result = new ArrayList<DomFileElement<T>>(list.size());
    for (VirtualFile file : list) {
      final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
      if (psiFile instanceof XmlFile) {
        final DomFileElement<T> element =
            DomManager.getDomManager(project).getFileElement((XmlFile) psiFile, clazz);
        if (element != null) {
          result.add(element);
        }
      }
    }

    return result;
  }
 @Nullable
 private static <T extends MavenDomElement> DomFileElement<T> getMavenDomFile(
     @NotNull PsiFile file, @NotNull Class<T> clazz) {
   if (!(file instanceof XmlFile)) return null;
   return DomManager.getDomManager(file.getProject()).getFileElement((XmlFile) file, clazz);
 }
  protected DomModelTreeView(
      DomElement rootElement, DomManager manager, SimpleTreeStructure treeStructure) {
    myDomManager = manager;
    myRootElement = rootElement;
    myTree = new SimpleTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
    myTree.setRootVisible(isRootVisible());
    myTree.setShowsRootHandles(true);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);

    myBuilder =
        new AbstractTreeBuilder(
            myTree,
            (DefaultTreeModel) myTree.getModel(),
            treeStructure,
            WeightBasedComparator.INSTANCE,
            false);
    Disposer.register(this, myBuilder);

    myBuilder.setNodeDescriptorComparator(null);

    myBuilder.initRootNode();

    add(myTree, BorderLayout.CENTER);

    myTree.addTreeExpansionListener(
        new TreeExpansionListener() {
          @Override
          public void treeExpanded(TreeExpansionEvent event) {
            final SimpleNode simpleNode = myTree.getNodeFor(event.getPath());

            if (simpleNode instanceof AbstractDomElementNode) {
              ((AbstractDomElementNode) simpleNode).setExpanded(true);
            }
          }

          @Override
          public void treeCollapsed(TreeExpansionEvent event) {
            final SimpleNode simpleNode = myTree.getNodeFor(event.getPath());

            if (simpleNode instanceof AbstractDomElementNode) {
              ((AbstractDomElementNode) simpleNode).setExpanded(false);
              simpleNode.update();
            }
          }
        });

    myDomManager.addDomEventListener(
        new DomChangeAdapter() {
          @Override
          protected void elementChanged(DomElement element) {
            if (element.isValid()) {
              queueUpdate(DomUtil.getFile(element).getVirtualFile());
            } else if (element instanceof DomFileElement) {
              final XmlFile xmlFile = ((DomFileElement) element).getFile();
              queueUpdate(xmlFile.getVirtualFile());
            }
          }
        },
        this);

    final Project project = myDomManager.getProject();
    DomElementAnnotationsManager.getInstance(project)
        .addHighlightingListener(
            new DomElementAnnotationsManager.DomHighlightingListener() {
              @Override
              public void highlightingFinished(@NotNull DomFileElement element) {
                if (element.isValid()) {
                  queueUpdate(DomUtil.getFile(element).getVirtualFile());
                }
              }
            },
            this);

    myTree.setPopupGroup(getPopupActions(), DOM_MODEL_TREE_VIEW_POPUP);
  }
 protected final Project getProject() {
   return myDomManager.getProject();
 }
 @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass"})
 public static DomManagerImpl getDomManager(Project project) {
   return (DomManagerImpl) DomManager.getDomManager(project);
 }