highlight unused LowMemoryWatcher.register call results

and create a less error-prone overload with parentDisposable
This commit is contained in:
peter
2014-08-21 10:42:33 +02:00
parent f1d4ca661a
commit 786a88f583
6 changed files with 48 additions and 39 deletions
@@ -49,21 +49,20 @@ import java.util.concurrent.ConcurrentMap;
public abstract class BaseExternalAnnotationsManager extends ExternalAnnotationsManager {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.BaseExternalAnnotationsManager");
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@NotNull private static final List<PsiFile> NULL_LIST = new ArrayList<PsiFile>(0);
@NotNull
private final ConcurrentMap<VirtualFile, List<PsiFile>> myExternalAnnotations = new ConcurrentSoftValueHashMap<VirtualFile, List<PsiFile>>(10, 0.75f, 2);
protected final PsiManager myPsiManager;
@SuppressWarnings("UnusedDeclaration")
private final LowMemoryWatcher myLowMemoryWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
dropCache();
}
});
public BaseExternalAnnotationsManager(final PsiManager psiManager) {
myPsiManager = psiManager;
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
dropCache();
}
}, psiManager.getProject());
}
@Nullable
@@ -71,13 +71,6 @@ public class FileManagerImpl implements FileManager {
private final FileDocumentManager myFileDocumentManager;
private final MessageBusConnection myConnection;
@SuppressWarnings("UnusedDeclaration")
private final LowMemoryWatcher myLowMemoryWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
processQueue();
}
});
public FileManagerImpl(PsiManagerImpl manager, FileDocumentManager fileDocumentManager, FileIndexFacade fileIndex) {
myManager = manager;
@@ -98,6 +91,12 @@ public class FileManagerImpl implements FileManager {
}
});
Disposer.register(manager.getProject(), this);
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
processQueue();
}
}, this);
}
private static final VirtualFile NULL = new LightVirtualFile();
@@ -17,8 +17,6 @@ package com.intellij.semantic;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerAdapter;
import com.intellij.openapi.util.LowMemoryWatcher;
import com.intellij.openapi.util.RecursionGuard;
import com.intellij.openapi.util.RecursionManager;
@@ -83,7 +81,7 @@ public class SemServiceImpl extends SemService{
});
final LowMemoryWatcher watcher = LowMemoryWatcher.register(new Runnable() {
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
if (myCreatingSem.get() == 0) {
@@ -91,13 +89,7 @@ public class SemServiceImpl extends SemService{
}
//System.out.println("SemService cache flushed");
}
});
ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerAdapter() {
@Override
public void projectClosing(Project project) {
watcher.stop();
}
});
}, project);
}
private static MultiMap<SemKey, SemKey> cacheKeyHierarchy(Collection<SemKey> allKeys) {
@@ -67,15 +67,16 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone
private final Object myInputLock = new Object();
private final AtomicBoolean myShutDown = new AtomicBoolean(false);
@SuppressWarnings("FieldCanBeLocal")
private final LowMemoryWatcher myWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
clearIdCache();
}
});
public PersistentFSImpl(@NotNull MessageBus bus) {
myEventBus = bus;
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
clearIdCache();
}
});
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
@Override
public void run() {
@@ -71,14 +71,6 @@ public class RootIndex {
private final TObjectIntHashMap<JpsModuleSourceRootType<?>> myRootTypeId = new TObjectIntHashMap<JpsModuleSourceRootType<?>>();
@NotNull private final Project myProject;
private volatile Map<VirtualFile, OrderEntry[]> myOrderEntries;
@SuppressWarnings("UnusedDeclaration")
private final LowMemoryWatcher myLowMemoryWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
myNonExistentPackages.clear();
}
});
// made public for Upsource
public RootIndex(@NotNull Project project, @NotNull InfoCache cache) {
@@ -98,6 +90,12 @@ public class RootIndex {
myProjectExcludedRoots.add(root);
}
}
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
myNonExistentPackages.clear();
}
}, project);
}
@NotNull
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.util;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.WeakList;
@@ -93,10 +94,29 @@ public class LowMemoryWatcher {
}, null, null);
}
/**
* Registers a runnable to run on low memory events
* @return a LowMemoryWatcher instance holding the runnable. This instance should be kept in memory while the
* low memory notification functionality is needed. As soon as it's garbage-collected, the runnable won't receive any further notifications.
*/
public static LowMemoryWatcher register(Runnable runnable) {
return new LowMemoryWatcher(runnable);
}
/**
* Registers a runnable to run on low memory events. The notifications will be issued until parentDisposable is disposed.
*/
public static void register(Runnable runnable, Disposable parentDisposable) {
final Ref<LowMemoryWatcher> watcher = Ref.create(new LowMemoryWatcher(runnable));
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
watcher.get().stop();
watcher.set(null);
}
});
}
private LowMemoryWatcher(Runnable runnable) {
myRunnable = runnable;
ourInstances.add(this);