diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index b8326d3e5a84..b2a2c5334c80 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -52,10 +52,11 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi private static final DataExternalizer KEY_EXTERNALIZER = new DataExternalizer() { @Override - public void save(final DataOutput out, final SerializedStubTree v) throws IOException { + public void save(final DataOutput out, @NotNull final SerializedStubTree v) throws IOException { v.write(out); } + @NotNull @Override public SerializedStubTree read(final DataInput in) throws IOException { return new SerializedStubTree(in); @@ -64,12 +65,12 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi private static final FileBasedIndex.InputFilter INPUT_FILTER = new FileBasedIndex.InputFilter() { @Override - public boolean acceptInput(final VirtualFile file) { + public boolean acceptInput(@NotNull final VirtualFile file) { return canHaveStub(file); } }; - public static boolean canHaveStub(VirtualFile file) { + public static boolean canHaveStub(@NotNull VirtualFile file) { final FileType fileType = file.getFileType(); if (fileType instanceof LanguageFileType) { Language l = ((LanguageFileType)fileType).getLanguage(); @@ -90,6 +91,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi private static final KeyDescriptor DATA_DESCRIPTOR = new IntInlineKeyDescriptor(); + @NotNull @Override public ID getName() { return INDEX_ID; @@ -100,12 +102,13 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi return 5; // no need to cache many serialized trees } + @NotNull @Override public DataIndexer getIndexer() { return new DataIndexer() { @Override @NotNull - public Map map(final FileContent inputData) { + public Map map(@NotNull final FileContent inputData) { final Map result = new HashMap(); ApplicationManager.getApplication().runReadAction(new Runnable() { @@ -127,16 +130,19 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi }; } + @NotNull @Override public KeyDescriptor getKeyDescriptor() { return DATA_DESCRIPTOR; } + @NotNull @Override public DataExternalizer getValueExternalizer() { return KEY_EXTERNALIZER; } + @NotNull @Override public FileBasedIndex.InputFilter getInputFilter() { return INPUT_FILTER; @@ -175,8 +181,9 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi return version; } + @NotNull @Override - public UpdatableIndex createIndexImplementation(final ID indexId, final FileBasedIndex owner, IndexStorage storage) { + public UpdatableIndex createIndexImplementation(final ID indexId, @NotNull final FileBasedIndex owner, @NotNull IndexStorage storage) { if (storage instanceof MemoryIndexStorage) { final MemoryIndexStorage memStorage = (MemoryIndexStorage)storage; memStorage.addBufferingStateListsner(new MemoryIndexStorage.BufferingStateListener() { @@ -194,7 +201,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi return new MyIndex(indexId, storage, getIndexer()); } - private static void updateStubIndices(final Collection indexKeys, final int inputId, final Map> oldStubTree, final Map> newStubTree) { + private static void updateStubIndices(@NotNull final Collection indexKeys, final int inputId, @NotNull final Map> oldStubTree, @NotNull final Map> newStubTree) { final StubIndexImpl stubIndex = (StubIndexImpl)StubIndex.getInstance(); for (StubIndexKey key : indexKeys) { final Map oldMap = oldStubTree.get(key); @@ -207,7 +214,8 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi } } - private static Collection getAffectedIndices(final Map> oldStubTree, final Map> newStubTree) { + @NotNull + private static Collection getAffectedIndices(@NotNull final Map> oldStubTree, @NotNull final Map> newStubTree) { Set allIndices = new HashSet(); allIndices.addAll(oldStubTree.keySet()); allIndices.addAll(newStubTree.keySet()); @@ -242,7 +250,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi } @Override - protected void updateWithMap(final int inputId, final Map newData, Callable> oldKeysGetter) + protected void updateWithMap(final int inputId, @NotNull final Map newData, @NotNull Callable> oldKeysGetter) throws StorageException { checkNameStorage(); @@ -294,7 +302,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi } } - private static Map> getStubTree(final Map data) { + private static Map> getStubTree(@NotNull final Map data) { final Map> stubTree; if (!data.isEmpty()) { final SerializedStubTree stub = data.values().iterator().next(); @@ -307,6 +315,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi } /*MUST be called under the WriteLock*/ + @NotNull private Map readOldData(final int key) throws StorageException { final Map result = new HashMap(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 36d62b756f4a..0ccea453bf84 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -99,7 +99,7 @@ public class FileBasedIndex implements ApplicationComponent { private final Set myNoLimitCheckTypes = new THashSet(); private final PerIndexDocumentVersionMap myLastIndexedDocStamps = new PerIndexDocumentVersionMap(); - private final ChangedFilesCollector myChangedFilesCollector; + @NotNull private final ChangedFilesCollector myChangedFilesCollector; private final List myIndexableSets = ContainerUtil.createEmptyCOWList(); private final Map myIndexableSetToProjectMap = new THashMap(); @@ -119,15 +119,15 @@ public class FileBasedIndex implements ApplicationComponent { @Nullable private final String myConfigPath; @Nullable private final String mySystemPath; private final boolean myIsUnitTestMode; - private ScheduledFuture myFlushingFuture; + @Nullable private ScheduledFuture myFlushingFuture; private volatile int myLocalModCount; private volatile int myFilesModCount; - public void requestReindex(final VirtualFile file) { + public void requestReindex(@NotNull final VirtualFile file) { myChangedFilesCollector.invalidateIndices(file, true); } - public void requestReindexExcluded(final VirtualFile file) { + public void requestReindexExcluded(@NotNull final VirtualFile file) { myChangedFilesCollector.invalidateIndices(file, false); } @@ -136,7 +136,7 @@ public class FileBasedIndex implements ApplicationComponent { } public FileBasedIndex(final VirtualFileManagerEx vfManager, FileDocumentManager fdm, - FileTypeManager fileTypeManager, MessageBus bus, SerializationManager sm /*need this parameter to ensure component dependency*/) throws IOException { + FileTypeManager fileTypeManager, @NotNull MessageBus bus, SerializationManager sm /*need this parameter to ensure component dependency*/) throws IOException { myVfManager = vfManager; myFileDocumentManager = fdm; myFileTypeManager = fileTypeManager; @@ -165,7 +165,7 @@ public class FileBasedIndex implements ApplicationComponent { }); connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { - private Map> myTypeToExtensionMap; + @Nullable private Map> myTypeToExtensionMap; @Override public void beforeFileTypesChanged(final FileTypeEvent event) { cleanupProcessedFlag(); @@ -201,7 +201,8 @@ public class FileBasedIndex implements ApplicationComponent { } } - private Set getExtensions(FileType type) { + @NotNull + private Set getExtensions(@NotNull FileType type) { final Set set = new THashSet(); for (FileNameMatcher matcher : myFileTypeManager.getAssociations(type)) { set.add(matcher.getPresentableString()); @@ -224,7 +225,7 @@ public class FileBasedIndex implements ApplicationComponent { connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { @Override - public void before(List events) { + public void before(@NotNull List events) { for (VFileEvent event : events) { final Object requestor = event.getRequestor(); if (requestor instanceof FileDocumentManager || requestor instanceof PsiManager || requestor == LocalHistory.VFS_EVENT_REQUESTOR) { @@ -235,7 +236,7 @@ public class FileBasedIndex implements ApplicationComponent { } @Override - public void after(List events) { + public void after(@NotNull List events) { } }); @@ -342,6 +343,7 @@ public class FileBasedIndex implements ApplicationComponent { public void initComponent() { } + @Nullable private static String calcConfigPath(final String path) { try { final String _path = FileUtil.toSystemIndependentName(new File(path).getCanonicalPath()); @@ -367,7 +369,7 @@ public class FileBasedIndex implements ApplicationComponent { * @param extension * @param isCurrentVersionCorrupted */ - private boolean registerIndexer(final FileBasedIndexExtension extension, final boolean isCurrentVersionCorrupted) throws IOException { + private boolean registerIndexer(@NotNull final FileBasedIndexExtension extension, final boolean isCurrentVersionCorrupted) throws IOException { final ID name = extension.getName(); final int version = extension.getVersion(); final File versionFile = IndexInfrastructure.getVersionFile(name); @@ -376,7 +378,7 @@ public class FileBasedIndex implements ApplicationComponent { if (isCurrentVersionCorrupted || IndexInfrastructure.versionDiffers(versionFile, version)) { if (!isCurrentVersionCorrupted && versionFileExisted) { versionChanged = true; - LOG.info("Version has changed for index " + extension.getName() + ". The index will be rebuilt."); + LOG.info("Version has changed for index " + name + ". The index will be rebuilt."); } FileUtil.delete(IndexInfrastructure.getIndexRootDir(name)); IndexInfrastructure.rewriteVersion(versionFile, version); @@ -412,7 +414,7 @@ public class FileBasedIndex implements ApplicationComponent { return versionChanged; } - private static void saveRegisteredIndices(Collection> ids) { + private static void saveRegisteredIndices(@NotNull Collection> ids) { final File file = getRegisteredIndicesFile(); try { FileUtil.createIfDoesntExist(file); @@ -431,6 +433,7 @@ public class FileBasedIndex implements ApplicationComponent { } } + @NotNull private static Set readRegisteredIndexNames() { final Set result = new THashSet(); try { @@ -450,11 +453,13 @@ public class FileBasedIndex implements ApplicationComponent { return result; } + @NotNull private static File getRegisteredIndicesFile() { return new File(PathManager.getIndexRoot(), "registered"); } - private UpdatableIndex createIndex(final ID indexId, final FileBasedIndexExtension extension, final MemoryIndexStorage storage) throws IOException { + @NotNull + private UpdatableIndex createIndex(@NotNull final ID indexId, @NotNull final FileBasedIndexExtension extension, @NotNull final MemoryIndexStorage storage) throws IOException { final MapReduceIndex index; if (extension instanceof CustomImplementationFileBasedIndexExtension) { final UpdatableIndex custom = ((CustomImplementationFileBasedIndexExtension)extension).createIndexImplementation(indexId, this, storage); @@ -486,16 +491,17 @@ public class FileBasedIndex implements ApplicationComponent { return index; } - private static PersistentHashMap> createIdToDataKeysIndex(final ID indexId, - final KeyDescriptor keyDescriptor, - MemoryIndexStorage storage) throws IOException { + @NotNull + private static PersistentHashMap> createIdToDataKeysIndex(@NotNull final ID indexId, + @NotNull final KeyDescriptor keyDescriptor, + @NotNull MemoryIndexStorage storage) throws IOException { final File indexStorageFile = IndexInfrastructure.getInputIndexStorageFile(indexId); final Ref isBufferingMode = new Ref(false); final TIntObjectHashMap> tempMap = new TIntObjectHashMap>(); final DataExternalizer> dataExternalizer = new DataExternalizer>() { @Override - public void save(DataOutput out, Collection value) throws IOException { + public void save(DataOutput out, @NotNull Collection value) throws IOException { try { DataInputOutputUtil.writeINT(out, value.size()); for (K key : value) { @@ -507,6 +513,7 @@ public class FileBasedIndex implements ApplicationComponent { } } + @NotNull @Override public Collection read(DataInput in) throws IOException { try { @@ -545,7 +552,7 @@ public class FileBasedIndex implements ApplicationComponent { } @Override - protected void doPut(Integer integer, Collection ks) throws IOException { + protected void doPut(Integer integer, @Nullable Collection ks) throws IOException { if (isBufferingMode.get()) { tempMap.put(integer, ks == null? Collections.emptySet() : ks); } @@ -664,7 +671,7 @@ public class FileBasedIndex implements ApplicationComponent { * Keys obtained from the files which do not belong to the project specified may not be up-to-date or even exist */ @NotNull - public Collection getAllKeys(final ID indexId, @NotNull Project project) { + public Collection getAllKeys(@NotNull final ID indexId, @NotNull Project project) { Set allKeys = new THashSet(); processAllKeys(indexId, new CommonProcessors.CollectProcessor(allKeys), project); return allKeys; @@ -674,7 +681,7 @@ public class FileBasedIndex implements ApplicationComponent { * @param project it is guaranteed to return data which is up-to-date withing the project * Keys obtained from the files which do not belong to the project specified may not be up-to-date or even exist */ - public boolean processAllKeys(final ID indexId, Processor processor, @Nullable Project project) { + public boolean processAllKeys(@NotNull final ID indexId, Processor processor, @Nullable Project project) { try { final UpdatableIndex index = getIndex(indexId); if (index == null) { @@ -736,11 +743,11 @@ public class FileBasedIndex implements ApplicationComponent { * DO NOT CALL DIRECTLY IN CLIENT CODE * The method is internal to indexing engine end is called internally. The method is public due to implementation details */ - public void ensureUpToDate(final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter) { + public void ensureUpToDate(@NotNull final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter) { ensureUpToDate(indexId, project, filter, null); } - private void ensureUpToDate(final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter, + private void ensureUpToDate(@NotNull final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter, @Nullable VirtualFile restrictedFile) { if (!needsFileContentLoading(indexId)) { return; //indexed eagerly in foreground while building unindexed file list @@ -813,7 +820,7 @@ public class FileBasedIndex implements ApplicationComponent { } @NotNull - public List getValues(final ID indexId, @NotNull K dataKey, @NotNull final GlobalSearchScope filter) { + public List getValues(@NotNull final ID indexId, @NotNull K dataKey, @NotNull final GlobalSearchScope filter) { final List values = new SmartList(); processValuesImpl(indexId, dataKey, true, null, new ValueProcessor() { @Override @@ -826,7 +833,7 @@ public class FileBasedIndex implements ApplicationComponent { } @NotNull - public Collection getContainingFiles(final ID indexId, @NotNull K dataKey, @NotNull final GlobalSearchScope filter) { + public Collection getContainingFiles(@NotNull final ID indexId, @NotNull K dataKey, @NotNull final GlobalSearchScope filter) { final Set files = new THashSet(); processValuesImpl(indexId, dataKey, false, null, new ValueProcessor() { @Override @@ -851,18 +858,19 @@ public class FileBasedIndex implements ApplicationComponent { /** * @return false if ValueProcessor.process() returned false; true otherwise or if ValueProcessor was not called at all */ - public boolean processValues(final ID indexId, @NotNull final K dataKey, @Nullable final VirtualFile inFile, - ValueProcessor processor, @NotNull final GlobalSearchScope filter) { + public boolean processValues(@NotNull final ID indexId, @NotNull final K dataKey, @Nullable final VirtualFile inFile, + @NotNull ValueProcessor processor, @NotNull final GlobalSearchScope filter) { return processValuesImpl(indexId, dataKey, false, inFile, processor, filter); } - private R processExceptions(final ID indexId, + @Nullable + private R processExceptions(@NotNull final ID indexId, @Nullable final VirtualFile restrictToFile, - final GlobalSearchScope filter, - ThrowableConvertor, R, StorageException> computable) { + @NotNull final GlobalSearchScope filter, + @NotNull ThrowableConvertor, R, StorageException> computable) { try { final UpdatableIndex index = getIndex(indexId); if (index == null) { @@ -895,12 +903,12 @@ public class FileBasedIndex implements ApplicationComponent { return null; } - private boolean processValuesImpl(final ID indexId, final K dataKey, final boolean ensureValueProcessedOnce, - @Nullable final VirtualFile restrictToFile, final ValueProcessor processor, - final GlobalSearchScope filter) { + private boolean processValuesImpl(@NotNull final ID indexId, final K dataKey, final boolean ensureValueProcessedOnce, + @Nullable final VirtualFile restrictToFile, @NotNull final ValueProcessor processor, + @NotNull final GlobalSearchScope filter) { ThrowableConvertor, Boolean, StorageException> keyProcessor = new ThrowableConvertor, Boolean, StorageException>() { @Override - public Boolean convert(UpdatableIndex index) throws StorageException { + public Boolean convert(@NotNull UpdatableIndex index) throws StorageException { final ValueContainer container = index.getData(dataKey); boolean shouldContinue = true; @@ -947,17 +955,14 @@ public class FileBasedIndex implements ApplicationComponent { return result == null || result.booleanValue(); } - public boolean processFilesContainingAllKeys(final ID indexId, - final Collection dataKeys, - final GlobalSearchScope filter, + public boolean processFilesContainingAllKeys(@NotNull final ID indexId, + @NotNull final Collection dataKeys, + @NotNull final GlobalSearchScope filter, @Nullable Condition valueChecker, - final Processor processor) { + @NotNull final Processor processor) { ProjectIndexableFilesFilter filesSet = projectIndexableFiles(filter.getProject()); final TIntHashSet set = collectFileIdsContainingAllKeys(indexId, dataKeys, filter, valueChecker, filesSet); - if (set == null) { - return false; - } - return processVirtualFiles(set, filter, processor); + return set != null && processVirtualFiles(set, filter, processor); } private static final Key> ourProjectFilesSetKey = Key.create("projectFiles"); @@ -966,7 +971,7 @@ public class FileBasedIndex implements ApplicationComponent { private static final int MAGIC = 0x278DDE6D; private final int myModificationCount; - private ProjectIndexableFilesFilter(TIntHashSet set, int modificationCount) { + private ProjectIndexableFilesFilter(@NotNull TIntHashSet set, int modificationCount) { super(set.size(), 0.005d); myModificationCount = modificationCount; set.forEach(new TIntProcedure() { @@ -983,7 +988,8 @@ public class FileBasedIndex implements ApplicationComponent { } } - public @Nullable ProjectIndexableFilesFilter projectIndexableFiles(Project project) { + @Nullable + public ProjectIndexableFilesFilter projectIndexableFiles(@Nullable Project project) { if (project == null) return null; SoftReference reference = project.getUserData(ourProjectFilesSetKey); @@ -993,7 +999,7 @@ public class FileBasedIndex implements ApplicationComponent { final TIntHashSet filesSet = new TIntHashSet(); iterateIndexableFiles(new ContentIterator() { @Override - public boolean processFile(VirtualFile fileOrDir) { + public boolean processFile(@NotNull VirtualFile fileOrDir) { filesSet.add(((VirtualFileWithId)fileOrDir).getId()); return true; } @@ -1004,17 +1010,16 @@ public class FileBasedIndex implements ApplicationComponent { } @Nullable - private TIntHashSet collectFileIdsContainingAllKeys(final ID indexId, - final Collection dataKeys, - final GlobalSearchScope filter, - @Nullable final Condition valueChecker, - @Nullable final ProjectIndexableFilesFilter projectFilesFilter - ) { + private TIntHashSet collectFileIdsContainingAllKeys(@NotNull final ID indexId, + @NotNull final Collection dataKeys, + @NotNull final GlobalSearchScope filter, + @Nullable final Condition valueChecker, + @Nullable final ProjectIndexableFilesFilter projectFilesFilter) { final ThrowableConvertor, TIntHashSet, StorageException> convertor = new ThrowableConvertor, TIntHashSet, StorageException>() { @Nullable @Override - public TIntHashSet convert(UpdatableIndex index) throws StorageException { + public TIntHashSet convert(@NotNull UpdatableIndex index) throws StorageException { TIntHashSet mainIntersection = null; for (K dataKey : dataKeys) { @@ -1065,7 +1070,9 @@ public class FileBasedIndex implements ApplicationComponent { return processExceptions(indexId, null, filter, convertor); } - private static boolean processVirtualFiles(TIntHashSet ids, final GlobalSearchScope filter, final Processor processor) { + private static boolean processVirtualFiles(@NotNull TIntHashSet ids, + @NotNull final GlobalSearchScope filter, + @NotNull final Processor processor) { final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); return ids.forEach(new TIntProcedure() { @Override @@ -1080,14 +1087,18 @@ public class FileBasedIndex implements ApplicationComponent { }); } - public static @Nullable Throwable getCauseToRebuildIndex(RuntimeException e) { + @Nullable + public static Throwable getCauseToRebuildIndex(@NotNull RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof StorageException || cause instanceof IOException || cause instanceof IllegalArgumentException) return cause; return null; } - public boolean getFilesWithKey(final ID indexId, final Set dataKeys, Processor processor, GlobalSearchScope filter) { + public boolean getFilesWithKey(@NotNull final ID indexId, + @NotNull final Set dataKeys, + @NotNull Processor processor, + @NotNull GlobalSearchScope filter) { try { final UpdatableIndex index = getIndex(indexId); if (index == null) { @@ -1159,7 +1170,8 @@ public class FileBasedIndex implements ApplicationComponent { return true; } - private static TIntHashSet join(List locals) { + @NotNull + private static TIntHashSet join(@NotNull List locals) { TIntHashSet result = locals.get(0); if (locals.size() > 1) { TIntIterator it = result.iterator(); @@ -1177,7 +1189,7 @@ public class FileBasedIndex implements ApplicationComponent { return result; } - public void scheduleRebuild(final ID indexId, final Throwable e) { + public void scheduleRebuild(@NotNull final ID indexId, @NotNull final Throwable e) { LOG.info(e); requestRebuild(indexId); try { @@ -1187,7 +1199,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void checkRebuild(final ID indexId, final boolean cleanupOnly) { + private void checkRebuild(@NotNull final ID indexId, final boolean cleanupOnly) { final AtomicInteger status = ourRebuildStatus.get(indexId); if (status.get() == OK) return; if (status.compareAndSet(REQUIRES_REBUILD, REBUILD_IN_PROGRESS)) { @@ -1249,7 +1261,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void clearIndex(final ID indexId) throws StorageException { + private void clearIndex(@NotNull final ID indexId) throws StorageException { final UpdatableIndex index = getIndex(indexId); assert index != null: "Index with key " + indexId + " not found or not registered properly"; index.clear(); @@ -1261,6 +1273,7 @@ public class FileBasedIndex implements ApplicationComponent { } } + @NotNull private Set getUnsavedOrTransactedDocuments() { final Set docs = new THashSet(Arrays.asList(myFileDocumentManager.getUnsavedDocuments())); synchronized (myTransactionMap) { @@ -1269,7 +1282,9 @@ public class FileBasedIndex implements ApplicationComponent { return docs; } - private void indexUnsavedDocuments(ID indexId, @Nullable Project project, GlobalSearchScope filter, + private void indexUnsavedDocuments(@NotNull ID indexId, + @Nullable Project project, + GlobalSearchScope filter, VirtualFile restrictedFile) throws StorageException { if (myUpToDateIndices.contains(indexId)) { return; // no need to index unsaved docs @@ -1366,7 +1381,7 @@ public class FileBasedIndex implements ApplicationComponent { // returns false if doc was not indexed because the file does not fit in scope private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID requestedIndexId, final Project project, - GlobalSearchScope filter, VirtualFile restrictedFile) throws StorageException { + @Nullable GlobalSearchScope filter, @Nullable VirtualFile restrictedFile) throws StorageException { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; @@ -1451,6 +1466,7 @@ public class FileBasedIndex implements ApplicationComponent { private final StorageGuard myStorageLock = new StorageGuard(); + @NotNull private StorageGuard.Holder setDataBufferingEnabled(final boolean enabled) { final StorageGuard.Holder holder = myStorageLock.enter(enabled); for (ID indexId : myIndices.keySet()) { @@ -1520,6 +1536,7 @@ public class FileBasedIndex implements ApplicationComponent { return myChangedFilesCollector.getNumberOfPendingInvalidations(); } + @NotNull public Collection getFilesToUpdate(final Project project) { return ContainerUtil.findAll(myChangedFilesCollector.getAllFilesToUpdate(), new Condition() { @Override @@ -1538,12 +1555,12 @@ public class FileBasedIndex implements ApplicationComponent { }); } - public void processRefreshedFile(@NotNull Project project, final com.intellij.ide.caches.FileContent fileContent) { + public void processRefreshedFile(@NotNull Project project, @NotNull final com.intellij.ide.caches.FileContent fileContent) { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); myChangedFilesCollector.processFileImpl(project, fileContent, false); } - public void indexFileContent(@Nullable Project project, com.intellij.ide.caches.FileContent content) { + public void indexFileContent(@Nullable Project project, @NotNull com.intellij.ide.caches.FileContent content) { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); final VirtualFile file = content.getVirtualFile(); FileContentImpl fc = null; @@ -1593,7 +1610,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void updateSingleIndex(final ID indexId, final VirtualFile file, final FileContent currentFC) + private void updateSingleIndex(final ID indexId, @NotNull final VirtualFile file, @Nullable final FileContent currentFC) throws StorageException { if (ourRebuildStatus.get(indexId).get() == REQUIRES_REBUILD) { return; // the index is scheduled for rebuild, no need to update @@ -1644,7 +1661,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - public static int getFileId(final VirtualFile file) { + public static int getFileId(@NotNull final VirtualFile file) { if (file instanceof VirtualFileWithId) { return ((VirtualFileWithId)file).getId(); } @@ -1676,37 +1693,37 @@ public class FileBasedIndex implements ApplicationComponent { // No need to react on movement events since files stay valid, their ids don't change and all associated attributes remain intact. @Override - public void fileCreated(final VirtualFileEvent event) { + public void fileCreated(@NotNull final VirtualFileEvent event) { markDirty(event, false); } @Override - public void fileDeleted(final VirtualFileEvent event) { + public void fileDeleted(@NotNull final VirtualFileEvent event) { myFilesToUpdate.remove(event.getFile()); // no need to update it anymore } @Override - public void fileCopied(final VirtualFileCopyEvent event) { + public void fileCopied(@NotNull final VirtualFileCopyEvent event) { markDirty(event, false); } @Override - public void beforeFileDeletion(final VirtualFileEvent event) { + public void beforeFileDeletion(@NotNull final VirtualFileEvent event) { invalidateIndices(event.getFile(), false); } @Override - public void beforeContentsChange(final VirtualFileEvent event) { + public void beforeContentsChange(@NotNull final VirtualFileEvent event) { invalidateIndices(event.getFile(), true); } @Override - public void contentsChanged(final VirtualFileEvent event) { + public void contentsChanged(@NotNull final VirtualFileEvent event) { markDirty(event, true); } @Override - public void beforePropertyChange(final VirtualFilePropertyEvent event) { + public void beforePropertyChange(@NotNull final VirtualFilePropertyEvent event) { if (event.getPropertyName().equals(VirtualFile.PROP_NAME)) { // indexes may depend on file name final VirtualFile file = event.getFile(); @@ -1719,7 +1736,7 @@ public class FileBasedIndex implements ApplicationComponent { } @Override - public void propertyChanged(final VirtualFilePropertyEvent event) { + public void propertyChanged(@NotNull final VirtualFilePropertyEvent event) { if (event.getPropertyName().equals(VirtualFile.PROP_NAME)) { // indexes may depend on file name if (!event.getFile().isDirectory()) { @@ -1728,12 +1745,12 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void markDirty(final VirtualFileEvent event, final boolean contentChange) { + private void markDirty(@NotNull final VirtualFileEvent event, final boolean contentChange) { final VirtualFile eventFile = event.getFile(); cleanProcessedFlag(eventFile); iterateIndexableFiles(eventFile, new Processor() { @Override - public boolean process(final VirtualFile file) { + public boolean process(@NotNull final VirtualFile file) { if (!contentChange) ++myFilesModCount; FileContent fileContent = null; // handle 'content-less' indices separately @@ -1771,7 +1788,7 @@ public class FileBasedIndex implements ApplicationComponent { myFilesToUpdate.add(file); } - void invalidateIndices(final VirtualFile file, final boolean markForReindex) { + void invalidateIndices(@NotNull final VirtualFile file, final boolean markForReindex) { if (isUnderConfigOrSystem(file)) { return; } @@ -1850,7 +1867,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void removeFileDataFromIndices(Collection> affectedIndices, VirtualFile file) { + private void removeFileDataFromIndices(@NotNull Collection> affectedIndices, @NotNull VirtualFile file) { Throwable unexpectedError = null; for (ID indexId : affectedIndices) { try { @@ -1900,11 +1917,11 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void iterateIndexableFiles(final VirtualFile file, final Processor processor) { + private void iterateIndexableFiles(@NotNull final VirtualFile file, @NotNull final Processor processor) { if (file.isDirectory()) { final ContentIterator iterator = new ContentIterator() { @Override - public boolean processFile(final VirtualFile fileOrDir) { + public boolean processFile(@NotNull final VirtualFile fileOrDir) { if (!fileOrDir.isDirectory()) { processor.process(fileOrDir); } @@ -1963,7 +1980,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void processFileImpl(Project project, final com.intellij.ide.caches.FileContent fileContent, boolean onlyRemoveOutdatedData) { + private void processFileImpl(Project project, @NotNull final com.intellij.ide.caches.FileContent fileContent, boolean onlyRemoveOutdatedData) { final VirtualFile file = fileContent.getVirtualFile(); final boolean reallyRemoved = myFilesToUpdate.remove(file); if (reallyRemoved && file.isValid()) { @@ -1993,13 +2010,14 @@ public class FileBasedIndex implements ApplicationComponent { myProgressIndicator = ProgressManager.getInstance().getProgressIndicator(); } + @NotNull @Override public List getFiles() { return myFiles; } @Override - public boolean processFile(final VirtualFile file) { + public boolean processFile(@NotNull final VirtualFile file) { if (!file.isValid()) { return true; } @@ -2081,7 +2099,7 @@ public class FileBasedIndex implements ApplicationComponent { (isMock(file) || !IndexingStamp.isFileIndexed(file, indexId, IndexInfrastructure.getIndexCreationStamp(indexId))); } - private boolean isUnderConfigOrSystem(VirtualFile file) { + private boolean isUnderConfigOrSystem(@NotNull VirtualFile file) { final String filePath = file.getPath(); return myConfigPath != null && FileUtil.startsWith(filePath, myConfigPath) || mySystemPath != null && FileUtil.startsWith(filePath, mySystemPath); @@ -2091,7 +2109,7 @@ public class FileBasedIndex implements ApplicationComponent { return !(file instanceof NewVirtualFile); } - private boolean isTooLarge(VirtualFile file) { + private boolean isTooLarge(@NotNull VirtualFile file) { if (SingleRootFileViewProvider.isTooLarge(file)) { final FileType type = file.getFileType(); return !myNoLimitCheckTypes.contains(type); @@ -2099,7 +2117,7 @@ public class FileBasedIndex implements ApplicationComponent { return false; } - private boolean isTooLarge(VirtualFile file, long contentSize) { + private boolean isTooLarge(@NotNull VirtualFile file, long contentSize) { if (SingleRootFileViewProvider.isTooLarge(file, contentSize)) { final FileType type = file.getFileType(); return !myNoLimitCheckTypes.contains(type); @@ -2107,17 +2125,18 @@ public class FileBasedIndex implements ApplicationComponent { return false; } + @NotNull public CollectingContentIterator createContentIterator() { ++myFilesModCount; return new UnindexedFilesFinder(); } - public void registerIndexableSet(IndexableFileSet set, @Nullable Project project) { + public void registerIndexableSet(@NotNull IndexableFileSet set, @Nullable Project project) { myIndexableSets.add(set); myIndexableSetToProjectMap.put(set, project); } - public void removeIndexableSet(IndexableFileSet set) { + public void removeIndexableSet(@NotNull IndexableFileSet set) { myChangedFilesCollector.forceUpdate(null, null, null, true); myIndexableSets.remove(set); myIndexableSetToProjectMap.remove(set); @@ -2148,7 +2167,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private static void cleanProcessedFlag(final VirtualFile file) { + private static void cleanProcessedFlag(@NotNull final VirtualFile file) { if (!(file instanceof NewVirtualFile)) return; final NewVirtualFile nvf = (NewVirtualFile)file; @@ -2162,7 +2181,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - public static void iterateIndexableFiles(final ContentIterator processor, Project project, ProgressIndicator indicator) { + public static void iterateIndexableFiles(@NotNull final ContentIterator processor, @NotNull Project project, ProgressIndicator indicator) { if (project.isDisposed()) { return; } @@ -2220,7 +2239,7 @@ public class FileBasedIndex implements ApplicationComponent { } } - private static void iterateRecursively(@Nullable final VirtualFile root, final ContentIterator processor, ProgressIndicator indicator) { + private static void iterateRecursively(@Nullable final VirtualFile root, @NotNull final ContentIterator processor, @Nullable ProgressIndicator indicator) { if (root != null) { if (indicator != null) { indicator.checkCanceled(); @@ -2263,6 +2282,7 @@ public class FileBasedIndex implements ApplicationComponent { } }; + @NotNull public synchronized Holder enter(boolean mode) { if (mode) { while (myHolds < 0) { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexInfrastructure.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexInfrastructure.java index 290080cb23fc..15d1df8333d5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexInfrastructure.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexInfrastructure.java @@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.psi.stubs.StubIndexKey; import com.intellij.psi.stubs.StubUpdatingIndex; import gnu.trove.TObjectLongHashMap; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.*; @@ -42,19 +43,19 @@ public class IndexInfrastructure { private IndexInfrastructure() { } - public static File getVersionFile(final ID indexName) { + public static File getVersionFile(@NotNull ID indexName) { return new File(getIndexRootDir(indexName), indexName + ".ver"); } - public static File getStorageFile(final ID indexName) { + public static File getStorageFile(@NotNull ID indexName) { return new File(getIndexRootDir(indexName), indexName.toString()); } - public static File getInputIndexStorageFile(final ID indexName) { + public static File getInputIndexStorageFile(@NotNull ID indexName) { return new File(getIndexRootDir(indexName), indexName.toString()+"_inputs"); } - public static File getIndexRootDir(final ID indexName) { + public static File getIndexRootDir(@NotNull ID indexName) { final String dirName = indexName.toString().toLowerCase(Locale.US); // store StubIndices under StubUpdating index' root to ensure they are deleted // when StubUpdatingIndex version is changed diff --git a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java index 442afb9e3282..7a4acf603be5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java @@ -38,22 +38,23 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class MapReduceIndex implements UpdatableIndex { private static final Logger LOG = Logger.getInstance("#com.intellij.util.indexing.MapReduceIndex"); - private final ID myIndexId; + @Nullable private final ID myIndexId; private final DataIndexer myIndexer; - protected final IndexStorage myStorage; - private PersistentHashMap> myInputsIndex; + @NotNull protected final IndexStorage myStorage; + @Nullable private PersistentHashMap> myInputsIndex; private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(); private Factory>> myInputsIndexFactory; - public MapReduceIndex(@Nullable final ID indexId, DataIndexer indexer, final IndexStorage storage) { + public MapReduceIndex(@Nullable final ID indexId, DataIndexer indexer, @NotNull IndexStorage storage) { myIndexId = indexId; myIndexer = indexer; myStorage = storage; } + @NotNull public IndexStorage getStorage() { return myStorage; } @@ -149,6 +150,7 @@ public class MapReduceIndex implements UpdatableIndex getAllKeys() throws StorageException { Set allKeys = new HashSet(); @@ -186,6 +188,7 @@ public class MapReduceIndex implements UpdatableIndex> createInputsIndex() throws IOException { Factory>> factory = myInputsIndexFactory; if (factory != null) { @@ -217,7 +220,7 @@ public class MapReduceIndex implements UpdatableIndex newData, Callable> oldKeysGetter) throws StorageException { + protected void updateWithMap(final int inputId, @NotNull Map newData, @NotNull Callable> oldKeysGetter) throws StorageException { getWriteLock().lock(); try { try {