use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.
the class XPathAnnotator method visitXPathVariableReference.
@Override
public void visitXPathVariableReference(XPathVariableReference o) {
final ContextProvider contextProvider = o.getXPathContext();
checkVariableReference(myHolder, o, contextProvider);
super.visitXPathVariableReference(o);
}
use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.
the class CompletionLists method getVariableCompletions.
public static Collection<Lookup> getVariableCompletions(XPathElement reference) {
final ContextProvider contextProvider = ContextProvider.getContextProvider(reference);
final VariableContext resolver = contextProvider.getVariableContext();
if (resolver != null) {
final Object[] variablesInScope = resolver.getVariablesInScope(reference);
final List<Lookup> lookups = new ArrayList<>(variablesInScope.length);
for (final Object o : variablesInScope) {
if (o instanceof PsiNamedElement) {
final String type;
if (o instanceof XPathVariable) {
final XPathType t = ((XPathVariable) o).getType();
if (t != XPathType.UNKNOWN) {
type = t.getName();
} else {
type = "";
}
} else {
type = "";
}
final String name = ((PsiNamedElement) o).getName();
lookups.add(new VariableLookup("$" + name, type, ((PsiNamedElement) o).getIcon(0), (PsiElement) o));
} else {
lookups.add(new VariableLookup("$" + String.valueOf(o), PlatformIcons.VARIABLE_ICON));
}
}
return lookups;
} else {
return Collections.emptySet();
}
}
use of org.intellij.lang.xpath.context.ContextProvider in project intellij-community by JetBrains.
the class CompletionLists method getNodeTestCompletions.
public static Collection<Lookup> getNodeTestCompletions(final XPathNodeTest element) {
if (!element.isNameTest()) {
return Collections.emptyList();
}
final PrefixedName prefixedName = element.getQName();
assert prefixedName != null;
final String canonicalText = prefixedName.toString();
final String suffix = canonicalText.substring(canonicalText.indexOf(INTELLIJ_IDEA_RULEZ));
final XPathAxisSpecifier axisSpecifier = element.getStep().getAxisSpecifier();
final ContextProvider contextProvider = ContextProvider.getContextProvider(element);
final XmlElement context = contextProvider.getContextElement();
final boolean insidePrefix = suffix.contains(INTELLIJ_IDEA_RULEZ + ":");
final Set<Lookup> list = new HashSet<>();
addNameCompletions(contextProvider, element, list);
final String namespacePrefix = prefixedName.getPrefix();
if (namespacePrefix == null || insidePrefix) {
addNamespaceCompletions(contextProvider.getNamespaceContext(), list, context);
}
final XPathNodeTest.PrincipalType principalType = addContextNames(element, contextProvider, prefixedName, list);
if (namespacePrefix == null && !insidePrefix) {
if (axisSpecifier == null || axisSpecifier.isDefaultAxis()) {
list.addAll(getAxisCompletions());
// wow, this code sux. find a better implementation
PsiElement sibling = element.getParent().getPrevSibling();
while (sibling instanceof PsiWhiteSpace) {
sibling = sibling.getPrevSibling();
}
boolean check = sibling != null;
if (!check) {
XPathLocationPath lp = null;
do {
lp = PsiTreeUtil.getParentOfType(lp == null ? element : lp, XPathLocationPath.class, true);
} while (lp != null && lp.getPrevSibling() == null);
check = lp == null || (sibling = lp.getPrevSibling()) != null;
}
if (check) {
if (sibling instanceof XPathToken && XPathTokenTypes.PATH_OPS.contains(((XPathToken) sibling).getTokenType())) {
// xx/yy<caret> : prevSibl = /
} else {
list.addAll(getFunctionCompletions(element));
list.addAll(getVariableCompletions(element));
}
}
}
if (principalType == XPathNodeTest.PrincipalType.ELEMENT && prefixedName.getPrefix() == null) {
list.addAll(getNodeTypeCompletions(element));
}
}
return list;
}
use of org.intellij.lang.xpath.context.ContextProvider 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.ContextProvider 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);
}
Aggregations