RefCountHolder () { assert ready; boolean changed = false; MultiMap<PsiElement, PsiReference> newLocalRefsMap = MultiMap.createConcurrentSet(); for (Map.Entry<PsiElement, Collection<PsiReference>> entry : myLocalRefsMap.entrySet()) { PsiElement element = entry.getKey(); for (PsiReference ref : entry.getValue()) { if (ref.getElement().isValid()) { newLocalRefsMap.putValue(element, ref); } else { changed = true; } } } Set<PsiAnchor> newDclsUsedMap = ConcurrentCollectionFactory.createConcurrentSet(); for (PsiAnchor element : myDclsUsedMap) { if (element.retrieve() != null) { newDclsUsedMap.add(element); } else { changed = true; } } Map<PsiReference, PsiImportStatementBase> newImportStatements = ConcurrentCollectionFactory.createConcurrentMap(); for (Map.Entry<PsiReference, PsiImportStatementBase> entry : myImportStatements.entrySet()) { PsiReference key = entry.getKey(); PsiImportStatementBase value = entry.getValue(); if (value.isValid() && key.getElement().isValid()) { newImportStatements.put(key, value); } else { changed = true; } } return changed ? new RefCountHolder(myFile, newLocalRefsMap, newDclsUsedMap, newImportStatements) : this; }