Class AstNode
- java.lang.Object
-
- com.strobel.core.Freezable
-
- com.strobel.decompiler.languages.java.ast.AstNode
-
- All Implemented Interfaces:
UserDataStore
,IFreezable
,INode
,java.lang.Cloneable
- Direct Known Subclasses:
ArraySpecifier
,AstNode.NullAstNode
,AstNode.PatternPlaceholder
,AstType
,CaseLabel
,CatchClause
,Comment
,CompilationUnit
,EntityDeclaration
,Expression
,Identifier
,ImportDeclaration
,JavaTokenNode
,NewLineNode
,PackageDeclaration
,Statement
,SwitchExpressionArm
,SwitchSection
,TextNode
,TypeParameterDeclaration
,VariableInitializer
public abstract class AstNode extends Freezable implements INode, UserDataStore, java.lang.Cloneable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AstNode.NullAstNode
private static class
AstNode.PatternPlaceholder
-
Field Summary
Fields Modifier and Type Field Description private UserDataStore
_dataStore
private AstNode
_firstChild
private AstNode
_lastChild
private AstNode
_nextSibling
private AstNode
_parent
private AstNode
_previousSibling
protected static int
AST_NODE_USED_FLAGS
protected int
flags
(package private) static int
FROZEN_BIT
static AstNode
NULL
(package private) static int
ROLE_INDEX_MASK
(package private) static Role<AstNode>
ROOT_ROLE
-
Fields inherited from interface com.strobel.decompiler.patterns.INode
CHILD_ITERATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AstNode()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <T,R>
RacceptVisitor(IAstVisitor<? super T,? extends R> visitor, T data)
<T extends AstNode>
voidaddChild(T child, Role<? extends T> role)
(package private) void
addChildUnsafe(AstNode child, Role<?> role)
AstNode
clone()
boolean
contains(int line, int column)
boolean
contains(TextLocation location)
private static <T> void
copyKey(AstNode source, AstNode target, Key<T> key)
void
copyUserDataFrom(AstNode source)
(package private) java.lang.String
debugToString()
static AstNode
forPattern(Pattern pattern)
protected void
freezeCore()
java.lang.Iterable<AstNode>
getAncestors()
<T extends AstNode>
java.lang.Iterable<T>getAncestors(java.lang.Class<T> type)
java.lang.Iterable<AstNode>
getAncestorsAndSelf()
<T extends AstNode>
TgetChildByRole(Role<? extends T> role)
java.lang.Iterable<AstNode>
getChildren()
<T extends AstNode>
AstNodeCollection<T>getChildrenByRole(Role<? extends T> role)
java.lang.Iterable<AstNode>
getDescendants()
java.lang.Iterable<AstNode>
getDescendantsAndSelf()
TextLocation
getEndLocation()
AstNode
getFirstChild()
AstNode
getLastChild()
AstNode
getNextNode()
AstNode
getNextSibling()
<T extends AstNode>
TgetNextSibling(Role<? extends T> role)
abstract NodeType
getNodeType()
AstNode
getParent()
<T extends AstNode>
TgetParent(java.lang.Class<T> nodeType)
AstNode
getPreviousNode()
AstNode
getPreviousSibling()
<T extends AstNode>
TgetPreviousSibling(Role<? extends T> role)
Region
getRegion()
Role<? extends AstNode>
getRole()
TextLocation
getStartLocation()
java.lang.String
getText()
java.lang.String
getText(JavaFormattingOptions options)
<T> T
getUserData(Key<T> key)
boolean
hasChildren()
<T extends AstNode>
voidinsertChildAfter(AstNode previousSibling, T child, Role<? extends T> role)
<T extends AstNode>
voidinsertChildBefore(AstNode nextSibling, T child, Role<? extends T> role)
(package private) void
insertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role<?> role)
<T extends AstNode>
voidinsertChildrenAfter(AstNode nextSibling, Role<? extends T> role, T... children)
<T extends AstNode>
voidinsertChildrenBefore(AstNode nextSibling, Role<? extends T> role, T... children)
boolean
isAncestorOf(AstNode node)
boolean
isAncestorOf(AstNode node, AstNode stopAt)
boolean
isDescendantOf(AstNode node)
boolean
isInside(int line, int column)
boolean
isInside(TextLocation location)
static boolean
isLoop(AstNode statement)
boolean
isNull()
boolean
isReference()
static boolean
isUnconditionalBranch(AstNode statement)
OptionalNode
makeOptional()
Match
match(INode other)
boolean
matches(INode other)
abstract boolean
matches(INode other, Match match)
boolean
matchesCollection(Role<?> role, INode position, Match match, BacktrackingInfo backtrackingInfo)
protected static boolean
matchString(java.lang.String pattern, java.lang.String text)
<T> void
putUserData(Key<T> key, T value)
<T> T
putUserDataIfAbsent(Key<T> key, T value)
void
remove()
<T> boolean
replace(Key<T> key, T oldValue, T newValue)
void
replaceWith(AstNode newNode)
<T extends AstNode>
TreplaceWith(Function<? super AstNode,? extends T> replaceFunction)
protected <T extends AstNode>
voidsetChildByRole(Role<? extends T> role, T newChild)
void
setRole(Role<?> role)
(package private) void
setRoleUnsafe(Role<?> role)
java.lang.String
toString()
NamedNode
withName(java.lang.String name)
-
Methods inherited from class com.strobel.core.Freezable
canFreeze, freeze, freezeIfUnfrozen, isFrozen, tryFreeze, verifyFrozen, verifyNotFrozen
-
-
-
-
Field Detail
-
ROLE_INDEX_MASK
static final int ROLE_INDEX_MASK
- See Also:
- Constant Field Values
-
FROZEN_BIT
static final int FROZEN_BIT
- See Also:
- Constant Field Values
-
AST_NODE_USED_FLAGS
protected static final int AST_NODE_USED_FLAGS
- See Also:
- Constant Field Values
-
flags
protected int flags
-
_parent
private AstNode _parent
-
_previousSibling
private AstNode _previousSibling
-
_nextSibling
private AstNode _nextSibling
-
_firstChild
private AstNode _firstChild
-
_lastChild
private AstNode _lastChild
-
NULL
public static final AstNode NULL
-
_dataStore
private final UserDataStore _dataStore
-
-
Method Detail
-
matchString
protected static boolean matchString(java.lang.String pattern, java.lang.String text)
-
isLoop
public static boolean isLoop(AstNode statement)
-
isUnconditionalBranch
public static boolean isUnconditionalBranch(AstNode statement)
-
setRoleUnsafe
final void setRoleUnsafe(Role<?> role)
-
acceptVisitor
public abstract <T,R> R acceptVisitor(IAstVisitor<? super T,? extends R> visitor, T data)
-
clone
public AstNode clone()
- Overrides:
clone
in classjava.lang.Object
-
copyUserDataFrom
public void copyUserDataFrom(AstNode source)
-
getParent
public final AstNode getParent()
-
getPreviousSibling
public final AstNode getPreviousSibling()
-
getLastChild
public final AstNode getLastChild()
-
getFirstChild
public final AstNode getFirstChild()
- Specified by:
getFirstChild
in interfaceINode
-
getNextSibling
public final AstNode getNextSibling()
- Specified by:
getNextSibling
in interfaceINode
-
hasChildren
public final boolean hasChildren()
-
getNextNode
public final AstNode getNextNode()
-
getPreviousNode
public final AstNode getPreviousNode()
-
getChildren
public final java.lang.Iterable<AstNode> getChildren()
-
isAncestorOf
public final boolean isAncestorOf(AstNode node)
-
isDescendantOf
public final boolean isDescendantOf(AstNode node)
-
getAncestors
public final <T extends AstNode> java.lang.Iterable<T> getAncestors(@NotNull java.lang.Class<T> type)
-
getAncestors
public final java.lang.Iterable<AstNode> getAncestors()
-
getAncestorsAndSelf
public final java.lang.Iterable<AstNode> getAncestorsAndSelf()
-
getDescendants
public final java.lang.Iterable<AstNode> getDescendants()
-
getDescendantsAndSelf
public final java.lang.Iterable<AstNode> getDescendantsAndSelf()
-
getChildrenByRole
@NotNull public final <T extends AstNode> AstNodeCollection<T> getChildrenByRole(Role<? extends T> role)
-
setChildByRole
protected final <T extends AstNode> void setChildByRole(Role<? extends T> role, T newChild)
-
getParent
public final <T extends AstNode> T getParent(java.lang.Class<T> nodeType)
-
insertChildrenBefore
@SafeVarargs public final <T extends AstNode> void insertChildrenBefore(AstNode nextSibling, Role<? extends T> role, T... children)
-
insertChildBefore
public final <T extends AstNode> void insertChildBefore(AstNode nextSibling, T child, Role<? extends T> role)
-
insertChildrenAfter
@SafeVarargs public final <T extends AstNode> void insertChildrenAfter(AstNode nextSibling, Role<? extends T> role, T... children)
-
insertChildAfter
public final <T extends AstNode> void insertChildAfter(AstNode previousSibling, T child, Role<? extends T> role)
-
insertChildBeforeUnsafe
final void insertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role<?> role)
-
remove
public final void remove()
-
replaceWith
public final void replaceWith(AstNode newNode)
-
replaceWith
public final <T extends AstNode> T replaceWith(Function<? super AstNode,? extends T> replaceFunction)
-
freezeCore
protected void freezeCore()
- Overrides:
freezeCore
in classFreezable
-
getNodeType
public abstract NodeType getNodeType()
-
isReference
public boolean isReference()
-
setRole
public final void setRole(Role<?> role)
-
matchesCollection
public boolean matchesCollection(Role<?> role, INode position, Match match, BacktrackingInfo backtrackingInfo)
- Specified by:
matchesCollection
in interfaceINode
-
withName
public NamedNode withName(java.lang.String name)
-
makeOptional
public OptionalNode makeOptional()
-
getStartLocation
public TextLocation getStartLocation()
-
getEndLocation
public TextLocation getEndLocation()
-
getRegion
public Region getRegion()
-
contains
public final boolean contains(int line, int column)
-
contains
public final boolean contains(TextLocation location)
-
isInside
public final boolean isInside(int line, int column)
-
isInside
public final boolean isInside(TextLocation location)
-
getText
public java.lang.String getText()
-
getText
public java.lang.String getText(JavaFormattingOptions options)
-
debugToString
java.lang.String debugToString()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getUserData
public final <T> T getUserData(Key<T> key)
- Specified by:
getUserData
in interfaceUserDataStore
-
putUserData
public final <T> void putUserData(Key<T> key, T value)
- Specified by:
putUserData
in interfaceUserDataStore
-
putUserDataIfAbsent
public final <T> T putUserDataIfAbsent(Key<T> key, T value)
- Specified by:
putUserDataIfAbsent
in interfaceUserDataStore
-
replace
public final <T> boolean replace(Key<T> key, T oldValue, T newValue)
- Specified by:
replace
in interfaceUserDataStore
-
-