Top Description Fields Constructors Methods
com.github.javaparser.ast

public Class NodeList<N extends Node>

extends Object
implements List<N extends Node>, Iterable<N extends Node>, HasParentNode<NodeList<N extends Node>>, Visitable, Observable
Class Inheritance
All Implemented Interfaces
com.github.javaparser.ast.observer.Observable, com.github.javaparser.ast.visitor.Visitable, com.github.javaparser.HasParentNode, java.lang.Iterable, java.util.List, java.util.SequencedCollection, java.util.Collection
Type Parameters
<N>
the type of nodes contained.
Imports
com.github.javaparser.HasParentNode, com.github.javaparser.ast.observer.AstObserver, .Observable, com.github.javaparser.ast.visitor.GenericVisitor, .Visitable, .VoidVisitor, com.github.javaparser.metamodel.InternalProperty, java.util.*, java.util.function.*, java.util.stream.Collector, .Collectors, .Stream

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.

Field Summary

Modifier and TypeField and Description
private List<N>
private List<AstObserver>
private Node

Constructor Summary

AccessConstructor and Description
public
public
public
NodeList(N... n)

Method Summary

Modifier and TypeMethod and Description
public <R, A> R
accept(final GenericVisitor<R, A>
the visitor implementation
v
,
final A
the argument passed to the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public <A> void
accept(final VoidVisitor<A>
the visitor implementation
v
,
final A
any value relevant for the visitor (of type A)
arg
)

Implements com.github.javaparser.ast.visitor.Visitable.accept.

Accept method for visitor support.
public boolean
add(N
element to be appended to this list
node
)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).
public void
add(int
index at which the specified element is to be inserted
index
,
N
element to be inserted
node
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public NodeList<N>
addAfter(N node, N afterThisNode)

Inserts the node after afterThisNode.

public void
addAll(NodeList<N> otherList)

public boolean
addAll(Collection<? extends N>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
public boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<? extends N>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
public NodeList<N>
addBefore(N node, N beforeThisNode)

Inserts the node before beforeThisNode.

public NodeList<N>
addFirst(N
the element to be added
node
)

Overrides default java.util.List.addFirst.

Inserts the node before all other nodes.
public NodeList<N>
addLast(N
the element to be added.
node
)

Overrides default java.util.List.addLast.

Inserts the node after all other nodes.
public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).
public boolean
contains(N node)

public boolean
contains(Object
element whose presence in this list is to be tested
o
)

Implements java.util.List.contains.

Returns true if this list contains the specified element.
public boolean
containsAll(Collection<?>
collection to be checked for containment in this list
c
)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.
public boolean
equals(Object
the object to be compared for equality with this list
o
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals.

Compares the specified object with this list for equality.
public void
forEach(Consumer<? super N>
The action to be performed for each element
action
)

Overrides default java.lang.Iterable.forEach.

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
public N
get(int
index of the element to return
i
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
public Optional<Node>
getParentNode()

Implements com.github.javaparser.HasParentNode.getParentNode.

Returns the parent node, or Optional.empty if no parent is set.
public Node
getParentNodeForChildren()

Implements com.github.javaparser.HasParentNode.getParentNodeForChildren.

Returns the parent node from the perspective of the children of this node.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode.

Returns the hash code value for this list.
public void
ifNonEmpty(Consumer<? super NodeList<N>> consumer)

public int
indexOf(Object
element to search for
o
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.
public boolean

Returns:

the opposite of isEmpty()
isNonEmpty
()

public boolean
isRegistered(AstObserver observer)

Implements com.github.javaparser.ast.observer.Observable.isRegistered.

Was this observer registered?
public Iterator<N>
iterator()

Implements java.util.List.iterator, java.lang.Iterable.iterator.

Returns an iterator over the elements in this list in proper sequence.
public int
lastIndexOf(Object
element to search for
o
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<N>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<N>
listIterator(int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public static <X extends Node> NodeList<X>
nodeList(X... nodes)

public static <X extends Node> NodeList<X>
nodeList(Collection<X> nodes)

public static <X extends Node> NodeList<X>
nodeList(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)

public Stream<N>
parallelStream()

Overrides default java.util.Collection.parallelStream.

Returns a possibly parallel Stream with this collection as its source.
public void
public boolean
remove(Node node)

public N
remove(int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public boolean
remove(Object
element to be removed from this list, if present
o
)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).
public boolean
removeAll(Collection<?>
collection containing elements to be removed from this list
c
)

Implements java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).
public N
removeFirst()

Overrides default java.util.List.removeFirst.

Removes and returns the first element of this collection (optional operation).
public boolean
removeIf(Predicate<? super N>
a predicate which returns true for elements to be removed
filter
)

Overrides default java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate (optional operation).
public N
removeLast()

Overrides default java.util.List.removeLast.

Removes and returns the last element of this collection (optional operation).
public boolean

Returns:

true if a replacement has happened.
replace
(N old, N replacement)

Replaces the first node that is equal to "old" with "replacement".

public void
replaceAll(UnaryOperator<N>
the operator to apply to each element
operator
)

Overrides default java.util.List.replaceAll.

Replaces each element of this list with the result of applying the operator to that element (optional operation).
public boolean
retainAll(Collection<?>
collection containing elements to be retained in this list
c
)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).
public N
set(int
index of the element to replace
index
,
N
element to be stored at the specified position
element
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
private void
setAsParentNodeOf(List<? extends Node> childNodes)

private void
public NodeList<N>

Returns:

this, the NodeList
setParentNode
(Node
the parentNode
parentNode
)

Implements com.github.javaparser.HasParentNode.setParentNode.

Sets the parentNode
public int
size()

Implements java.util.List.size.

Returns the number of elements in this list.
public void
sort(Comparator<? super N>
the Comparator used to compare list elements. A null value indicates that the elements' natural ordering should be used
comparator
)

Overrides default java.util.List.sort.

Sorts this list according to the order induced by the specified Comparator (optional operation).
public Spliterator<N>
spliterator()

Overrides default java.util.List.spliterator, java.lang.Iterable.spliterator.

Creates a Spliterator over the elements in this list.
public List<N>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
public Object[]
toArray()

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).
public <T> T[]
toArray(T[]
the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
a
)

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
public static <T extends Node> Collector<T, NodeList<T>, NodeList<T>>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait