use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class CompletionLists method addContextNames.
private static XPathNodeTest.PrincipalType addContextNames(XPathNodeTest element, ContextProvider contextProvider, PrefixedName prefixedName, Set<Lookup> list) {
final NamespaceContext namespaceContext = contextProvider.getNamespaceContext();
final XmlElement context = contextProvider.getContextElement();
final XPathNodeTest.PrincipalType principalType = element.getPrincipalType();
if (principalType == XPathNodeTest.PrincipalType.ELEMENT) {
final Set<QName> elementNames = contextProvider.getElements(false);
if (elementNames != null) {
for (QName pair : elementNames) {
if ("*".equals(pair.getLocalPart()))
continue;
if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, true)) {
if (prefixedName.getPrefix() == null && namespaceContext != null) {
final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context);
list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ELEMENT));
} else {
list.add(new NodeLookup(pair.getLocalPart(), XPathNodeTest.PrincipalType.ELEMENT));
}
}
}
}
} else if (principalType == XPathNodeTest.PrincipalType.ATTRIBUTE) {
final Set<QName> attributeNames = contextProvider.getAttributes(false);
if (attributeNames != null) {
for (QName pair : attributeNames) {
if ("*".equals(pair.getLocalPart()))
continue;
if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, false)) {
if (prefixedName.getPrefix() == null && namespaceContext != null) {
final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context);
list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ATTRIBUTE));
} else {
list.add(new NodeLookup(pair.getLocalPart(), XPathNodeTest.PrincipalType.ATTRIBUTE));
}
}
}
}
}
return principalType;
}
use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class PrefixReferenceImpl method resolve.
@Nullable
public PsiElement resolve() {
final ContextProvider provider = getElement().getXPathContext();
final NamespaceContext namespaceContext = provider.getNamespaceContext();
if (namespaceContext != null) {
return namespaceContext.resolve(getCanonicalText(), provider.getContextElement());
} else {
return null;
}
}
use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class PrefixReferenceImpl method isUnresolved.
public boolean isUnresolved() {
if (!canResolve())
return true;
if (resolve() != null) {
return false;
}
final ContextProvider provider = getElement().getXPathContext();
final NamespaceContext namespaceContext = provider.getNamespaceContext();
assert namespaceContext != null;
final String prefix = getCanonicalText();
return !namespaceContext.getKnownPrefixes(provider.getContextElement()).contains(prefix);
}
use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class XsltExtractFunctionAction method getSettings.
protected RefactoringOptions getSettings(XPathExpression expression, Set<XPathExpression> matchingExpressions) {
final String name = Messages.showInputDialog(expression.getProject(), "Function Name: ", getRefactoringName(), Messages.getQuestionIcon());
final boolean[] b = new boolean[] { false };
if (name != null) {
final String[] parts = name.split(":", 2);
if (parts.length < 2) {
Messages.showMessageDialog(expression.getProject(), "Custom functions require a prefixed name", "Error", Messages.getErrorIcon());
b[0] = true;
}
final XmlElement context = PsiTreeUtil.getContextOfType(expression, XmlElement.class);
final NamespaceContext namespaceContext = expression.getXPathContext().getNamespaceContext();
if (namespaceContext != null && context != null && namespaceContext.resolve(parts[0], context) == null) {
Messages.showMessageDialog(expression.getProject(), "Prefix '" + parts[0] + "' is not defined", "Error", Messages.getErrorIcon());
b[0] = true;
}
}
return new RefactoringOptions() {
@Override
public boolean isCanceled() {
return b[0];
}
@Override
public String getName() {
return name;
}
};
}
use of org.intellij.lang.xpath.context.NamespaceContext in project intellij-community by JetBrains.
the class TestNamespaceContext method install.
@TestOnly
public static void install(Disposable parent) {
final NamespaceContext old = ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT;
ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE;
Disposer.register(parent, new Disposable() {
@Override
public void dispose() {
ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = old;
}
});
}
Aggregations