/*
 * 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.core;

import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.mock.MockComponentManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.PathMacros;
import com.intellij.openapi.components.ExtensionAreas;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.components.impl.ModulePathMacroManager;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.module.impl.ModuleEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleExtension;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.impl.DirectoryIndex;
import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
import com.intellij.openapi.roots.impl.ProjectRootManagerImpl;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;

/**
 * @author yole
 */
public class CoreModule extends MockComponentManager implements ModuleEx {
  private String myPath;
  private final Project myProject;

  public CoreModule(@NotNull Disposable parentDisposable, Project project, String moduleFilePath) {
    super(project.getPicoContainer(), parentDisposable);
    myProject = project;
    myPath = moduleFilePath;

    Extensions.instantiateArea(ExtensionAreas.IDEA_MODULE, this, null);
    CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class);
    Disposer.register(parentDisposable, new Disposable() {
      @Override
      public void dispose() {
        Extensions.disposeArea(CoreModule.this);
      }
    });

    ModuleRootManagerImpl moduleRootManager = new ModuleRootManagerImpl(this,
                                                                        DirectoryIndex.getInstance(project),
                                                                        ProjectRootManagerImpl.getInstanceImpl(project),
                                                                        VirtualFilePointerManager.getInstance());
    getPicoContainer().registerComponentInstance(ModuleRootManager.class, moduleRootManager);
    getPicoContainer().registerComponentInstance(PathMacroManager.class, new ModulePathMacroManager(PathMacros.getInstance(), this));
  }

  @Override
  public void init() {
  }

  @Override
  public void loadModuleComponents() {
  }

  @Override
  public void moduleAdded() {
  }

  @Override
  public void projectOpened() {
  }

  @Override
  public void projectClosed() {
  }

  @Override
  public void rename(String newName) {
  }

  @Override
  public VirtualFile getModuleFile() {
    throw new UnsupportedOperationException();
  }

  @NotNull
  @Override
  public String getModuleFilePath() {
    return myPath;
  }

  @NotNull
  @Override
  public Project getProject() {
    return myProject;
  }

  @NotNull
  @Override
  public String getName() {
    return StringUtil.trimEnd(myPath, ModuleFileType.DOT_DEFAULT_EXTENSION);
  }

  @Override
  public boolean isLoaded() {
    return true;
  }

  @Override
  public void setOption(@NotNull String optionName, @NotNull String optionValue) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void clearOption(@NotNull String optionName) {
    throw new UnsupportedOperationException();
  }

  @Override
  public String getOptionValue(@NotNull String optionName) {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleScope(boolean includeTests) {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleWithLibrariesScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleWithDependenciesScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleContentScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleContentWithDependenciesScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(boolean includeTests) {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleWithDependentsScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleTestsWithDependentsScope() {
    throw new UnsupportedOperationException();
  }

  @Override
  public GlobalSearchScope getModuleRuntimeScope(boolean includeTests) {
    throw new UnsupportedOperationException();
  }
}

@@ -1675,24 +1675,59 @@
 earchScope;%0A
+import com.intellij.util.PathUtil;%0A
 import org.j
@@ -3804,22 +3804,44 @@
 trimEnd(
+PathUtil.getFileName(
 myPath
+)
 , Module

fix CoreModule.getName()