use of org.intellij.plugins.relaxNG.model.Define in project intellij-community by JetBrains.
the class RngRefImpl method getPattern.
@Override
public Define getPattern() {
final XmlAttributeValue value = getName().getXmlAttributeValue();
if (value == null)
return null;
final String name = getReferencedName();
if (name == null) {
return null;
}
final RngGrammar scope = getScope();
if (scope == null) {
return null;
}
final Set<Define> defines = DefinitionResolver.resolve(scope, name);
// TODO: honor combine & return virtual element if defines.size() > 1
return defines != null && defines.size() > 0 ? defines.iterator().next() : null;
}
use of org.intellij.plugins.relaxNG.model.Define 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)");
}
}
};
}
use of org.intellij.plugins.relaxNG.model.Define 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()]);
}
use of org.intellij.plugins.relaxNG.model.Define in project intellij-community by JetBrains.
the class OverridingDefineRenderer method doClickAction.
static void doClickAction(AnActionEvent e, Collection<Define> set, String title) {
if (set.size() == 1) {
final Navigatable n = (Navigatable) set.iterator().next().getPsiElement();
OpenSourceUtil.navigate(true, n);
} else {
final Define[] array = set.toArray(new Define[set.size()]);
NavigationUtil.getPsiElementPopup(ContainerUtil.map(array, define -> define.getPsiElement(), PsiElement.EMPTY_ARRAY), title).show(new RelativePoint((MouseEvent) e.getInputEvent()));
}
}
use of org.intellij.plugins.relaxNG.model.Define in project intellij-community by JetBrains.
the class DefinitionReference method getVariants.
@Override
@NotNull
public Object[] getVariants() {
final RngGrammar scope = getScope();
if (scope == null) {
return ResolveResult.EMPTY_ARRAY;
}
final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
if (map == null || map.size() == 0)
return ArrayUtil.EMPTY_OBJECT_ARRAY;
return ContainerUtil.mapNotNull(map.values(), defines -> {
final Define define = defines.iterator().next();
if (defines.size() == 0) {
return null;
} else {
final PsiElement element = define.getPsiElement();
if (element != null) {
final PsiPresentableMetaData data = (PsiPresentableMetaData) ((PsiMetaOwner) element).getMetaData();
if (data != null) {
return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
} else {
return define.getName();
}
} else {
return define.getName();
}
}
}).toArray();
}
Aggregations