package editor;


import editor.util.EditorUtilities;
import editor.util.Project;
import gw.config.CommonServices;
import gw.config.IPlatformHelper;
import gw.lang.Gosu;
import gw.lang.gosuc.GosucDependency;
import gw.lang.gosuc.GosucModule;
import gw.lang.init.GosuInitialization;
import gw.lang.reflect.TypeSystem;
import gw.lang.reflect.module.IExecutionEnvironment;

import java.awt.*;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

public class RunMe
{
  private static BasicGosuEditor _gosuEditor;
  private static GosuInitialization _gosuInitialization;

  public static void main( String[] args ) throws Exception
  {
    launchEditor();
  }

  public static BasicGosuEditor getEditorFrame()
  {
    return _gosuEditor;
  }

  public static void launchEditor() throws Exception
  {
    EventQueue.invokeLater(
      () -> {
        _gosuEditor = BasicGosuEditor.create();
        _gosuEditor.restoreState( EditorUtilities.getRecentProject( _gosuEditor.getGosuPanel() ) );
        _gosuEditor.showMe();
      } );
  }

  public static void reinitializeGosu( Project project )
  {
    CommonServices.getKernel().redefineService_Privileged( IPlatformHelper.class, new GosuEditorPlatformHelper() );

    IExecutionEnvironment execEnv = TypeSystem.getExecutionEnvironment();
    _gosuInitialization = GosuInitialization.instance( execEnv );
    GosucModule gosucModule = new GosucModule(
      IExecutionEnvironment.DEFAULT_SINGLE_MODULE_NAME, project.getSourcePath(), Gosu.deriveClasspathFrom( RunMe.class ).stream().map( File::getAbsolutePath ).collect( Collectors.toList() ),
      "", Collections.<GosucDependency>emptyList(), Collections.<String>emptyList() );
    _gosuInitialization.reinitializeSimpleIde( gosucModule );
  }
}

@@ -420,24 +420,47 @@
 ava.util.*;%0A
+import java.util.List;%0A
 import java.
@@ -1523,13 +1523,8 @@
 (), 
-Gosu.
 deri
@@ -1538,94 +1538,17 @@
 path
-From( RunMe.class ).stream().map( File::getAbsolutePath ).collect( Collectors.toList()
+( project
  ),%0A
@@ -1699,11 +1699,576 @@
 e );%0A  %7D
+%0A%0A  private static List%3CString%3E deriveClasspath( Project project )%0A  %7B%0A    List%3CString%3E classpath = new ArrayList%3C%3E();%0A    List%3CString%3E sourcePath = project.getSourcePath();%0A    for( String path: sourcePath )%0A    %7B%0A      if( !path.toLowerCase().startsWith( project.getProjectDir().getAbsolutePath().toLowerCase() ) )%0A      %7B%0A        classpath.add( path );%0A      %7D%0A    %7D%0A    List%3CString%3E collect = Gosu.deriveClasspathFrom( RunMe.class ).stream().map( File::getAbsolutePath ).collect( Collectors.toList() );%0A    classpath.addAll( collect );%0A    return classpath;%0A  %7D
 %0A%7D%0A

fix runtime classpath in editor