@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); } }); }
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); }
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; }
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); }
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); }
private static void removeFromLazyMarkersList(@NotNull LazyMarker marker, @NotNull VirtualFile file) { WeakList<LazyMarker> markers = getMarkers(file); if (markers != null) { markers.remove(marker); } }
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)); }
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); }
public void hidePersistentPopups() { final WeakList<JBPopup> list = myPersistentPopups; for (JBPopup each : list) { if (each.isNativePopup()) { each.setUiVisible(false); } } }
public void restorePersistentPopups() { final WeakList<JBPopup> list = myPersistentPopups; for (JBPopup each : list) { if (each.isNativePopup()) { each.setUiVisible(true); } } }
@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)); }
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); }
private static void removeFromLazyMarkersList(@Nonnull LazyMarker marker, @Nonnull VirtualFile file) { WeakList<LazyMarker> markers = getMarkers(file); if (markers != null) { markers.remove(marker); } }
static WeakList<LazyMarker> getMarkers(@NotNull VirtualFile file) { return file.getUserData(LazyRangeMarkerFactoryImpl.LAZY_MARKERS_KEY); }
@Override public boolean isFinished(@NotNull final TaskInfo task) { WeakList<TaskInfo> list = myFinished; return list != null && list.contains(task); }
static WeakList<LazyMarker> getMarkers(@Nonnull VirtualFile file) { return file.getUserData(LazyRangeMarkerFactoryImpl.LAZY_MARKERS_KEY); }