@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; }
@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 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; }
@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); }
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass"}) public static DomManagerImpl getDomManager(Project project) { return (DomManagerImpl) DomManager.getDomManager(project); }