@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 GroovyScriptRunner findConfiguration() {
    final VirtualFile scriptFile = getScriptFile();
    if (scriptFile == null) {
      return null;
    }

    final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(scriptFile);
    if (!(psiFile instanceof GroovyFile)) {
      return null;
    }
    if (!((GroovyFile) psiFile).isScript()) {
      return new DefaultGroovyScriptRunner();
    }

    return GroovyScriptTypeDetector.getScriptType((GroovyFile) psiFile).getRunner();
  }
  protected RunnerAndConfigurationSettings createConfigurationByElement(
      final Location location, final ConfigurationContext context) {
    final PsiElement element = location.getPsiElement();
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof GroovyFile)) {
      return null;
    }

    GroovyFile groovyFile = (GroovyFile) file;
    final PsiClass aClass = GroovyRunnerUtil.getRunningClass(location.getPsiElement());
    if (aClass instanceof GroovyScriptClass || GroovyRunnerUtil.isRunnable(aClass)) {
      final RunnerAndConfigurationSettings settings = createConfiguration(aClass);
      if (settings != null) {
        mySourceElement = element;
        final GroovyScriptRunConfiguration configuration =
            (GroovyScriptRunConfiguration) settings.getConfiguration();
        GroovyScriptTypeDetector.getScriptType(groovyFile)
            .tuneConfiguration(groovyFile, configuration, location);
        return settings;
      }
    }

    if (file.getText().contains("@Grab")) {
      ApplicationConfigurationProducer producer = new ApplicationConfigurationProducer();
      ConfigurationFromContext settings = producer.createConfigurationFromContext(context);
      if (settings != null) {
        PsiElement src = settings.getSourceElement();
        mySourceElement = src;
        return createConfiguration(
            src instanceof PsiMethod ? ((PsiMethod) src).getContainingClass() : (PsiClass) src);
      }

      return null;
    } else {
      return null;
    }
  }