/**
   * return "this.<attribute name>.add(<argument name>);" -or- "<value get method>.add(<argument
   * name>);
   *
   * <p>if back pointer, add "<argument name>.<set method name>(this);"
   *
   * <p>e.g. "addBar(Bar bar) { getBars().add(bar); bar.setFoo(this); }"
   */
  protected void insertCollectionMethodBody(NonreflectiveMethodDefinition methodDef) {
    if (methodDef.argumentNamesSize() != 1) super.insertMethodBody(methodDef);

    String argumentName = methodDef.getArgumentName(0);
    methodDef.addLine(attributeValueCode() + ".add(" + argumentName + ");");

    if (getBackPointerSetMethod() != null)
      methodDef.addLine(argumentName + "." + getBackPointerSetMethod().getName() + "(this);");
  }
  /**
   * return "this.<attribute name>.put(<argument name 1>, <argument name 2>);" -or- "<value get
   * method>.add(<argument name>);
   *
   * <p>if back pointer, adds "<argument name>.<set method name>(this);"
   *
   * <p>e.g. "addBar(Key key, Bar bar) { getBars().put(key, bar); bar.setFoo(this); }"
   */
  protected void insertMapMethodBody(NonreflectiveMethodDefinition methodDef) {
    if (methodDef.argumentNamesSize() != 2) super.insertMethodBody(methodDef);

    String keyArgumentName = methodDef.getArgumentName(0);
    String valueArgumentName = methodDef.getArgumentName(1);
    methodDef.addLine(
        attributeValueCode() + ".put(" + keyArgumentName + ", " + valueArgumentName + ");");

    if (getBackPointerSetMethod() != null)
      methodDef.addLine(valueArgumentName + "." + getBackPointerSetMethod().getName() + "(this);");
  }
  /**
   * The assumption is that this method will have 2 arguments for a map and 1 argument for a
   * collection. However, it is possible for this not to be the case, so we check and generate
   * nothing if this assumption proves not to be accurate.
   */
  void insertArguments(NonreflectiveMethodDefinition methodDef) {
    int assumedArgumentSize = 1; // for collections
    if (getAccessedAttribute().canHaveMapKeyAndValueTypes()) assumedArgumentSize = 2;

    if (getMethod().methodParametersSize() != assumedArgumentSize) super.insertArguments(methodDef);

    if (getAccessedAttribute().canHaveMapKeyAndValueTypes())
      methodDef.addArgument(getMethod().getMethodParameter(0).declaration(), "key");

    addArgument(methodDef, getMethod().getMethodParameter(assumedArgumentSize - 1));
  }