diff --git a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java index d39126e0d1c6..5c291502ec47 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java +++ b/platform/core-impl/src/com/intellij/util/indexing/FileContentImpl.java @@ -45,6 +45,7 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon private byte[] myContent; private CharSequence myContentAsText; private final long myStamp; + private final int myHashId; @Override public Project getProject() { @@ -90,26 +91,32 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon } public FileContentImpl(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset) { - this(file, contentAsText, null, charset, -1); + this(file, contentAsText, null, charset, -1, -1); } public FileContentImpl(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset, long documentStamp) { - this(file, contentAsText, null, charset, documentStamp); + this(file, contentAsText, null, charset, documentStamp, -1); } public FileContentImpl(@NotNull final VirtualFile file, @NotNull final byte[] content) { - this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content), -1); + this(file, content, -1); + } + + public FileContentImpl(@NotNull final VirtualFile file, @NotNull final byte[] content, int hashId) { + this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content), -1, hashId); } public FileContentImpl(@NotNull final VirtualFile file) { - this(file, null, null, null, -1); + this(file, null, null, null, -1, -1); } private FileContentImpl(@NotNull VirtualFile file, CharSequence contentAsText, byte[] content, Charset charset, - long stamp) { + long stamp, + int hashId + ) { myFile = file; myContentAsText = contentAsText; myContent = content; @@ -118,6 +125,7 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon // remember name explicitly because the file could be renamed afterwards myFileName = file.getName(); myStamp = stamp; + myHashId = hashId; } @NotNull @@ -209,4 +217,8 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon public String toString() { return myFileName; } + + public int getHashId() { + return myHashId; + } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index f3afcf241190..424d984d2e05 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1698,7 +1698,8 @@ public class FileBasedIndexImpl extends FileBasedIndex { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); final VirtualFile file = content.getVirtualFile(); - FileTypeManagerImpl.cacheFileType(file, file.getFileType()); + FileType fileType = file.getFileType(); + FileTypeManagerImpl.cacheFileType(file, fileType); try { PsiFile psiFile = null; @@ -1711,13 +1712,16 @@ public class FileBasedIndexImpl extends FileBasedIndex { if (shouldIndexFile(file, indexId)) { if (fc == null) { byte[] currentBytes; + int hashId; try { currentBytes = content.getBytes(); + hashId = ContentHashesSupport.calcContentHashIdWithFileType(currentBytes, fileType); } catch (IOException e) { currentBytes = ArrayUtil.EMPTY_BYTE_ARRAY; + hashId = -1; } - fc = new FileContentImpl(file, currentBytes); + fc = new FileContentImpl(file, currentBytes, hashId); if (project == null) { project = ProjectUtil.guessProjectForFile(file); } 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 e9cd76d351b3..d5a4403748d8 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java @@ -317,8 +317,8 @@ public class MapReduceIndex implements UpdatableIndex