Class JsonML
- java.lang.Object
-
- com.google.javascript.jscomp.jsonml.JsonML
-
public class JsonML extends java.lang.ObjectClass which represents JsonML element according to the specification at "http://code.google.com/p/es-lab/wiki/JsonMLASTFormat"
-
-
Constructor Summary
Constructors Constructor Description JsonML(TagType type)Creates a new element with a given type.JsonML(TagType type, JsonML... children)Creates a new element.JsonML(TagType type, java.util.List<? extends JsonML> children)JsonML(TagType type, java.util.Map<? extends TagAttr,?> attributes)JsonML(TagType type, java.util.Map<? extends TagAttr,?> attributes, java.util.List<? extends JsonML> children)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(int index, JsonML element)Inserts the given JsonML element at the given position in the list of children.voidappendChild(JsonML element)Appends a given child element to the list of children.voidappendChildren(java.util.Collection<? extends JsonML> elements)Appends a collection of children to the back of the list of children.intchildrenSize()Returns number of the children.voidclearChildren()Removes all elements from the list of children.java.lang.ObjectgetAttribute(TagAttr name)Returns value associated with a given attribute.java.util.Map<TagAttr,java.lang.Object>getAttributes()Returns a map with attributes and respective values.JsonMLgetChild(int index)Returns child at a given position.java.util.List<JsonML>getChildren()Returns a list of all children.java.util.List<JsonML>getChildren(int fromIndex, int toIndex)Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.TagTypegetType()Returns type of the JsonML element.booleanhasChildren()Returns true if the JsonML element has at least one child.voidsetAttribute(TagAttr name, java.lang.Object value)Sets value for a given attribute.voidsetAttributes(java.util.Map<TagAttr,java.lang.Object> attributes)Sets attributes of the JsonML element.voidsetChild(int index, JsonML element)Replaces the element at the given position in the list of children wit the given JsonML element.voidsetChildren(JsonML... children)Replaces all elements in the list of children with the given JsonML elements.voidsetChildren(java.util.List<JsonML> children)Replaces all elements in the list of children with the given list of JsonML elements..java.lang.StringtoString()java.lang.StringtoStringTree()Prints a JsonML tree in a human readable format.
-
-
-
Method Detail
-
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 insertedelement- 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(java.util.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 java.lang.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 java.util.Map<TagAttr,java.lang.Object> getAttributes()
Returns a map with attributes and respective values.
-
getChild
public JsonML getChild(int index)
Returns child at a given position.
-
getChildren
public java.util.List<JsonML> getChildren()
Returns a list of all children.
-
getChildren
public java.util.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, java.lang.Object value)
Sets value for a given attribute.- Parameters:
name- name of the attributevalue- value to associate with the attribute
-
setAttributes
public void setAttributes(java.util.Map<TagAttr,java.lang.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 replaceelement- 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(java.util.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toStringTree
public java.lang.String toStringTree()
Prints a JsonML tree in a human readable format.
-
-