Class JsonML

java.lang.Object
com.google.javascript.jscomp.jsonml.JsonML

public class JsonML extends Object
Class which represents JsonML element according to the specification at "http://code.google.com/p/es-lab/wiki/JsonMLASTFormat"
  • Constructor Details

    • JsonML

      public JsonML(TagType type)
      Creates a new element with a given type.
      Parameters:
      type -
    • JsonML

      public JsonML(TagType type, JsonML... children)
      Creates a new element.
      Parameters:
      type - type of the element
      children - children to append to the element
    • JsonML

      public JsonML(TagType type, List<? extends JsonML> children)
    • JsonML

      public JsonML(TagType type, Map<? extends TagAttr,?> attributes)
    • JsonML

      public JsonML(TagType type, Map<? extends TagAttr,?> attributes, List<? extends JsonML> children)
  • Method Details

    • addChild

      public void addChild(int index, JsonML element)
      Inserts the given JsonML element at the given position in the list of children.
      Parameters:
      index - index at which the given element is to be inserted
      element - JsonML element to be inserted
    • appendChild

      public void appendChild(JsonML element)
      Appends a given child element to the list of children.
      Parameters:
      element - JsonML element to append
    • appendChildren

      public void appendChildren(Collection<? extends JsonML> elements)
      Appends a collection of children to the back of the list of children.
      Parameters:
      elements - collection of JsonML elements to append
    • childrenSize

      public int childrenSize()
      Returns number of the children.
    • clearChildren

      public void clearChildren()
      Removes all elements from the list of children.
    • getAttribute

      public Object getAttribute(TagAttr name)
      Returns value associated with a given attribute.
      Parameters:
      name - name of the attribute
      Returns:
      associated value or null if the attribute is not present
    • getAttributes

      public Map<TagAttr,Object> getAttributes()
      Returns a map with attributes and respective values.
    • getChild

      public JsonML getChild(int index)
      Returns child at a given position.
    • getChildren

      public List<JsonML> getChildren()
      Returns a list of all children.
    • getChildren

      public List<JsonML> getChildren(int fromIndex, int toIndex)
      Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.
      Parameters:
      fromIndex - low endpoint (inclusive)
      toIndex - high endpoint (exclusive)
    • getType

      public TagType getType()
      Returns type of the JsonML element.
    • hasChildren

      public boolean hasChildren()
      Returns true if the JsonML element has at least one child.
    • setAttribute

      public void setAttribute(TagAttr name, Object value)
      Sets value for a given attribute.
      Parameters:
      name - name of the attribute
      value - value to associate with the attribute
    • setAttributes

      public void setAttributes(Map<TagAttr,Object> attributes)
      Sets attributes of the JsonML element.
      Parameters:
      attributes - map with attributes and their values
    • setChild

      public void setChild(int index, JsonML element)
      Replaces the element at the given position in the list of children wit the given JsonML element.
      Parameters:
      index - index of element to replace
      element - JsonML element to append
    • setChildren

      public void setChildren(JsonML... children)
      Replaces all elements in the list of children with the given JsonML elements.
      Parameters:
      children - a comma separated list of JsonML elements
    • setChildren

      public void setChildren(List<JsonML> children)
      Replaces all elements in the list of children with the given list of JsonML elements..
      Parameters:
      children - a list of JsonML elements.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringTree

      public String toStringTree()
      Prints a JsonML tree in a human readable format.