package org.metaborg.spoofax.eclipse;

import org.apache.commons.vfs2.FileSystemManager;
import org.metaborg.core.editor.IEditorRegistry;
import org.metaborg.core.project.IMavenProjectService;
import org.metaborg.core.project.IProjectService;
import org.metaborg.core.resource.IResourceService;
import org.metaborg.core.transform.CompileGoal;
import org.metaborg.core.transform.ITransformerGoal;
import org.metaborg.core.transform.ITransformerResultHandler;
import org.metaborg.core.transform.NamedGoal;
import org.metaborg.spoofax.core.SpoofaxModule;
import org.metaborg.spoofax.eclipse.build.MavenProjectService;
import org.metaborg.spoofax.eclipse.editor.IEclipseEditorRegistry;
import org.metaborg.spoofax.eclipse.editor.IEclipseEditorRegistryInternal;
import org.metaborg.spoofax.eclipse.editor.SpoofaxEditorRegistry;
import org.metaborg.spoofax.eclipse.job.GlobalSchedulingRules;
import org.metaborg.spoofax.eclipse.language.LanguageChangeProcessor;
import org.metaborg.spoofax.eclipse.resource.EclipseFileSystemManagerProvider;
import org.metaborg.spoofax.eclipse.resource.EclipseProjectService;
import org.metaborg.spoofax.eclipse.resource.EclipseResourceService;
import org.metaborg.spoofax.eclipse.resource.IEclipseResourceService;
import org.metaborg.spoofax.eclipse.transform.OpenEditorResultHandler;
import org.spoofax.interpreter.terms.IStrategoTerm;

import com.google.inject.Singleton;
import com.google.inject.multibindings.MapBinder;

public class SpoofaxEclipseModule extends SpoofaxModule {
    public SpoofaxEclipseModule() {
        super(SpoofaxEclipseModule.class.getClassLoader());
    }

    public SpoofaxEclipseModule(ClassLoader resourceClassLoader) {
        super(resourceClassLoader);
    }


    @Override protected void bindResource() {
        bind(EclipseResourceService.class).in(Singleton.class);
        bind(IResourceService.class).to(EclipseResourceService.class);
        bind(IEclipseResourceService.class).to(EclipseResourceService.class);

        bind(FileSystemManager.class).toProvider(EclipseFileSystemManagerProvider.class).in(Singleton.class);
    }

    @Override protected void bindProject() {
        bind(IProjectService.class).to(EclipseProjectService.class).in(Singleton.class);
        bind(IMavenProjectService.class).to(MavenProjectService.class).in(Singleton.class);
    }

    @Override protected void bindTransformerResultHandlers(
        MapBinder<Class<? extends ITransformerGoal>, ITransformerResultHandler<IStrategoTerm>> binder) {
        bind(OpenEditorResultHandler.class).in(Singleton.class);
        binder.addBinding(NamedGoal.class).to(OpenEditorResultHandler.class);
        binder.addBinding(CompileGoal.class).to(OpenEditorResultHandler.class);
    }

    @Override protected void bindOther() {
        bind(GlobalSchedulingRules.class).in(Singleton.class);
        bind(LanguageChangeProcessor.class).in(Singleton.class);

        bind(SpoofaxEditorRegistry.class).in(Singleton.class);
        bind(IEditorRegistry.class).to(SpoofaxEditorRegistry.class);
        bind(IEclipseEditorRegistry.class).to(SpoofaxEditorRegistry.class);
        bind(IEclipseEditorRegistryInternal.class).to(SpoofaxEditorRegistry.class);
    }
}

@@ -78,24 +78,65 @@
 temManager;%0A
+import org.metaborg.core.MetaborgModule;%0A
 import org.m
@@ -164,32 +164,32 @@
 EditorRegistry;%0A
-
 import org.metab
@@ -1759,16 +1759,664 @@
     %7D%0A%0A%0A
+    @Override protected void configure() %7B%0A        super.configure();%0A%0A        bind(GlobalSchedulingRules.class).in(Singleton.class);%0A        bind(LanguageChangeProcessor.class).in(Singleton.class);%0A%0A        bind(SpoofaxEditorRegistry.class).in(Singleton.class);%0A        bind(IEditorRegistry.class).to(SpoofaxEditorRegistry.class);%0A        bind(IEclipseEditorRegistry.class).to(SpoofaxEditorRegistry.class);%0A        bind(IEclipseEditorRegistryInternal.class).to(SpoofaxEditorRegistry.class);%0A    %7D%0A%0A%0A    /**%0A     * Overrides %7B@link MetaborgModule#bindResource()%7D to provide an Eclipse resource manager and filesystem%0A     * implementation.%0A     */%0A
     @Ove
@@ -2776,32 +2776,169 @@
 .class);%0A    %7D%0A%0A
+    /**%0A     * Overrides %7B@link MetaborgModule#bindProject()%7D for non-dummy implementation of project and Maven project service.%0A     */%0A
     @Override pr
@@ -3146,32 +3146,177 @@
 .class);%0A    %7D%0A%0A
+    /**%0A     * Overrides %7B@link SpoofaxModule#bindTransformerResultHandlers()%7D for transformation handlers that open new%0A     * editors.%0A     */%0A
     @Override pr
@@ -3599,32 +3599,32 @@
 Handler.class);%0A
+
         binder.a
@@ -3696,478 +3696,7 @@
    %7D
-%0A%0A    @Override protected void bindOther() %7B%0A        bind(GlobalSchedulingRules.class).in(Singleton.class);%0A        bind(LanguageChangeProcessor.class).in(Singleton.class);%0A%0A        bind(SpoofaxEditorRegistry.class).in(Singleton.class);%0A        bind(IEditorRegistry.class).to(SpoofaxEditorRegistry.class);%0A        bind(IEclipseEditorRegistry.class).to(SpoofaxEditorRegistry.class);%0A        bind(IEclipseEditorRegistryInternal.class).to(SpoofaxEditorRegistry.class);%0A    %7D
 %0A%7D%0A

Split up Spoofax module.