use of org.intellij.lang.xpath.context.VariableContext 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.VariableContext in project intellij-community by JetBrains.
the class XPathAnnotator method markUnresolvedVariable.
private static void markUnresolvedVariable(XPathVariableReference reference, AnnotationHolder holder) {
final String referencedName = reference.getReferencedName();
// missing name is already flagged by parser
if (referencedName.length() > 0) {
final TextRange range = reference.getTextRange().shiftRight(1).grown(-1);
final Annotation ann = holder.createErrorAnnotation(range, "Unresolved variable '" + referencedName + "'");
ann.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
final VariableContext variableContext = ContextProvider.getContextProvider(reference).getVariableContext();
if (variableContext != null) {
final IntentionAction[] fixes = variableContext.getUnresolvedVariableFixes(reference);
for (IntentionAction fix : fixes) {
ann.registerFix(fix);
}
}
}
}
use of org.intellij.lang.xpath.context.VariableContext in project intellij-community by JetBrains.
the class XPathVariableReferenceImpl method resolve.
@Nullable
public XPathVariable resolve() {
if (getContainingFile().getLanguage() == XPathFileType.XPATH2.getLanguage()) {
XPathVariableHolder f = PsiTreeUtil.getParentOfType(this, XPathVariableHolder.class, true);
while (f != null) {
final XPathVariable variable = findVariable(f.getVariables(), getReferencedName());
if (variable != null) {
return variable;
}
f = PsiTreeUtil.getParentOfType(f, XPathVariableHolder.class, true);
}
}
final VariableContext context = getXPathContext().getVariableContext();
if (context == null) {
return null;
}
return context.resolve(this);
}
Aggregations