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>
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 Modifier and Type Class Description protected class
NodeList.NodeListIterator
-
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, Collection<? extends N> c)
void
addAll(NodeList<N> otherList)
boolean
addAll(Collection<? extends N> c)
NodeList<N>
addBefore(N node, N beforeThisNode)
Inserts the node before beforeThisNode.NodeList<N>
addFirst(N node)
Inserts the node before all other nodes.NodeList<N>
addLast(N node)
Inserts the node after all other nodes.void
clear()
boolean
contains(Object o)
boolean
contains(N node)
boolean
containsAll(Collection<?> c)
boolean
equals(Object o)
void
forEach(Consumer<? super N> action)
N
get(int i)
Optional<N>
getFirst()
Optional<N>
getLast()
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(Consumer<? super NodeList<N>> consumer)
int
indexOf(Object o)
boolean
isEmpty()
boolean
isNonEmpty()
boolean
isRegistered(AstObserver observer)
Was this observer registered?Iterator<N>
iterator()
int
lastIndexOf(Object o)
ListIterator<N>
listIterator()
ListIterator<N>
listIterator(int index)
static <X extends Node>
NodeList<X>nodeList(NodeList<X> nodes)
static <X extends Node>
NodeList<X>nodeList(Collection<X> nodes)
static <X extends Node>
NodeList<X>nodeList(X... nodes)
Stream<N>
parallelStream()
void
register(AstObserver observer)
Register an observer.N
remove(int index)
boolean
remove(Node node)
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
N
removeFirst()
boolean
removeIf(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(UnaryOperator<N> operator)
boolean
retainAll(Collection<?> c)
N
set(int index, N element)
NodeList<N>
setParentNode(Node parentNode)
Sets the parentNodeint
size()
void
sort(Comparator<? super N> comparator)
Spliterator<N>
spliterator()
List<N>
subList(int fromIndex, int toIndex)
Object[]
toArray()
<T> T[]
toArray(T[] a)
static <T extends Node>
Collector<T,NodeList<T>,NodeList<T>>toNodeList()
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 java.util.Collection
stream, toArray
-
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
-
-
-
-
Constructor Detail
-
NodeList
public NodeList()
-
NodeList
public NodeList(Collection<N> n)
-
NodeList
@SafeVarargs public NodeList(N... n)
-
-
Method Detail
-
add
public boolean add(N node)
-
remove
public boolean remove(Node node)
-
removeFirst
public N removeFirst()
-
removeLast
public N removeLast()
-
nodeList
@SafeVarargs public static <X extends Node> NodeList<X> nodeList(X... nodes)
-
nodeList
public static <X extends Node> NodeList<X> nodeList(Collection<X> nodes)
-
contains
public boolean contains(N node)
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
sort
public void sort(Comparator<? super N> comparator)
-
addLast
public NodeList<N> 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:
IllegalArgumentException
- when afterThisNode is not in this list.
-
addBefore
public NodeList<N> addBefore(N node, N beforeThisNode)
Inserts the node before beforeThisNode.- Throws:
IllegalArgumentException
- when beforeThisNode is not in this list.
-
getParentNode
public 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(Consumer<? super N> action)
- Specified by:
forEach
in interfaceIterable<N extends Node>
- See Also:
Iterable.forEach(java.util.function.Consumer)
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<N extends Node>
- Specified by:
contains
in interfaceList<N extends Node>
- See Also:
List.contains(java.lang.Object)
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<N extends Node>
- Specified by:
toArray
in interfaceList<N extends Node>
- See Also:
List.toArray()
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<N extends Node>
- Specified by:
toArray
in interfaceList<N extends Node>
- See Also:
List.toArray(java.lang.Object[])
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<N extends Node>
- Specified by:
remove
in interfaceList<N extends Node>
- See Also:
List.remove(java.lang.Object)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<N extends Node>
- Specified by:
containsAll
in interfaceList<N extends Node>
- See Also:
List.containsAll(java.util.Collection)
-
addAll
public boolean addAll(Collection<? extends N> c)
- Specified by:
addAll
in interfaceCollection<N extends Node>
- Specified by:
addAll
in interfaceList<N extends Node>
- See Also:
List.addAll(java.util.Collection)
-
addAll
public boolean addAll(int index, Collection<? extends N> c)
- Specified by:
addAll
in interfaceList<N extends Node>
- See Also:
List.addAll(int, java.util.Collection)
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<N extends Node>
- Specified by:
removeAll
in interfaceList<N extends Node>
- See Also:
List.removeAll(java.util.Collection)
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<N extends Node>
- Specified by:
retainAll
in interfaceList<N extends Node>
- See Also:
List.retainAll(java.util.Collection)
-
replaceAll
public void replaceAll(UnaryOperator<N> operator)
- Specified by:
replaceAll
in interfaceList<N extends Node>
- See Also:
List.replaceAll(java.util.function.UnaryOperator)
-
removeIf
public boolean removeIf(Predicate<? super N> filter)
- Specified by:
removeIf
in interfaceCollection<N extends Node>
- See Also:
Collection.removeIf(java.util.function.Predicate)
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<N extends Node>
- Specified by:
clear
in interfaceList<N extends Node>
- See Also:
List.clear()
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
indexOf
public int indexOf(Object o)
- Specified by:
indexOf
in interfaceList<N extends Node>
- See Also:
List.indexOf(java.lang.Object)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interfaceList<N extends Node>
- See Also:
List.lastIndexOf(java.lang.Object)
-
listIterator
public ListIterator<N> listIterator()
- Specified by:
listIterator
in interfaceList<N extends Node>
- See Also:
List.listIterator()
-
listIterator
public ListIterator<N> listIterator(int index)
- Specified by:
listIterator
in interfaceList<N extends Node>
- See Also:
List.listIterator(int)
-
parallelStream
public Stream<N> parallelStream()
- Specified by:
parallelStream
in interfaceCollection<N extends Node>
- See Also:
Collection.parallelStream()
-
subList
public List<N> subList(int fromIndex, int toIndex)
- Specified by:
subList
in interfaceList<N extends Node>
- See Also:
List.subList(int, int)
-
spliterator
public Spliterator<N> 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:
List.spliterator()
-
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()
-
-