/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.xcodeml.xnode;

import cx2x.xcodeml.helper.XnodeUtil;
import org.w3c.dom.Element;

import java.util.List;

/**
 * The Xparams represents the params (8.5) element in XcodeML intermediate
 * representation.
 *
 * Elements: (name*)
 * - Optional:
 *   - name (Xname)
 *
 * @author clementval
 */
public class Xparams extends Xnode {

  private List<Xnode> _parameters = null;

  /**
   * Element standard ctor. Pass the base element to the base class and read
   * inner information (elements and attributes).
   * @param baseElement The root of the element.
   */
  public Xparams(Element baseElement){
    super(baseElement);
    _parameters = XnodeUtil.findAllNames(this);
  }

  /**
   * Get the number of parameters in the params element.
   * @return Number of parameters.
   */
  public int count(){
    return _parameters.size();
  }

  /**
   * Get the list of all name elements.
   * @return List of Xname objects.
   */
  public List<Xnode> getAll(){
    return _parameters;
  }

  /**
   * Add a name element to the parameters list.
   * @param name The name element to add.
   */
  public void add(Xnode name){
    _parameters.add(name);
    appendToChildren(name, false);
  }

  @Override
  public Xparams cloneObject() {
    Element clone = (Element)cloneNode();
    return new Xparams(clone);
  }
}

@@ -1295,16 +1295,387 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Add a name element to the parameters list before the referenced element.%0A   * @param ref  Referenced element. New element will be added before.%0A   * @param name The name element to add.%0A   */%0A  public void addBefore(Xnode ref, Xnode name)%7B%0A    int index = _parameters.indexOf(ref);%0A    _parameters.add(index, name);%0A    XnodeUtil.insertBefore(ref, name);%0A  %7D%0A%0A
   @Overr

Add method addBefore