예제 #1
0
 private static RefCountHolder getInstance(
     @NotNull PsiFile file, @NotNull ProgressIndicator indicator, boolean acquire) {
   HolderReference ref = file.getUserData(REF_COUNT_HOLDER_IN_FILE_KEY);
   RefCountHolder holder = com.intellij.reference.SoftReference.dereference(ref);
   if (holder == null && acquire) {
     holder = new RefCountHolder(file);
     HolderReference newRef = new HolderReference(holder);
     while (true) {
       boolean replaced =
           ((UserDataHolderEx) file).replace(REF_COUNT_HOLDER_IN_FILE_KEY, ref, newRef);
       if (replaced) {
         ref = newRef;
         break;
       }
       ref = file.getUserData(REF_COUNT_HOLDER_IN_FILE_KEY);
       RefCountHolder newHolder = com.intellij.reference.SoftReference.dereference(ref);
       if (newHolder != null) {
         holder = newHolder;
         break;
       }
     }
   }
   if (ref != null) {
     if (acquire) {
       ref.acquire(indicator);
     } else {
       ref.release(indicator);
     }
   }
   return holder;
 }