Search in sources :

Example 1 with Grammar

use of org.intellij.plugins.relaxNG.model.Grammar in project intellij-community by JetBrains.

the class OverriddenDefineRenderer method getClickAction.

@Override
@Nullable
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final PsiElement element = myDefine.getPsiElement();
            if (element == null || !element.isValid())
                return;
            final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<>();
            final XmlFile localFile = (XmlFile) element.getContainingFile();
            RelaxIncludeIndex.processBackwardDependencies(localFile, collector);
            final Collection<XmlFile> files = collector.getCollection();
            final List<Define> result = new SmartList<>();
            final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(myDefine, localFile, result);
            for (XmlFile file : files) {
                final Grammar grammar = GrammarFactory.getGrammar(file);
                if (grammar == null)
                    continue;
                grammar.acceptChildren(searcher);
            }
            if (result.size() > 0) {
                OverridingDefineRenderer.doClickAction(e, result, "Go to overriding define(s)");
            }
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Grammar(org.intellij.plugins.relaxNG.model.Grammar) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Define(org.intellij.plugins.relaxNG.model.Define) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Grammar

use of org.intellij.plugins.relaxNG.model.Grammar in project intellij-community by JetBrains.

the class RelaxSymbolIndex method getSymbolsByName.

public static NavigationItem[] getSymbolsByName(final String name, Project project, boolean includeNonProjectItems) {
    final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
    final Collection<NavigationItem> result = new ArrayList<>();
    PsiManager psiManager = PsiManager.getInstance(project);
    for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(NAME, name, scope)) {
        final PsiFile psiFile = psiManager.findFile(file);
        if (psiFile instanceof XmlFile) {
            final Grammar grammar = GrammarFactory.getGrammar((XmlFile) psiFile);
            if (grammar != null) {
                grammar.acceptChildren(new CommonElement.Visitor() {

                    @Override
                    public void visitDefine(Define define) {
                        if (name.equals(define.getName())) {
                            final PsiElement psi = define.getPsiElement();
                            if (psi != null) {
                                MyNavigationItem.add((NavigationItem) define.getPsiElement(), result);
                            }
                        }
                    }
                });
            }
        }
    }
    return result.toArray(new NavigationItem[result.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager) Grammar(org.intellij.plugins.relaxNG.model.Grammar) CommonElement(org.intellij.plugins.relaxNG.model.CommonElement) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) Define(org.intellij.plugins.relaxNG.model.Define) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 XmlFile (com.intellij.psi.xml.XmlFile)2 Define (org.intellij.plugins.relaxNG.model.Define)2 Grammar (org.intellij.plugins.relaxNG.model.Grammar)2 NavigationItem (com.intellij.navigation.NavigationItem)1 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 SmartList (com.intellij.util.SmartList)1 CommonElement (org.intellij.plugins.relaxNG.model.CommonElement)1 Nullable (org.jetbrains.annotations.Nullable)1