diff --git a/platform/lang-impl/src/com/intellij/psi/search/FileTypeIndex.java b/platform/lang-impl/src/com/intellij/psi/search/FileTypeIndex.java index b81138eb54c8..7ddbeaa25e63 100644 --- a/platform/lang-impl/src/com/intellij/psi/search/FileTypeIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/search/FileTypeIndex.java @@ -65,7 +65,12 @@ public class FileTypeIndex extends ScalarIndexExtension @Override public int getVersion() { - return 1; + FileType[] types = myFileTypeManager.getRegisteredFileTypes(); + int version = 1; + for (FileType type : types) { + version += type.getName().hashCode(); + } + return version; } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/psi/search/FileTypeIndexTest.java b/platform/platform-tests/testSrc/com/intellij/psi/search/FileTypeIndexTest.java new file mode 100644 index 000000000000..bb01e38f9021 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/psi/search/FileTypeIndexTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.search; + +import com.intellij.openapi.fileTypes.FileNameMatcher; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.ex.FakeFileType; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; + +/** + * @author Dmitry Avdeev + * Date: 7/24/12 + */ +public class FileTypeIndexTest extends LightPlatformCodeInsightFixtureTestCase { + + public FileTypeIndexTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + public void testAddFileType() throws Exception { + FileType foo = new FakeFileType() { + @Override + public boolean isMyFileType(VirtualFile file) { + return true; + } + + @NotNull + @Override + public String getName() { + return "foo"; + } + + @NotNull + @Override + public String getDescription() { + return ""; + } + }; + FileTypeIndex index = new FileTypeIndex(FileTypeManager.getInstance()); + int version = index.getVersion(); + + FileTypeManager.getInstance().registerFileType(foo, Collections.emptyList()); + + assertNotSame(version, index.getVersion()); + } +}