boolean (@NotNull T configuration, @NotNull ConfigurationContext context, @NotNull Ref<PsiElement> sourceElement) { if (isMultipleElementsSelected(context)) { return false; } final Location<?> contextLocation = context.getLocation(); setupConfigurationParamName(configuration, contextLocation); PsiClass psiClass = null; PsiElement element = context.getPsiLocation(); Integer sourceValueIndex = null; while (element != null) { if (element instanceof PsiClass cls && isTestClass(cls)) { psiClass = cls; break; } else if (element instanceof PsiMember member) { psiClass = contextLocation instanceof MethodLocation methodLoc ? methodLoc.getContainingClass() : contextLocation instanceof PsiMemberParameterizedLocation memberLoc ? memberLoc.getContainingClass() : member.getContainingClass(); if (isTestClass(psiClass)) { break; } } else if (element instanceof PsiClassOwner classOwner) { final PsiClass[] classes = classOwner.getClasses(); if (classes.length == 1) { psiClass = classes[0]; break; } } else if (element instanceof PsiJavaToken token) { JvmAnnotationAttribute annotationArrayValue = getAnnotationValue(token); if (annotationArrayValue != null) { sourceValueIndex = getSourceValueIndex(token, annotationArrayValue); } } element = element.getParent(); } if (!isTestClass(psiClass)) return false; String classQualifiedName = psiClass.getQualifiedName(); if (classQualifiedName == null) return false; PsiElement psiElement = psiClass; RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context); setupConfigurationModule(context, configuration); final Module originalModule = configuration.getConfigurationModule().getModule(); configuration.beClassConfiguration(psiClass); PsiMethod method = PsiTreeUtil.getParentOfType(context.getPsiLocation(), PsiMethod.class, false); while (method != null) { if (isTestMethod(false, method)) { configuration.beMethodConfiguration(MethodLocation.elementInClass(method, psiClass)); psiElement = method; } method = PsiTreeUtil.getParentOfType(method, PsiMethod.class); } configuration.restoreOriginalModule(originalModule); Module module = configuration.getConfigurationModule().getModule(); if (module == null && psiClass.getManager().isInProject(psiClass)) { PsiFile containingFile = psiClass.getContainingFile(); if (LOG.isDebugEnabled()) { LOG.info("No module found: " + "generated name:" + configuration.getName() + "; valid: " + psiClass.isValid() + "; physical: " + psiClass.isPhysical() + "; className: " + classQualifiedName + "; file: " + containingFile + "; module: " + ModuleUtilCore.findModuleForPsiElement(psiClass.getContainingFile()) + "; original module: " + originalModule); } return false; } settings.setName(configuration.getName()); sourceElement.set(psiElement); if (sourceValueIndex != null) { String oldParameters = configuration.getProgramParameters() != null ? configuration.getProgramParameters() + " " : ""; final String newProgramParameters = oldParameters + "valueSource " + sourceValueIndex; configuration.setProgramParameters(newProgramParameters); } return true; }