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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R, A> Raccept(GenericVisitor<R,A> v, A arg)Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg)Accept method for visitor support.voidbooleanInserts the node after afterThisNode.booleanaddAll(int index, Collection<? extends N> c)voidbooleanaddAll(Collection<? extends N> c)Inserts the node before beforeThisNode.Inserts the node before all other nodes.Inserts the node after all other nodes.voidclear()booleanbooleanbooleancontainsAll(Collection<?> c)booleanvoidget(int i)getFirst()getLast()Returns the parent node, orOptional.emptyif no parent is set.Returns the parent node from the perspective of the children of this node.inthashCode()voidifNonEmpty(Consumer<? super NodeList<N>> consumer)intbooleanisEmpty()booleanbooleanisRegistered(AstObserver observer)Was this observer registered? Note that equals is used to determine if the given observer was registered.iterator()intlastIndexOf(Object o)listIterator(int index)nodeList(Collection<X> nodes)nodeList(X... nodes)voidregister(AstObserver observer)Register an observer.remove(int index)booleanbooleanbooleanremoveAll(Collection<?> c)booleanbooleanReplaces the first node that is equal to "old" with "replacement".voidreplaceAll(UnaryOperator<N> operator)booleanretainAll(Collection<?> c)setParentNode(Node parentNode)Sets the parentNodeintsize()voidsort(Comparator<? super N> comparator)subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)toString()voidunregister(AstObserver observer)Unregister an observer.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
stream, toArrayMethods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, hasParentNode, isDescendantOf
-
Constructor Details
-
NodeList
public NodeList() -
NodeList
-
NodeList
-
-
Method Details
-
add
-
remove
-
removeFirst
-
removeLast
-
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
- Returns:
- the first node, or empty if the list is empty.
-
getLast
- Returns:
- the last node, or empty if the list is empty.
-
getParentNode
Description copied from interface:HasParentNodeReturns the parent node, orOptional.emptyif no parent is set.- Specified by:
getParentNodein interfaceHasParentNode<N extends Node>
-
setParentNode
Sets the parentNode- Specified by:
setParentNodein interfaceHasParentNode<N extends Node>- Parameters:
parentNode- the parentNode- Returns:
- this, the NodeList
-
getParentNodeForChildren
Description copied from interface:HasParentNodeReturns the parent node from the perspective of the children of this node.That is, this method returns
thisfor everything exceptNodeList. ANodeListreturns its parent node instead. This is because aNodeListsets the parent of all its children to its own parent node (seeNodeListfor details).- Specified by:
getParentNodeForChildrenin interfaceHasParentNode<N extends Node>
-
accept
Description copied from interface:VisitableAccept method for visitor support.- Specified by:
acceptin 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:VisitableAccept method for visitor support. -
forEach
- Specified by:
forEachin interfaceIterable<N extends Node>- See Also:
Iterable.forEach(java.util.function.Consumer)
-
contains
- Specified by:
containsin interfaceCollection<N extends Node>- Specified by:
containsin interfaceList<N extends Node>- See Also:
List.contains(java.lang.Object)
-
toArray
- Specified by:
toArrayin interfaceCollection<N extends Node>- Specified by:
toArrayin interfaceList<N extends Node>- See Also:
List.toArray()
-
toArray
public <T> T[] toArray(T[] a)- Specified by:
toArrayin interfaceCollection<N extends Node>- Specified by:
toArrayin interfaceList<N extends Node>- See Also:
List.toArray(java.lang.Object[])
-
remove
- Specified by:
removein interfaceCollection<N extends Node>- Specified by:
removein interfaceList<N extends Node>- See Also:
List.remove(java.lang.Object)
-
containsAll
- Specified by:
containsAllin interfaceCollection<N extends Node>- Specified by:
containsAllin interfaceList<N extends Node>- See Also:
List.containsAll(java.util.Collection)
-
addAll
- Specified by:
addAllin interfaceCollection<N extends Node>- Specified by:
addAllin interfaceList<N extends Node>- See Also:
List.addAll(java.util.Collection)
-
addAll
- Specified by:
addAllin interfaceList<N extends Node>- See Also:
List.addAll(int, java.util.Collection)
-
removeAll
- Specified by:
removeAllin interfaceCollection<N extends Node>- Specified by:
removeAllin interfaceList<N extends Node>- See Also:
List.removeAll(java.util.Collection)
-
retainAll
- Specified by:
retainAllin interfaceCollection<N extends Node>- Specified by:
retainAllin interfaceList<N extends Node>- See Also:
List.retainAll(java.util.Collection)
-
replaceAll
- Specified by:
replaceAllin interfaceList<N extends Node>- See Also:
List.replaceAll(java.util.function.UnaryOperator)
-
removeIf
- Specified by:
removeIfin interfaceCollection<N extends Node>- See Also:
Collection.removeIf(java.util.function.Predicate)
-
clear
public void clear()- Specified by:
clearin interfaceCollection<N extends Node>- Specified by:
clearin interfaceList<N extends Node>- See Also:
List.clear()
-
equals
-
hashCode
public int hashCode() -
indexOf
- Specified by:
indexOfin interfaceList<N extends Node>- See Also:
List.indexOf(java.lang.Object)
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<N extends Node>- See Also:
List.lastIndexOf(java.lang.Object)
-
listIterator
- Specified by:
listIteratorin interfaceList<N extends Node>- See Also:
List.listIterator()
-
listIterator
- Specified by:
listIteratorin interfaceList<N extends Node>- See Also:
List.listIterator(int)
-
parallelStream
- Specified by:
parallelStreamin interfaceCollection<N extends Node>- See Also:
Collection.parallelStream()
-
subList
- Specified by:
subListin interfaceList<N extends Node>- See Also:
List.subList(int, int)
-
spliterator
- Specified by:
spliteratorin interfaceCollection<N extends Node>- Specified by:
spliteratorin interfaceIterable<N extends Node>- Specified by:
spliteratorin interfaceList<N extends Node>- See Also:
List.spliterator()
-
unregister
Description copied from interface:ObservableUnregister an observer. If the given observer was not registered there are no effects.- Specified by:
unregisterin interfaceObservable
-
register
Description copied from interface:ObservableRegister an observer.- Specified by:
registerin interfaceObservable
-
isRegistered
Description copied from interface:ObservableWas this observer registered? Note that equals is used to determine if the given observer was registered.- Specified by:
isRegisteredin 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
-
toString
-