public abstract class Node extends Object implements Cloneable, HasParentNode<Node>, Visitable
Modifier and Type | Class and Description |
---|---|
static class |
Node.ObserverRegistrationMode
Different registration mode for observers on nodes.
|
Modifier and Type | Field and Description |
---|---|
static int |
ABSOLUTE_BEGIN_LINE |
static int |
ABSOLUTE_END_LINE |
static Comparator<Node> |
NODE_BY_BEGIN_POSITION
This can be used to sort nodes on position.
|
protected static PrettyPrinterConfiguration |
prettyPrinterNoCommentsConfiguration |
Modifier and Type | Method and Description |
---|---|
void |
addOrphanComment(Comment comment) |
Node |
clone() |
<N extends Node> |
containsWithin(N other) |
boolean |
equals(Object obj) |
List<Comment> |
getAllContainedComments()
This is the list of Comment which are contained in the Node either because
they are properly associated to one of its children or because they are floating
around inside the Node
|
Optional<Position> |
getBegin()
The begin position of this node in the source file.
|
List<Node> |
getChildNodes()
Contains all nodes that have this node set as their parent.
|
Comment |
getComment()
This is a comment associated with this node.
|
<M> M |
getData(DataKey<M> key)
Gets data for this component using the given key.
|
Optional<Position> |
getEnd()
The end position of this node in the source file.
|
List<NodeList<?>> |
getNodeLists()
The list of NodeLists owned by this node.
|
<N extends Node> |
getNodesByType(Class<N> clazz)
Recursively finds all nodes of a certain type.
|
List<Comment> |
getOrphanComments()
This is a list of Comment which are inside the node and are not associated
with any meaningful AST Node.
|
Optional<Node> |
getParentNode()
Return the parent node or null, if no parent is set.
|
Node |
getParentNodeForChildren()
this for everything except NodeLists.
|
Optional<Range> |
getRange() |
boolean |
hasComment() |
int |
hashCode() |
boolean |
isPositionedAfter(Position position)
Deprecated.
|
boolean |
isPositionedBefore(Position position)
Deprecated.
|
boolean |
isRegistered(AstObserver observer)
Was this observer registered?
Note that equals is used to determine if the given observer was registered.
|
protected <P> void |
notifyPropertyChange(ObservableProperty property,
P oldValue,
P newValue) |
void |
register(AstObserver observer)
Register an observer.
|
void |
register(AstObserver observer,
Node.ObserverRegistrationMode mode)
Register a new observer for the given node.
|
void |
registerForSubtree(AstObserver observer)
Register the observer for the current node and all the contained node and nodelists, recursively.
|
boolean |
remove()
Try to remove this node from the parent
|
protected void |
setAsParentNodeOf(NodeList<? extends Node> list) |
Node |
setBlockComment(String comment)
Use this to store additional information to this node.
|
Node |
setComment(Comment comment)
Use this to store additional information to this node.
|
<M> void |
setData(DataKey<M> key,
M object)
Sets data for this component using the given key.
|
Node |
setLineComment(String comment)
Use this to store additional information to this node.
|
Node |
setParentNode(Node parentNode)
Assign a new parent to this node, removing it
from the list of children of the previous parent, if any.
|
Node |
setRange(Range range) |
String |
toString()
Return the String representation of this node.
|
String |
toString(PrettyPrinterConfiguration prettyPrinterConfiguration) |
void |
tryAddImportToParentCompilationUnit(Class<?> clazz) |
void |
unregister(AstObserver observer)
Unregister an observer.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
getAncestorOfType, setAsParentNodeOf, setAsParentNodeOf
public static Comparator<Node> NODE_BY_BEGIN_POSITION
protected static final PrettyPrinterConfiguration prettyPrinterNoCommentsConfiguration
public static final int ABSOLUTE_BEGIN_LINE
public static final int ABSOLUTE_END_LINE
public Node(Range range)
public final Comment getComment()
public Optional<Range> getRange()
public Node setRange(Range range)
range
- the range of characters in the source code that this node covers.
null can be used to indicate that no range information is known,
or that it is not of interest.public final Node setComment(Comment comment)
comment
- to be setpublic final Node setLineComment(String comment)
comment
- to be setpublic final Node setBlockComment(String comment)
comment
- to be setpublic final String toString()
public final String toString(PrettyPrinterConfiguration prettyPrinterConfiguration)
public Optional<Node> getParentNode()
HasParentNode
getParentNode
in interface HasParentNode<Node>
public List<Node> getChildNodes()
public <N extends Node> boolean containsWithin(N other)
public void addOrphanComment(Comment comment)
public List<Comment> getOrphanComments()
public List<Comment> getAllContainedComments()
public Node setParentNode(Node parentNode)
setParentNode
in interface HasParentNode<Node>
parentNode
- node to be set as parent@Deprecated public boolean isPositionedAfter(Position position)
@Deprecated public boolean isPositionedBefore(Position position)
public boolean hasComment()
public void tryAddImportToParentCompilationUnit(Class<?> clazz)
public <N extends Node> List<N> getNodesByType(Class<N> clazz)
clazz
- the type of node to find.public <M> M getData(DataKey<M> key)
M
- The type of the data.key
- The key for the dataDataKey
public <M> void setData(DataKey<M> key, M object)
DataKey
.M
- The type of datakey
- The singleton key for the dataobject
- The data objectIllegalArgumentException
DataKey
public boolean remove()
RuntimeException
- if it fails in an unexpected waypublic Node getParentNodeForChildren()
HasParentNode
getParentNodeForChildren
in interface HasParentNode<Node>
protected <P> void notifyPropertyChange(ObservableProperty property, P oldValue, P newValue)
public void unregister(AstObserver observer)
Observable
unregister
in interface Observable
public void register(AstObserver observer)
Observable
register
in interface Observable
public void register(AstObserver observer, Node.ObserverRegistrationMode mode)
public void registerForSubtree(AstObserver observer)
public boolean isRegistered(AstObserver observer)
Observable
isRegistered
in interface Observable
Copyright © 2007–2016. All rights reserved.