/** @param globalScope a new Global Scope to replace the scope of references with. */
 public void updateReferencesWithGlobalScope(Scope globalScope) {
   for (ReferenceCollection collection : refMap.values()) {
     List<Reference> newRefs = new ArrayList<>(collection.references.size());
     for (Reference ref : collection.references) {
       if (ref.getScope() != globalScope) {
         newRefs.add(ref.cloneWithNewScope(globalScope));
       } else {
         newRefs.add(ref);
       }
     }
     collection.references = newRefs;
   }
 }