Package com.github.javaparser.ast
Class NodeList<N extends Node>
- java.lang.Object
-
- com.github.javaparser.ast.NodeList<N>
-
- Type Parameters:
N
- the type of nodes contained.
- All Implemented Interfaces:
Observable
,Visitable
,HasParentNode<NodeList<N>>
,java.lang.Iterable<N>
,java.util.Collection<N>
,java.util.List<N>
public class NodeList<N extends Node> extends java.lang.Object implements java.util.List<N>, java.lang.Iterable<N>, HasParentNode<NodeList<N>>, Visitable, Observable
A list of nodes. It usually has a parent node. Unlike normal Nodes, this does not mean that it is a child of that parent. Instead, this list will make every node it contains a child of its parent. This way, a NodeList does not create an extra level inside the AST.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
NodeList.NodeListIterator
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<N>
innerList
private java.util.List<AstObserver>
observers
private Node
parentNode
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,A>
Raccept(GenericVisitor<R,A> v, A arg)
Accept method for visitor support.<A> void
accept(VoidVisitor<A> v, A arg)
Accept method for visitor support.void
add(int index, N node)
boolean
add(N node)
NodeList<N>
addAfter(N node, N afterThisNode)
Inserts the node after afterThisNode.boolean
addAll(int index, java.util.Collection<? extends N> c)
void
addAll(NodeList<N> otherList)
boolean
addAll(java.util.Collection<? extends N> c)
NodeList<N>
addBefore(N node, N beforeThisNode)
Inserts the node before beforeThisNode.void
addFirst(N node)
Inserts the node before all other nodes.void
addLast(N node)
Inserts the node after all other nodes.void
clear()
boolean
contains(java.lang.Object o)
boolean
contains(N node)
boolean
containsAll(java.util.Collection<?> c)
boolean
equals(java.lang.Object o)
void
forEach(java.util.function.Consumer<? super N> action)
N
get(int i)
N
getFirst()
N
getLast()
java.util.Optional<Node>
getParentNode()
Returns the parent node, orOptional.empty
if no parent is set.Node
getParentNodeForChildren()
Returns the parent node from the perspective of the children of this node.int
hashCode()
void
ifNonEmpty(java.util.function.Consumer<? super NodeList<N>> consumer)
int
indexOf(java.lang.Object o)
boolean
isEmpty()
boolean
isNonEmpty()
boolean
isRegistered(AstObserver observer)
Was this observer registered? Note that equals is used to determine if the given observer was registered.java.util.Iterator<N>
iterator()
int
lastIndexOf(java.lang.Object o)
java.util.ListIterator<N>
listIterator()
java.util.ListIterator<N>
listIterator(int index)
static <X extends Node>
NodeList<X>nodeList(NodeList<X> nodes)
static <X extends Node>
NodeList<X>nodeList(java.util.Collection<X> nodes)
static <X extends Node>
NodeList<X>nodeList(X... nodes)
private void
notifyElementAdded(int index, Node nodeAddedOrRemoved)
private void
notifyElementRemoved(int index, Node nodeAddedOrRemoved)
private void
notifyElementReplaced(int index, Node nodeAddedOrRemoved)
private void
own(N node)
java.util.stream.Stream<N>
parallelStream()
void
register(AstObserver observer)
Register an observer.N
remove(int index)
boolean
remove(Node node)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
N
removeFirst()
boolean
removeIf(java.util.function.Predicate<? super N> filter)
N
removeLast()
boolean
replace(N old, N replacement)
Replaces the first node that is equal to "old" with "replacement".void
replaceAll(java.util.function.UnaryOperator<N> operator)
boolean
retainAll(java.util.Collection<?> c)
N
set(int index, N element)
private void
setAsParentNodeOf(Node childNode)
private void
setAsParentNodeOf(java.util.List<? extends Node> childNodes)
NodeList<N>
setParentNode(Node parentNode)
Sets the parentNodeint
size()
void
sort(java.util.Comparator<? super N> comparator)
java.util.Spliterator<N>
spliterator()
java.util.List<N>
subList(int fromIndex, int toIndex)
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
static <T extends Node>
java.util.stream.Collector<T,NodeList<T>,NodeList<T>>toNodeList()
java.lang.String
toString()
void
unregister(AstObserver observer)
Unregister an observer.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
-
-
-
-
Field Detail
-
parentNode
private Node parentNode
-
observers
private final java.util.List<AstObserver> observers
-
-
Method Detail
-
add
public boolean add(N node)
-
own
private void own(N node)
-
remove
public boolean remove(Node node)
-
removeFirst
public N removeFirst()
-
removeLast
public N removeLast()
-
contains
public boolean contains(N node)
-
size
public int size()
-
iterator
public java.util.Iterator<N> iterator()
-
isEmpty
public boolean isEmpty()
-
sort
public void sort(java.util.Comparator<? super N> comparator)
-
add
public void add(int index, N node)
-
addFirst
public void addFirst(N node)
Inserts the node before all other nodes.
-
addLast
public void addLast(N node)
Inserts the node after all other nodes. (This is simply an alias for add.)
-
addAfter
public NodeList<N> addAfter(N node, N afterThisNode)
Inserts the node after afterThisNode.- Throws:
java.lang.IllegalArgumentException
- when afterThisNode is not in this list.
-
addBefore
public NodeList<N> addBefore(N node, N beforeThisNode)
Inserts the node before beforeThisNode.- Throws:
java.lang.IllegalArgumentException
- when beforeThisNode is not in this list.
-
getFirst
public N getFirst()
- Returns:
- the first node, or empty if the list is empty.
-
getLast
public N getLast()
- Returns:
- the last node, or empty if the list is empty.
-
getParentNode
public java.util.Optional<Node> getParentNode()
Description copied from interface:HasParentNode
Returns the parent node, orOptional.empty
if no parent is set.- Specified by:
getParentNode
in interfaceHasParentNode<N extends Node>
-
setParentNode
public NodeList<N> setParentNode(Node parentNode)
Sets the parentNode- Specified by:
setParentNode
in interfaceHasParentNode<N extends Node>
- Parameters:
parentNode
- the parentNode- Returns:
- this, the NodeList
-
getParentNodeForChildren
public Node getParentNodeForChildren()
Description copied from interface:HasParentNode
Returns the parent node from the perspective of the children of this node.That is, this method returns
this
for everything exceptNodeList
. ANodeList
returns its parent node instead. This is because aNodeList
sets the parent of all its children to its own parent node (seeNodeList
for details).- Specified by:
getParentNodeForChildren
in interfaceHasParentNode<N extends Node>
-
accept
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.- Specified by:
accept
in interfaceVisitable
- Type Parameters:
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitor- Parameters:
v
- the visitor implementationarg
- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
public <A> void accept(VoidVisitor<A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.
-
forEach
public void forEach(java.util.function.Consumer<? super N> action)
-
contains
public boolean contains(java.lang.Object o)
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
addAll
public boolean addAll(java.util.Collection<? extends N> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends N> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
replaceAll
public void replaceAll(java.util.function.UnaryOperator<N> operator)
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super N> filter)
-
clear
public void clear()
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
indexOf
public int indexOf(java.lang.Object o)
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
-
listIterator
public java.util.ListIterator<N> listIterator()
-
listIterator
public java.util.ListIterator<N> listIterator(int index)
-
parallelStream
public java.util.stream.Stream<N> parallelStream()
-
subList
public java.util.List<N> subList(int fromIndex, int toIndex)
-
spliterator
public java.util.Spliterator<N> spliterator()
-
notifyElementAdded
private void notifyElementAdded(int index, Node nodeAddedOrRemoved)
-
notifyElementRemoved
private void notifyElementRemoved(int index, Node nodeAddedOrRemoved)
-
notifyElementReplaced
private void notifyElementReplaced(int index, Node nodeAddedOrRemoved)
-
unregister
public void unregister(AstObserver observer)
Description copied from interface:Observable
Unregister an observer. If the given observer was not registered there are no effects.- Specified by:
unregister
in interfaceObservable
-
register
public void register(AstObserver observer)
Description copied from interface:Observable
Register an observer.- Specified by:
register
in interfaceObservable
-
isRegistered
public boolean isRegistered(AstObserver observer)
Description copied from interface:Observable
Was this observer registered? Note that equals is used to determine if the given observer was registered.- Specified by:
isRegistered
in interfaceObservable
-
replace
public boolean replace(N old, N replacement)
Replaces the first node that is equal to "old" with "replacement".- Returns:
- true if a replacement has happened.
-
isNonEmpty
public boolean isNonEmpty()
- Returns:
- the opposite of isEmpty()
-
toNodeList
public static <T extends Node> java.util.stream.Collector<T,NodeList<T>,NodeList<T>> toNodeList()
-
setAsParentNodeOf
private void setAsParentNodeOf(java.util.List<? extends Node> childNodes)
-
setAsParentNodeOf
private void setAsParentNodeOf(Node childNode)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-