private PsiMethod generateMethodFor(
      PsiField field, String methodName, String parameterName, PsiElementFactory elementFactory) {
    PsiMethod withMethod =
        elementFactory.createMethod(
            methodName, elementFactory.createType(field.getContainingClass()));
    PsiParameter parameter = elementFactory.createParameter(parameterName, field.getType());
    withMethod.getParameterList().add(parameter);
    PsiUtil.setModifierProperty(withMethod, PsiModifier.PUBLIC, true);

    return withMethod;
  }
  private GenerationInfo generateWithMethodFor(PsiField field) {
    PsiMethod templateMethod = generateMethodPrototype(field);
    PsiMethod existingMethod =
        field.getContainingClass().findMethodBySignature(templateMethod, false);

    return existingMethod == null ? new PsiGenerationInfo(templateMethod) : null;
  }
  private PsiMethod generateMethodPrototype(PsiField field) {
    Project project = field.getProject();
    JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();

    String propertyName =
        codeStyleManager.variableNameToPropertyName(
            field.getName(), codeStyleManager.getVariableKind(field));
    String methodName = methodNameGenerator.generateMethodNameFor(propertyName);
    String parameterName =
        codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);

    PsiMethod withMethod = generateMethodFor(field, methodName, parameterName, elementFactory);
    generateMethodBodyFor(withMethod, propertyName, parameterName, elementFactory);

    return withMethod;
  }