@Override
 protected RunnerAndConfigurationSettings findExistingByElement(
     Location location,
     @NotNull List<RunnerAndConfigurationSettings> existingConfigurations,
     ConfigurationContext context) {
   for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
     final RunConfiguration configuration = existingConfiguration.getConfiguration();
     final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration) configuration;
     final String path = existing.getScriptPath();
     if (path != null) {
       final PsiFile file = location.getPsiElement().getContainingFile();
       if (file instanceof GroovyFile) {
         final VirtualFile vfile = file.getVirtualFile();
         if (vfile != null && FileUtil.toSystemIndependentName(path).equals(vfile.getPath())) {
           if (!((GroovyFile) file).isScript()
               || GroovyScriptTypeDetector.getScriptType((GroovyFile) file)
                   .isConfigurationByLocation(existing, location)) {
             return existingConfiguration;
           }
         }
       }
     }
   }
   return null;
 }
  @Nullable
  private RunnerAndConfigurationSettings createConfiguration(final PsiClass aClass) {
    final Project project = aClass.getProject();
    RunnerAndConfigurationSettings settings =
        RunManagerEx.getInstanceEx(project).createConfiguration("", getConfigurationFactory());
    final GroovyScriptRunConfiguration configuration =
        (GroovyScriptRunConfiguration) settings.getConfiguration();
    final PsiFile file = aClass.getContainingFile().getOriginalFile();
    final PsiDirectory dir = file.getContainingDirectory();
    if (dir == null) return null;
    configuration.setWorkDir(dir.getVirtualFile().getPath());
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) return null;
    configuration.setScriptPath(vFile.getPath());
    RunConfigurationModule module = configuration.getConfigurationModule();

    String name = getConfigurationName(aClass, module);
    configuration.setName(name);
    configuration.setModule(JavaExecutionUtil.findModule(aClass));
    return settings;
  }