void (@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) { if (elements.length != 1 || !(elements[0] instanceof PsiMethod method)) return; if (!method.hasModifierProperty(PsiModifier.STATIC)) { String message = JavaRefactoringBundle.message("convertToInstanceMethod.method.is.not.static", method.getName()); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HelpID.CONVERT_TO_INSTANCE_METHOD); return; } final PsiParameter[] parameters = method.getParameterList().getParameters(); List<Object> targetQualifiers = new ArrayList<>(); boolean classTypesFound = false; boolean resolvableClassesFound = false; for (final PsiParameter parameter : parameters) { if (VariableAccessUtils.variableIsAssigned(parameter, parameter.getDeclarationScope())) continue; final PsiType type = parameter.getType(); if (type instanceof PsiClassType) { classTypesFound = true; final PsiClass psiClass = ((PsiClassType)type).resolve(); if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) { resolvableClassesFound = true; if (method.getManager().isInProject(psiClass)) { targetQualifiers.add(parameter); } } } } PsiClass containingClass = method.getContainingClass(); if (containingClass == null || containingClass.getQualifiedName() == null) return; String className = containingClass.getName(); PsiMethod[] constructors = containingClass.getConstructors(); boolean noArgConstructor = constructors.length == 0 || Arrays.stream(constructors).anyMatch(constructor -> constructor.getParameterList().isEmpty()); if (noArgConstructor) { targetQualifiers.add("this / new " + className + "()"); } if (targetQualifiers.isEmpty()) { String message; if (!classTypesFound) { message = JavaRefactoringBundle.message("convertToInstanceMethod.no.parameters.with.reference.type"); } else if (!resolvableClassesFound) { message = JavaRefactoringBundle.message("convertToInstanceMethod.all.reference.type.parameters.have.unknown.types"); } else { message = JavaRefactoringBundle.message("convertToInstanceMethod.all.reference.type.parameters.are.not.in.project"); } message += " " + JavaRefactoringBundle.message("convertToInstanceMethod.no.default.ctor"); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(message), getRefactoringName(), HelpID.CONVERT_TO_INSTANCE_METHOD); return; } new ConvertToInstanceMethodDialog(method, ArrayUtil.toObjectArray(targetQualifiers)).show(); }