@Override
 protected RunnerAndConfigurationSettings findExistingByElement(
     Location location,
     @NotNull RunnerAndConfigurationSettings[] existingConfigurations,
     ConfigurationContext context) {
   final PsiClass aClass = ApplicationConfigurationType.getMainClass(location.getPsiElement());
   if (aClass == null) {
     return null;
   }
   final Module predefinedModule =
       ((ApplicationConfiguration)
               ((RunManagerImpl) RunManagerEx.getInstanceEx(location.getProject()))
                   .getConfigurationTemplate(getConfigurationFactory())
                   .getConfiguration())
           .getConfigurationModule()
           .getModule();
   for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
     final ApplicationConfiguration appConfiguration =
         (ApplicationConfiguration) existingConfiguration.getConfiguration();
     if (Comparing.equal(
         JavaExecutionUtil.getRuntimeQualifiedName(aClass), appConfiguration.MAIN_CLASS_NAME)) {
       if (Comparing.equal(
           location.getModule(), appConfiguration.getConfigurationModule().getModule())) {
         return existingConfiguration;
       }
       final Module configurationModule = appConfiguration.getConfigurationModule().getModule();
       if (Comparing.equal(location.getModule(), configurationModule))
         return existingConfiguration;
       if (Comparing.equal(predefinedModule, configurationModule)) {
         return existingConfiguration;
       }
     }
   }
   return null;
 }
 private RunnerAndConfigurationSettings createConfiguration(
     final PsiClass aClass, final ConfigurationContext context, Location location) {
   final Project project = aClass.getProject();
   RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
   final ApplicationConfiguration configuration =
       (ApplicationConfiguration) settings.getConfiguration();
   configuration.MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(aClass);
   configuration.setName(configuration.getGeneratedName());
   setupConfigurationModule(context, configuration);
   JavaRunConfigurationExtensionManager.getInstance()
       .extendCreatedConfiguration(configuration, location);
   return settings;
 }