package x2x.translator.xcodeml.xelement;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * The Xname represents the name (8.3) element in XcodeML intermediate
 * representation.
 * Elements: the base element can contains text data
 * Attributes:
 * - Requited: type (text)
 */

public class Xname extends XbaseElement {
  private String _nameValue = null;
  private String _nameType = null;

  public Xname(Element nameElement){
    super(nameElement);
    readElementInformation();
  }

  public void setName(String value){
    if(baseElement != null){
      baseElement.setTextContent(value);
      _nameValue = value;
    }
  }

  public void setType(String value){
    if(baseElement != null){
      baseElement.setAttribute(XelementName.ATTR_TYPE, value);
      _nameType = value;
    }
  }

  private void readElementInformation(){
    _nameType = XelementHelper.getAttributeValue(baseElement
      , XelementName.ATTR_TYPE);
    _nameValue = baseElement.getTextContent();
  }

  public String getValue(){
    return _nameValue;
  }

  public String getType(){
    return _nameType;
  }

  public boolean isIdentical(Xname other){
    return isIdentical(other.getValue(), other.getType());
  }

  public boolean isIdentical(String name, String type){
    return _nameValue.equals(name) && _nameType.equals(type);
  }

  /**
   * Create a name element with value and type in the given program
   * @param name  Value of the element
   * @param type  Type of the name element
   */
  public static Xname createEmpty(XcodeProg xcodeml, String value,
    String type)
  {
    Element nameElement = xcodeml.getDocument().
      createElement(XelementName.NAME);
    Xname name = new Xname(nameElement);
    name.setName(value);
    name.setType(type);
    return name;
  }

}

@@ -383,21 +383,17 @@
 String _
-nameT
+t
 ype = nu
@@ -769,29 +769,25 @@
 ue);%0A      _
-nameT
+t
 ype = value;
@@ -844,21 +844,17 @@
 )%7B%0A    _
-nameT
+t
 ype = Xe
@@ -1076,21 +1076,17 @@
 return _
-nameT
+t
 ype;%0A  %7D
@@ -1293,13 +1293,9 @@
 && _
-nameT
+t
 ype.

Unify typo for type attribute