@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; }
public RunnerAndConfigurationSettings createConfigurationByElement( Location location, final ConfigurationContext context) { location = JavaExecutionUtil.stepIntoSingleClass(location); if (location == null) return null; final PsiElement element = location.getPsiElement(); if (!element.isPhysical()) return null; PsiElement currentElement = element; PsiMethod method; while ((method = findMain(currentElement)) != null) { final PsiClass aClass = method.getContainingClass(); if (ConfigurationUtil.MAIN_CLASS.value(aClass)) { myPsiElement = method; return createConfiguration(aClass, context, location); } currentElement = method.getParent(); } final PsiClass aClass = ApplicationConfigurationType.getMainClass(element); if (aClass == null) return null; myPsiElement = aClass; return createConfiguration(aClass, context, location); }
public ApplicationConfigurationProducer() { super(ApplicationConfigurationType.getInstance()); }