mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use more conventional API
This commit is contained in:
+14
-20
@@ -46,13 +46,6 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl");
|
||||
private static final Object lock = new Object();
|
||||
private static final ReferenceQueue<SmartPointerEx> ourQueue = new ReferenceQueue<SmartPointerEx>();
|
||||
@SuppressWarnings("unused") private static final LowMemoryWatcher ourWatcher = LowMemoryWatcher.register(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
processQueue();
|
||||
}
|
||||
});
|
||||
|
||||
private final Project myProject;
|
||||
private final Key<Set<PointerReference>> POINTERS_KEY;
|
||||
private final Key<Boolean> POINTERS_ARE_FASTENED_KEY;
|
||||
@@ -61,18 +54,24 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
myProject = project;
|
||||
POINTERS_KEY = Key.create("SMART_POINTERS for "+project);
|
||||
POINTERS_ARE_FASTENED_KEY = Key.create("SMART_POINTERS_ARE_FASTENED for "+project);
|
||||
LowMemoryWatcher.register(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
processQueue();
|
||||
}
|
||||
}, project);
|
||||
}
|
||||
|
||||
private static void processQueue() {
|
||||
private void processQueue() {
|
||||
while (true) {
|
||||
PointerReference reference = (PointerReference)ourQueue.poll();
|
||||
if (reference == null) break;
|
||||
synchronized (lock) {
|
||||
Set<PointerReference> pointers = reference.file.getUserData(reference.key);
|
||||
Set<PointerReference> pointers = reference.file.getUserData(POINTERS_KEY);
|
||||
if (pointers != null) {
|
||||
pointers.remove(reference);
|
||||
if (pointers.isEmpty()) {
|
||||
reference.file.putUserData(reference.key, null);
|
||||
reference.file.putUserData(POINTERS_KEY, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +216,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
pointers = ContainerUtil.newTroveSet(); // we synchronise access anyway
|
||||
containingFile.putUserData(POINTERS_KEY, pointers);
|
||||
}
|
||||
pointers.add(new PointerReference(pointer, containingFile, ourQueue, POINTERS_KEY));
|
||||
pointers.add(new PointerReference(pointer, containingFile));
|
||||
|
||||
if (areBeltsFastened(containingFile)) {
|
||||
pointer.fastenBelt(0, null);
|
||||
@@ -295,7 +294,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
file.putUserData(POINTERS_ARE_FASTENED_KEY, null);
|
||||
return fastened;
|
||||
}
|
||||
private boolean areBeltsFastened(VirtualFile file) {
|
||||
private boolean areBeltsFastened(@NotNull VirtualFile file) {
|
||||
return file.getUserData(POINTERS_ARE_FASTENED_KEY) == Boolean.TRUE;
|
||||
}
|
||||
|
||||
@@ -305,17 +304,12 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
}
|
||||
|
||||
private static class PointerReference extends WeakReference<SmartPointerEx> {
|
||||
@NotNull
|
||||
private final VirtualFile file;
|
||||
private final Key<Set<PointerReference>> key;
|
||||
|
||||
public PointerReference(SmartPointerEx<?> pointer,
|
||||
VirtualFile containingFile,
|
||||
ReferenceQueue<SmartPointerEx> queue,
|
||||
Key<Set<PointerReference>> key) {
|
||||
super(pointer, queue);
|
||||
private PointerReference(@NotNull SmartPointerEx<?> pointer, @NotNull VirtualFile containingFile) {
|
||||
super(pointer, ourQueue);
|
||||
file = containingFile;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user