void (@NotNull ActionContext context, @NotNull PsiMethod constructor, @NotNull List<PsiField> fields, @NotNull ModPsiUpdater updater, @Nullable ChainedConstructorData chainedConstructorData) { final PsiParameterList parameterList = constructor.getParameterList(); final List<PsiVariable> params = fillVariables(fields, parameterList); final Map<PsiField, String> usedFields = new LinkedHashMap<>(); final MultiMap<PsiType, PsiVariable> types = new MultiMap<>(); for (PsiVariable param : params) { types.putValue(param.getType(), param); } Project project = context.project(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); CodeStyleSettings allSettings = CodeStyleSettingsManager.getInstance(project).cloneSettings(CodeStyle.getSettings(context.file())); JavaCodeStyleSettings settings = allSettings.getCustomSettings(JavaCodeStyleSettings.class); boolean preferLongerNames = settings.PREFER_LONGER_NAMES; Ref<PsiElement> prev = Ref.create(); for (PsiVariable param : params) { final PsiType paramType = param.getType(); if (param instanceof PsiField field) { settings.PREFER_LONGER_NAMES = preferLongerNames || types.get(paramType).size() > 1; CodeStyle.runWithLocalSettings(project, allSettings, () -> { final String uniqueParameterName = getUniqueParameterName(parameterList.getParameters(), param, usedFields); usedFields.put(field, uniqueParameterName); PsiParameter parameter = factory .createParameter(uniqueParameterName, AnnotationTargetUtil.keepStrictlyTypeUseAnnotations(param.getModifierList(), paramType), parameterList); if (prev.isNull()) { prev.set(parameterList.isEmpty() ? parameterList.add(parameter) : parameterList.addBefore(parameter, parameterList.getParameter(0))); } else { prev.set(parameterList.addAfter(parameter, prev.get())); } }); } else { prev.set(param); } } if (chainedConstructorData != null) { chainedConstructorData.updateChainedCall(constructor, usedFields); } else { PsiParameter[] newParameters = constructor.getParameterList().getParameters(); // do not introduce assignment in chained constructor for (Map.Entry<PsiField, String> entry : usedFields.entrySet()) { PsiField field = entry.getKey(); final String parameterName = entry.getValue(); PsiParameter parameter = findParamByName(parameterName, newParameters); if (parameter == null) continue; NullableNotNullManager.getInstance(field.getProject()).copyNullableOrNotNullAnnotation(field, parameter); PsiStatement assignment = AssignFieldFromParameterAction.addFieldAssignmentStatement(project, field, parameter, updater); if (assignment != null) { CodeStyleManager.getInstance(project).reformat(assignment); } } } }