Class JsonML
java.lang.Object
com.google.javascript.jscomp.jsonml.JsonML
Class which represents JsonML element according to the specification at
"http://code.google.com/p/es-lab/wiki/JsonMLASTFormat"
-
Constructor Summary
ConstructorDescriptionCreates a new element with a given type.Creates a new element. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the given JsonML element at the given position in the list of children.void
appendChild
(JsonML element) Appends a given child element to the list of children.void
appendChildren
(Collection<? extends JsonML> elements) Appends a collection of children to the back of the list of children.int
Returns number of the children.void
Removes all elements from the list of children.getAttribute
(TagAttr name) Returns value associated with a given attribute.Returns a map with attributes and respective values.getChild
(int index) Returns child at a given position.Returns a list of all children.getChildren
(int fromIndex, int toIndex) Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.getType()
Returns type of the JsonML element.boolean
Returns true if the JsonML element has at least one child.void
setAttribute
(TagAttr name, Object value) Sets value for a given attribute.void
setAttributes
(Map<TagAttr, Object> attributes) Sets attributes of the JsonML element.void
Replaces the element at the given position in the list of children wit the given JsonML element.void
setChildren
(JsonML... children) Replaces all elements in the list of children with the given JsonML elements.void
setChildren
(List<JsonML> children) Replaces all elements in the list of children with the given list of JsonML elements..toString()
Prints a JsonML tree in a human readable format.
-
Constructor Details
-
JsonML
Creates a new element with a given type.- Parameters:
type
-
-
JsonML
Creates a new element.- Parameters:
type
- type of the elementchildren
- children to append to the element
-
JsonML
-
JsonML
-
JsonML
-
-
Method Details
-
addChild
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
Appends a given child element to the list of children.- Parameters:
element
- JsonML element to append
-
appendChildren
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
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
Returns a map with attributes and respective values. -
getChild
Returns child at a given position. -
getChildren
Returns a list of all children. -
getChildren
Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.- Parameters:
fromIndex
- low endpoint (inclusive)toIndex
- high endpoint (exclusive)
-
getType
Returns type of the JsonML element. -
hasChildren
public boolean hasChildren()Returns true if the JsonML element has at least one child. -
setAttribute
Sets value for a given attribute.- Parameters:
name
- name of the attributevalue
- value to associate with the attribute
-
setAttributes
Sets attributes of the JsonML element.- Parameters:
attributes
- map with attributes and their values
-
setChild
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
Replaces all elements in the list of children with the given JsonML elements.- Parameters:
children
- a comma separated list of JsonML elements
-
setChildren
Replaces all elements in the list of children with the given list of JsonML elements..- Parameters:
children
- a list of JsonML elements.
-
toString
-
toStringTree
Prints a JsonML tree in a human readable format.
-