/*
 * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
 */
package com.intellij.mock;

import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.psi.impl.file.impl.FileManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.containers.FactoryMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.List;

/**
 * @author peter
 */
public class MockFileManager implements FileManager {
  private PsiManagerEx myManager;
  private FactoryMap<VirtualFile,FileViewProvider> myViewProviders = new FactoryMap<VirtualFile, FileViewProvider>() {
    protected FileViewProvider create(final VirtualFile key) {
      return new SingleRootFileViewProvider(myManager, key);
    }
  };

  public FileViewProvider createFileViewProvider(final VirtualFile file, final boolean physical) {
    return new SingleRootFileViewProvider(myManager, file, true);
  }

  public MockFileManager(final PsiManagerEx manager) {
    myManager = manager;
  }

  public void dispose() {
    throw new UnsupportedOperationException("Method dispose is not yet implemented in " + getClass().getName());
  }

  public void runStartupActivity() {
    throw new UnsupportedOperationException("Method runStartupActivity is not yet implemented in " + getClass().getName());
  }

  @Nullable
  public PsiFile findFile(@NotNull VirtualFile vFile) {
    return getCachedPsiFile(vFile);
  }

  @Nullable
  public PsiDirectory findDirectory(@NotNull VirtualFile vFile) {
    throw new UnsupportedOperationException("Method findDirectory is not yet implemented in " + getClass().getName());
  }

  @Nullable
  public PsiPackage findPackage(@NotNull String packageName) {
    throw new UnsupportedOperationException("Method findPackage is not yet implemented in " + getClass().getName());
  }

  @Nullable
  public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) {
    throw new UnsupportedOperationException("Method findClass is not yet implemented in " + getClass().getName());
  }

  public PsiClass[] findClasses(@NotNull String qName, @NotNull GlobalSearchScope scope) {
    throw new UnsupportedOperationException("Method findClasses is not yet implemented in " + getClass().getName());
  }

  public void reloadFromDisk(@NotNull PsiFile file) //Q: move to PsiFile(Impl)?
  {
    throw new UnsupportedOperationException("Method reloadFromDisk is not yet implemented in " + getClass().getName());
  }

  @Nullable
  public PsiFile getCachedPsiFile(@NotNull VirtualFile vFile) {
    final FileViewProvider provider = findCachedViewProvider(vFile);
    return provider.getPsi(provider.getBaseLanguage());
  }

  @NotNull
  public GlobalSearchScope getResolveScope(@NotNull PsiElement element) {
    return new MockGlobalSearchScope();
  }

  @NotNull
  public GlobalSearchScope getUseScope(@NotNull PsiElement element) {
    return GlobalSearchScope.allScope(element.getProject());
  }

  public Collection<String> getNonTrivialPackagePrefixes() {
    throw new UnsupportedOperationException("Method getNonTrivialPackagePrefixes is not yet implemented in " + getClass().getName());
  }

  public void cleanupForNextTest() {
    throw new UnsupportedOperationException("Method cleanupForNextTest is not yet implemented in " + getClass().getName());
  }

  public FileViewProvider findViewProvider(VirtualFile file) {
    throw new UnsupportedOperationException("Method findViewProvider is not yet implemented in " + getClass().getName());
  }

  public FileViewProvider findCachedViewProvider(VirtualFile file) {
    return myViewProviders.get(file);
  }

  public void setViewProvider(VirtualFile virtualFile, FileViewProvider fileViewProvider) {
    myViewProviders.put(virtualFile, fileViewProvider);
  }

  public List<PsiFile> getAllCachedFiles() {
    throw new UnsupportedOperationException("Method getAllCachedFiles is not yet implemented in " + getClass().getName());
  }

}

@@ -448,37 +448,8 @@
 e;%0A%0A
-import java.util.Collection;%0A
 impo
@@ -467,16 +467,16 @@
 l.List;%0A
+
 %0A/**%0A * 
@@ -998,12 +998,16 @@
 le, 
-true
+physical
 );%0A 
@@ -1720,637 +1720,8 @@
  %7D%0A%0A
-  @Nullable%0A  public PsiPackage findPackage(@NotNull String packageName) %7B%0A    throw new UnsupportedOperationException(%22Method findPackage is not yet implemented in %22 + getClass().getName());%0A  %7D%0A%0A  @Nullable%0A  public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) %7B%0A    throw new UnsupportedOperationException(%22Method findClass is not yet implemented in %22 + getClass().getName());%0A  %7D%0A%0A  public PsiClass%5B%5D findClasses(@NotNull String qName, @NotNull GlobalSearchScope scope) %7B%0A    throw new UnsupportedOperationException(%22Method findClasses is not yet implemented in %22 + getClass().getName());%0A  %7D%0A%0A
   pu
@@ -2334,32 +2334,32 @@
 ment element) %7B%0A
+
     return Globa
@@ -2412,208 +2412,8 @@
  %7D%0A%0A
-  public Collection%3CString%3E getNonTrivialPackagePrefixes() %7B%0A    throw new UnsupportedOperationException(%22Method getNonTrivialPackagePrefixes is not yet implemented in %22 + getClass().getName());%0A  %7D%0A%0A
   pu

fix test?