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>>
,Iterable<N>
,Collection<N>
,List<N>
,SequencedCollection<N>
public class NodeList<N extends Node>
extends Object
implements List<N>, 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 -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R,
A> R accept
(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
boolean
Inserts the node after afterThisNode.boolean
addAll
(int index, Collection<? extends N> c) void
boolean
addAll
(Collection<? extends N> c) Inserts the node before beforeThisNode.void
Inserts the node before all other nodes.void
Inserts the node after all other nodes.void
clear()
boolean
boolean
boolean
containsAll
(Collection<?> c) boolean
void
get
(int i) getFirst()
getLast()
Returns the parent node, orOptional.empty
if no parent is set.Returns the parent node from the perspective of the children of this node.int
hashCode()
void
ifNonEmpty
(Consumer<? super NodeList<N>> consumer) int
boolean
isEmpty()
boolean
boolean
isRegistered
(AstObserver observer) Was this observer registered? Note that equals is used to determine if the given observer was registered.iterator()
int
listIterator
(int index) nodeList
(Collection<X> nodes) 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
void
register
(AstObserver observer) Register an observer.remove
(int index) boolean
boolean
boolean
removeAll
(Collection<?> c) boolean
boolean
Replaces the first node that is equal to "old" with "replacement".void
replaceAll
(UnaryOperator<N> operator) boolean
retainAll
(Collection<?> c) private void
setAsParentNodeOf
(Node childNode) private void
setAsParentNodeOf
(List<? extends Node> childNodes) setParentNode
(Node parentNode) Sets the parentNodeint
size()
void
sort
(Comparator<? super N> comparator) subList
(int fromIndex, int toIndex) Object[]
toArray()
<T> T[]
toArray
(T[] a) 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 java.util.Collection
stream, toArray
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
-
Field Details
-
innerList
-
parentNode
-
observers
-
-
Constructor Details
-
NodeList
public NodeList() -
NodeList
-
NodeList
-
-
Method Details
-
add
-
own
-
remove
-
removeFirst
- Specified by:
removeFirst
in interfaceList<N extends Node>
- Specified by:
removeFirst
in interfaceSequencedCollection<N extends Node>
-
removeLast
- Specified by:
removeLast
in interfaceList<N extends Node>
- Specified by:
removeLast
in interfaceSequencedCollection<N extends Node>
-
nodeList
-
nodeList
-
nodeList
-
contains
-
size
public int size() -
get
-
iterator
-
set
-
remove
-
isEmpty
public boolean isEmpty() -
sort
-
addAll
-
add
-
addFirst
Inserts the node before all other nodes. -
addLast
Inserts the node after all other nodes. (This is simply an alias for add.) -
addAfter
Inserts the node after afterThisNode.- Throws:
IllegalArgumentException
- when afterThisNode is not in this list.
-
addBefore
Inserts the node before beforeThisNode.- Throws:
IllegalArgumentException
- when beforeThisNode is not in this list.
-
getFirst
-
getLast
-
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
Sets the parentNode- Specified by:
setParentNode
in interfaceHasParentNode<N extends Node>
- Parameters:
parentNode
- the parentNode- Returns:
- this, the NodeList
-
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
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
Description copied from interface:Visitable
Accept method for visitor support. -
forEach
-
contains
-
toArray
-
toArray
public <T> T[] toArray(T[] a) -
remove
-
containsAll
- Specified by:
containsAll
in interfaceCollection<N extends Node>
- Specified by:
containsAll
in interfaceList<N extends Node>
- See Also:
-
addAll
-
addAll
-
removeAll
-
retainAll
-
replaceAll
- Specified by:
replaceAll
in interfaceList<N extends Node>
- See Also:
-
removeIf
- Specified by:
removeIf
in interfaceCollection<N extends Node>
- See Also:
-
clear
public void clear() -
equals
-
hashCode
public int hashCode() -
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<N extends Node>
- See Also:
-
listIterator
- Specified by:
listIterator
in interfaceList<N extends Node>
- See Also:
-
listIterator
- Specified by:
listIterator
in interfaceList<N extends Node>
- See Also:
-
parallelStream
- Specified by:
parallelStream
in interfaceCollection<N extends Node>
- See Also:
-
subList
-
spliterator
- Specified by:
spliterator
in interfaceCollection<N extends Node>
- Specified by:
spliterator
in interfaceIterable<N extends Node>
- Specified by:
spliterator
in interfaceList<N extends Node>
- See Also:
-
notifyElementAdded
-
notifyElementRemoved
-
notifyElementReplaced
-
unregister
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
Description copied from interface:Observable
Register an observer.- Specified by:
register
in interfaceObservable
-
isRegistered
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
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()
-
ifNonEmpty
-
toNodeList
-
setAsParentNodeOf
-
setAsParentNodeOf
-
toString
-