/*
 * 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.<FileNameMatcher>emptyList());

    assertNotSame(version, index.getVersion());
  }
}

@@ -632,63 +632,8 @@
 h;%0A%0A
-import com.intellij.openapi.fileTypes.FileNameMatcher;%0A
 impo
@@ -778,32 +778,92 @@
 x.FakeFileType;%0A
+import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;%0A
 import com.intel
@@ -1074,39 +1074,8 @@
 l;%0A%0A
-import java.util.Collections;%0A%0A
 /**%0A
@@ -1793,24 +1793,36 @@
 Version();%0A%0A
+    try %7B%0A  
     FileType
@@ -1820,32 +1820,34 @@
  FileTypeManager
+Ex
 .getInstance().r
@@ -1842,16 +1842,18 @@
 Instance
+Ex
 ().regis
@@ -1871,54 +1871,13 @@
 (foo
-, Collections.%3CFileNameMatcher%3EemptyList()
 );%0A
-%0A
+  
     
@@ -1920,14 +1920,105 @@
 ion());%0A
+    %7D%0A    finally %7B%0A      FileTypeManagerEx.getInstanceEx().unregisterFileType(foo);%0A    %7D%0A
   %7D%0A%7D%0A

test fix