use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.
the class CreatePatternFix method doFix.
private void doFix() throws IncorrectOperationException {
final XmlTag tag = PsiTreeUtil.getParentOfType(myReference.getElement(), XmlTag.class);
assert tag != null;
final XmlTag defineTag = tag.createChildTag("define", ApplicationLoader.RNG_NAMESPACE, "\n \n", false);
defineTag.setAttribute("name", myReference.getCanonicalText());
final RngGrammar grammar = ((DefinitionReference) myReference).getScope();
if (grammar == null)
return;
final XmlTag root = grammar.getXmlTag();
if (root == null)
return;
final XmlTag[] tags = root.getSubTags();
for (XmlTag xmlTag : tags) {
if (PsiTreeUtil.isAncestor(xmlTag, tag, false)) {
final XmlElementFactory ef = XmlElementFactory.getInstance(tag.getProject());
final XmlText text = ef.createDisplayText(" ");
final PsiElement e = root.addAfter(text, xmlTag);
root.addAfter(defineTag, e);
return;
}
}
root.add(defineTag);
}
use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.
the class DefinitionReference method getQuickFixes.
@Override
public LocalQuickFix[] getQuickFixes() {
final XmlTag tag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
assert tag != null;
final RngGrammar scope = myValue.getParentOfType(RngGrammar.class, true);
if (scope != null) {
return new LocalQuickFix[] { new CreatePatternFix(this) };
}
return LocalQuickFix.EMPTY_ARRAY;
}
use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar 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.xml.dom.RngGrammar 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();
}
use of org.intellij.plugins.relaxNG.xml.dom.RngGrammar in project intellij-community by JetBrains.
the class DefinitionReference method multiResolve.
@Override
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
final RngGrammar scope = getScope();
if (scope == null) {
return ResolveResult.EMPTY_ARRAY;
}
final Set<Define> set = DefinitionResolver.resolve(scope, myValue.getValue());
if (set == null || set.size() == 0)
return ResolveResult.EMPTY_ARRAY;
return ContainerUtil.map2Array(set, ResolveResult.class, this);
}
Aggregations