@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 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; }