public XQueryVariableReferenceResolver(XQueryVarRef myElement) {
   this.myElement = myElement;
   checkedNamespacePrefix =
       myElement.getVarName().getVarNamespace() != null
           ? myElement.getVarName().getVarNamespace().getText()
           : null;
 }
 private void addVariableAsTargetIfMatches(
     XQueryVarDecl variableDeclaration, String checkedNamespace) {
   if (variableDeclarationWithValidName(variableDeclaration)) {
     XQueryQName<XQueryVarName> source =
         aXQueryQName(myElement.getVarName()).withPrefix(checkedNamespace).build();
     XQueryQName<XQueryVarName> checkedQName =
         aXQueryQName(variableDeclaration.getVarName()).build();
     if (source.equals(checkedQName)) {
       matchingVariableNames.add(checkedQName.getNamedObject());
     }
   }
 }
 @NotNull
 public ResolveResult[] getResolutionResults() {
   XQueryFile file = (XQueryFile) myElement.getContainingFile();
   matchingVariableNames = new ArrayList<XQueryVarName>();
   addReferencesFromLocalScopes();
   if (matchingVariableNames.size() > 0) {
     return convertToResolveResults(matchingVariableNames);
   }
   addVariableDeclarationReferencesFromFile(file, checkedNamespacePrefix);
   addVariableDeclarationReferencesFromImportedFiles(file);
   return convertToResolveResults(matchingVariableNames);
 }
 private boolean variableHasNamespacePrefix() {
   return myElement.getVarName().getVarNamespace() != null;
 }