Java 类com.intellij.util.containers.WeakList 实例源码

项目:intellij-ce-playground    文件:AbstractProgressIndicatorExBase.java   
@Override
public void finish(@NotNull final TaskInfo task) {
  WeakList<TaskInfo> finished = myFinished;
  if (finished == null) {
    synchronized (this) {
      finished = myFinished;
      if (finished == null) {
        myFinished = finished = new WeakList<TaskInfo>();
      }
    }
  }
  if (!finished.addIfAbsent(task)) return;

  delegateRunningChange(new IndicatorAction() {
    @Override
    public void execute(@NotNull final ProgressIndicatorEx each) {
      each.finish(task);
    }
  });
}
项目:tools-idea    文件:LazyRangeMarkerFactory.java   
public LazyRangeMarkerFactory(@NotNull Project project, @NotNull final FileDocumentManager fileDocumentManager) {
  super(project);
  EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {
    @Override
    public void beforeDocumentChange(DocumentEvent e) {
      VirtualFile docFile = fileDocumentManager.getFile(e.getDocument());
      if (docFile == null) return;
      WeakList<LazyMarker> lazyMarkers = myMarkers.get(docFile);
      if (lazyMarkers == null) return;

      List<LazyMarker> markers = lazyMarkers.toStrongList();
      List<LazyMarker> markersToRemove = new ArrayList<LazyMarker>();
      for (final LazyMarker marker : markers) {
        if (Comparing.equal(marker.getFile(), docFile)) {
          marker.getOrCreateDelegate();
          markersToRemove.add(marker);
        }
      }
      lazyMarkers.removeAll(markersToRemove);
    }
  }, project);
}
项目:tools-idea    文件:ProgressIndicatorBase.java   
@Override
public void finish(@NotNull final TaskInfo task) {
  WeakList<TaskInfo> finished = myFinished;
  if (finished == null) {
    synchronized (this) {
      finished = myFinished;
      if (finished == null) {
        myFinished = finished = new WeakList<TaskInfo>();
      }
    }
  }
  if (!finished.addIfAbsent(task)) return;

  delegateRunningChange(new IndicatorAction() {
    @Override
    public void execute(@NotNull final ProgressIndicatorEx each) {
      each.finish(task);
    }
  });
}
项目:intellij-ce-playground    文件:UndoRedoStacksHolder.java   
private <T extends UserDataHolder> LinkedList<UndoableGroup> addWeaklyTrackedEmptyStack(T holder, WeakList<T> allHolders) {
  LinkedList<UndoableGroup> result;
  result = holder.getUserData(STACK_IN_DOCUMENT_KEY);
  if (result == null) {
    holder.putUserData(STACK_IN_DOCUMENT_KEY, result = new LinkedList<UndoableGroup>());
    allHolders.add(holder);
  }
  return result;
}
项目:intellij-ce-playground    文件:UndoRedoStacksHolder.java   
private <T extends UserDataHolder> void cleanWeaklyTrackedEmptyStacks(WeakList<T> stackHolders) {
  Set<T> holdersToDrop = new THashSet<T>();
  for (T holder : stackHolders) {
    LinkedList<UndoableGroup> stack = holder.getUserData(STACK_IN_DOCUMENT_KEY);
    if (stack != null && stack.isEmpty()) {
      holder.putUserData(STACK_IN_DOCUMENT_KEY, null);
      holdersToDrop.add(holder);
    }
  }
  stackHolders.removeAll(holdersToDrop);
}
项目:intellij-ce-playground    文件:LazyRangeMarkerFactoryImpl.java   
private static void addToLazyMarkersList(@NotNull LazyMarker marker, @NotNull VirtualFile file) {
  WeakList<LazyMarker> markers = getMarkers(file);

  if (markers == null) {
    markers = file.putUserDataIfAbsent(LAZY_MARKERS_KEY, new WeakList<LazyMarker>());
  }
  markers.add(marker);
}
项目:intellij-ce-playground    文件:LazyRangeMarkerFactoryImpl.java   
private static void removeFromLazyMarkersList(@NotNull LazyMarker marker, @NotNull VirtualFile file) {
  WeakList<LazyMarker> markers = getMarkers(file);

  if (markers != null) {
    markers.remove(marker);
  }
}
项目:intellij-ce-playground    文件:RangeMarkerTest.java   
public void testLazyRangeMarkers() {
  psiFile = createFile("x.txt", "xxx");

  LazyRangeMarkerFactoryImpl factory = (LazyRangeMarkerFactoryImpl)LazyRangeMarkerFactory.getInstance(getProject());
  VirtualFile virtualFile = psiFile.getVirtualFile();
  LazyRangeMarkerFactoryImpl.LazyMarker marker = (LazyRangeMarkerFactoryImpl.LazyMarker)factory.createRangeMarker(virtualFile, 0);
  WeakList<LazyRangeMarkerFactoryImpl.LazyMarker> markers = LazyRangeMarkerFactoryImpl.getMarkers(virtualFile);
  assertSame(marker, assertOneElement(markers));

  assertFalse(marker.isDelegated());
  assertTrue(marker.isValid());
  assertEquals(0, marker.getStartOffset());
  assertFalse(marker.isDelegated());

  marker.dispose();
  assertFalse(marker.isValid());
  assertEmpty(LazyRangeMarkerFactoryImpl.getMarkers(virtualFile));


  marker = (LazyRangeMarkerFactoryImpl.LazyMarker)factory.createRangeMarker(virtualFile, 0);
  assertFalse(marker.isDelegated());
  assertTrue(marker.isValid());
  assertEquals(0, marker.getStartOffset());
  assertFalse(marker.isDelegated());

  Document document = marker.getDocument();
  document.insertString(2, "yyy");
  assertTrue(marker.isDelegated());
  assertTrue(marker.isValid());
  assertEquals(0, marker.getStartOffset());

  assertEmpty(LazyRangeMarkerFactoryImpl.getMarkers(virtualFile));
  marker.dispose();
  assertEmpty(LazyRangeMarkerFactoryImpl.getMarkers(virtualFile));
}
项目:tools-idea    文件:LazyRangeMarkerFactory.java   
private void addToLazyMarkersList(@NotNull LazyMarker marker, @NotNull VirtualFile file) {
  WeakList<LazyMarker> markers = myMarkers.get(file);
  if (markers == null) {
    markers = ConcurrencyUtil.cacheOrGet(myMarkers, file, new WeakList<LazyMarker>());
  }
  markers.add(marker);
}
项目:tools-idea    文件:StackingPopupDispatcherImpl.java   
public void hidePersistentPopups() {
  final WeakList<JBPopup> list = myPersistentPopups;
  for (JBPopup each : list) {
    if (each.isNativePopup()) {
      each.setUiVisible(false);
    }
  }
}
项目:tools-idea    文件:StackingPopupDispatcherImpl.java   
public void restorePersistentPopups() {
  final WeakList<JBPopup> list = myPersistentPopups;
  for (JBPopup each : list) {
    if (each.isNativePopup()) {
      each.setUiVisible(true);
    }
  }
}
项目:consulo    文件:AbstractProgressIndicatorExBase.java   
@Override
public void finish(@Nonnull final TaskInfo task) {
  WeakList<TaskInfo> finished = myFinished;
  if (finished == null) {
    synchronized (this) {
      finished = myFinished;
      if (finished == null) {
        myFinished = finished = new WeakList<>();
      }
    }
  }
  if (!finished.addIfAbsent(task)) return;

  delegateRunningChange(each -> each.finish(task));
}
项目:consulo    文件:LazyRangeMarkerFactoryImpl.java   
private static void addToLazyMarkersList(@Nonnull LazyMarker marker, @Nonnull VirtualFile file) {
  WeakList<LazyMarker> markers = getMarkers(file);

  if (markers == null) {
    markers = file.putUserDataIfAbsent(LAZY_MARKERS_KEY, new WeakList<>());
  }
  markers.add(marker);
}
项目:consulo    文件:LazyRangeMarkerFactoryImpl.java   
private static void removeFromLazyMarkersList(@Nonnull LazyMarker marker, @Nonnull VirtualFile file) {
  WeakList<LazyMarker> markers = getMarkers(file);

  if (markers != null) {
    markers.remove(marker);
  }
}
项目:intellij-ce-playground    文件:LazyRangeMarkerFactoryImpl.java   
static WeakList<LazyMarker> getMarkers(@NotNull VirtualFile file) {
  return file.getUserData(LazyRangeMarkerFactoryImpl.LAZY_MARKERS_KEY);
}
项目:tools-idea    文件:ProgressIndicatorBase.java   
@Override
public boolean isFinished(@NotNull final TaskInfo task) {
  WeakList<TaskInfo> list = myFinished;
  return list != null && list.contains(task);
}
项目:consulo    文件:LazyRangeMarkerFactoryImpl.java   
static WeakList<LazyMarker> getMarkers(@Nonnull VirtualFile file) {
  return file.getUserData(LazyRangeMarkerFactoryImpl.LAZY_MARKERS_KEY);
}