From e4d785b33b7aee24635316e90f856d5295026e09 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Wed, 2 Oct 2019 08:00:37 +0300 Subject: [PATCH] cleanup: extract method GitOrigin-RevId: 563a06992f18dd26575efa96bbd52faa881ec245 --- .../com/intellij/psi/stubs/StubIndexImpl.java | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java index 1130d5453a82..2d679ae41bc2 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java @@ -66,12 +66,8 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom } private final Map, CachedValue>> myCachedStubIds = FactoryMap.createMap(k -> { - UpdatableIndex index = - ((FileBasedIndexImpl)FileBasedIndex.getInstance()).getIndex(StubUpdatingIndex.INDEX_ID); - ModificationTracker tracker = () -> { - - return index.getModificationStamp(); - }; + UpdatableIndex index = getStubUpdatingIndex(); + ModificationTracker tracker = index::getModificationStamp; return new CachedValueImpl<>(() -> new CachedValueProvider.Result<>(ContainerUtil.newConcurrentMap(), tracker)); }, ContainerUtil::newConcurrentMap); @@ -195,9 +191,7 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom } else { registrationResultSink.registerIndexAsUptoDate(indexKey); } - FileBasedIndexImpl fileBasedIndexManager = (FileBasedIndexImpl)FileBasedIndex.getInstance(); - UpdatableIndex stubUpdatingIndex = - fileBasedIndexManager.getIndex(StubUpdatingIndex.INDEX_ID); + UpdatableIndex stubUpdatingIndex = getStubUpdatingIndex(); ReadWriteLock lock = stubUpdatingIndex.getLock(); for (int attempt = 0; attempt < 2; attempt++) { @@ -375,30 +369,6 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom in.skipBytes(bufferSize); } - private static class CompositeKey { - private final K key; - private final int fileId; - - private CompositeKey(K key, int id) { - this.key = key; - fileId = id; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CompositeKey key1 = (CompositeKey)o; - return fileId == key1.fileId && - Objects.equals(key, key1.key); - } - - @Override - public int hashCode() { - return Objects.hash(key, fileId); - } - } - @Override public boolean processElements(@NotNull final StubIndexKey indexKey, @NotNull final Key key, @@ -408,8 +378,7 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom @NotNull final Class requiredClass, @NotNull final Processor processor) { IdIterator ids = getContainingIds(indexKey, key, project, idFilter, scope); - final FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance(); - UpdatableIndex stubUpdatingIndex = fileBasedIndex.getIndex(StubUpdatingIndex.INDEX_ID); + UpdatableIndex stubUpdatingIndex = getStubUpdatingIndex(); if (stubUpdatingIndex == null) return true; PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); // already ensured up-to-date in getContainingIds() method @@ -648,8 +617,7 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom } void cleanupMemoryStorage() { - UpdatableIndex stubUpdatingIndex = - ((FileBasedIndexImpl)FileBasedIndex.getInstance()).getIndex(StubUpdatingIndex.INDEX_ID); + UpdatableIndex stubUpdatingIndex = getStubUpdatingIndex(); stubUpdatingIndex.getWriteLock().lock(); try { @@ -782,4 +750,31 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom return state; } } + + private static UpdatableIndex getStubUpdatingIndex() { + return ((FileBasedIndexImpl)FileBasedIndex.getInstance()).getIndex(StubUpdatingIndex.INDEX_ID); + } + + private static class CompositeKey { + private final K key; + private final int fileId; + + private CompositeKey(K key, int id) { + this.key = key; + fileId = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CompositeKey key1 = (CompositeKey)o; + return fileId == key1.fileId && Objects.equals(key, key1.key); + } + + @Override + public int hashCode() { + return Objects.hash(key, fileId); + } + } }