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

package cx2x.xcodeml.xnode;

/**
 * The Xid represents the id (8.2) element in XcodeML intermediate
 * representation.
 * <p>
 * Elements:
 * - Required:
 * - name (Xname)
 * Attributes:
 * - Required: type (text), sclass (text: auto, param, extern, extern_def,
 * label, tagname) // TODO move to enum
 *
 * @author clementval
 */

public class Xid extends Xnode {

  private Xnode _xname;

  /**
   * Element standard ctor. Pass the base element to the base class and read
   * inner information (elements and attributes).
   *
   * @param node Raw node.
   */
  public Xid(Xnode node) {
    super(node == null ? null : node.element());
    _xname = matchSeq(Xcode.NAME);
  }

  /**
   * Get the id name value.
   *
   * @return Name value.
   */
  public String getName() {
    return (_xname != null) ? _xname.value() : null;
  }

  /**
   * Set id name value.
   *
   * @param value The new name value.
   */
  public void setName(String value) {
    if(_xname != null && value != null) {
      _xname.setValue(value);
    }
  }

  /**
   * Set id type value.
   *
   * @param value The new type value.
   */
  public void setType(String value) {
    if(_baseElement != null && value != null) {
      _baseElement.setAttribute(Xname.ATTR_TYPE, value);
    }
  }

  /**
   * Get the sclass value.
   *
   * @return Sclass value.
   */
  public String getSclass() {
    return getAttribute(Xattr.SCLASS);
  }

  /**
   * Set id sclass value.
   *
   * @param value The new sclass value.
   */
  public void setSclass(String value) {
    if(_baseElement != null && value != null) {
      _baseElement.setAttribute(Xname.ATTR_SCLASS, value);
    }
  }

  /**
   * @return A new object Xid that is the clone of the current object.
   */
  public Xid cloneNode() {
    return new Xid(super.cloneNode());
  }

  /**
   * Return a brief description of the Xid.
   *
   * @return String description of the Xid as
   * "name-value (type=type-value, sclass=sclass-value)".
   */
  @Override
  public String toString() {
    return String.format("%s (type=%s, sclass=%s)", getName(),
        getType(), getSclass());
  }
}

@@ -470,16 +470,22 @@
 private 
+final 
 Xnode _x
@@ -1259,71 +1259,8 @@
     
-if(_baseElement != null && value != null) %7B%0A      _baseElement.
 setA
@@ -1269,26 +1269,21 @@
 ribute(X
-name.ATTR_
+attr.
 TYPE, va
@@ -1280,38 +1280,32 @@
 r.TYPE, value);%0A
-    %7D%0A
   %7D%0A%0A  /**%0A   * 
@@ -1569,71 +1569,8 @@
     
-if(_baseElement != null && value != null) %7B%0A      _baseElement.
 setA
@@ -1583,18 +1583,13 @@
 te(X
-name.ATTR_
+attr.
 SCLA
@@ -1592,38 +1592,32 @@
 SCLASS, value);%0A
-    %7D%0A
   %7D%0A%0A  /**%0A   * 

Use safe Xnode methods