@Override protected boolean isAvailableForFile(PsiFile file) { return file instanceof XmlFile && AndroidFacet.getInstance(file) != null && DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile) file) instanceof LayoutDomFileDescription; }
@NotNull private static Map<Module, String> collectJpsPluginModules(@NotNull Module module) { XmlFile pluginXml = PluginModuleType.getPluginXml(module); if (pluginXml == null) return Collections.emptyMap(); DomFileElement<IdeaPlugin> fileElement = DomManager.getDomManager(module.getProject()).getFileElement(pluginXml, IdeaPlugin.class); if (fileElement == null) return Collections.emptyMap(); Map<Module, String> jpsPluginToOutputPath = new HashMap<Module, String>(); IdeaPlugin plugin = fileElement.getRootElement(); List<Extensions> extensions = plugin.getExtensions(); for (Extensions extensionGroup : extensions) { XmlTag extensionsTag = extensionGroup.getXmlTag(); String defaultExtensionNs = extensionsTag.getAttributeValue("defaultExtensionNs"); for (XmlTag tag : extensionsTag.getSubTags()) { String name = tag.getLocalName(); String qualifiedName = defaultExtensionNs != null ? defaultExtensionNs + "." + name : name; if (CompileServerPlugin.EP_NAME.getName().equals(qualifiedName)) { String classpath = tag.getAttributeValue("classpath"); if (classpath != null) { for (String path : StringUtil.split(classpath, ";")) { String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path)); Module jpsModule = ModuleManager.getInstance(module.getProject()).findModuleByName(moduleName); if (jpsModule != null) { jpsPluginToOutputPath.put(jpsModule, path); } } } } } } return jpsPluginToOutputPath; }
public DomElementsErrorPanel(final DomElement... domElements) { assert domElements.length > 0; myDomElements = domElements; final DomManager domManager = domElements[0].getManager(); myProject = domManager.getProject(); myAnnotationsManager = (DomElementAnnotationsManagerImpl) DomElementAnnotationsManager.getInstance(myProject); setPreferredSize(getDimension()); myErrorStripeRenderer = new DomElementsTrafficLightRenderer(DomUtil.getFile(domElements[0])); Disposer.register(this, myErrorStripeRenderer); addUpdateRequest(); domManager.addDomEventListener( new DomChangeAdapter() { protected void elementChanged(DomElement element) { addUpdateRequest(); } }, this); }
@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(); }
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; }
@Override public ProblemDescriptor[] checkFile( @NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof XmlFile)) { return ProblemDescriptor.EMPTY_ARRAY; } final AndroidFacet facet = AndroidFacet.getInstance(file); if (facet == null) { return ProblemDescriptor.EMPTY_ARRAY; } final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile) file); if (!(description instanceof LayoutDomFileDescription) && !(description instanceof MenuDomFileDescription)) { return ProblemDescriptor.EMPTY_ARRAY; } final Collection<PsiClass> activities = findRelatedActivities((XmlFile) file, facet, description); final MyVisitor visitor = new MyVisitor(manager, isOnTheFly, activities); file.accept(visitor); return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]); }
@Nullable public static LayoutViewElement getLayoutViewElement(@NotNull XmlTag tag) { final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag); return domElement instanceof LayoutViewElement ? (LayoutViewElement) domElement : null; }
@Override protected boolean isMyFile(PsiFile file) { return DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile) file) instanceof LayoutDomFileDescription; }
@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(); }
public void visitXmlTag(XmlTag tag) { final PsiFile file = tag.getContainingFile(); if (file.getFileType() != StdFileTypes.XML) { return; } if (!tag.getLocalName().equals("define")) { return; } if (!tag.getNamespace().equals(ApplicationLoader.RNG_NAMESPACE)) { return; } if (tag.getAttribute("combine") != null) { return; // ? } final XmlAttribute attr = tag.getAttribute("name"); if (attr == null) return; final XmlAttributeValue value = attr.getValueElement(); if (value == null) return; final String s = value.getValue(); if (s == null || s.length() == 0) { return; } final PsiElement parent = value.getParent(); if (!(parent instanceof XmlAttribute)) { return; } if (!"name".equals(((XmlAttribute) parent).getName())) { return; } final PsiElement grandParent = parent.getParent(); if (!(grandParent instanceof XmlTag)) { return; } final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag); if (element == null) { return; } final RngGrammar rngGrammar = element.getParentOfType(RngGrammar.class, true); if (rngGrammar != null) { if (processUsages(tag, value, new LocalSearchScope(rngGrammar.getXmlTag()))) return; } else { if (processUsages(tag, value, new LocalSearchScope(file))) return; } final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<XmlFile>(); RelaxIncludeIndex.processBackwardDependencies((XmlFile) file, collector); if (processUsages(tag, value, new LocalSearchScope(collector.toArray()))) return; myHolder.registerProblem( value, "Unreferenced define", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MyFix<XmlTag>(tag)); }
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass"}) public static DomManagerImpl getDomManager(Project project) { return (DomManagerImpl) DomManager.getDomManager(project); }