Class FieldAccessExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.FieldAccessExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class FieldAccessExpr extends Object implements Expression
A field access expression: obj.field or Type.staticField.
-
-
Constructor Summary
Constructors Constructor Description FieldAccessExpr(Expression receiver, String fieldName, String ownerClass, boolean isStatic, SourceType type)Creates a field access with an unknown source location.FieldAccessExpr(Expression receiver, String fieldName, String ownerClass, boolean isStatic, SourceType type, SourceLocation location)Creates a field access and reparents the receiver if present.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.StringgetDescriptor()StringgetFieldName()SourceLocationgetLocation()Gets the source location of this node.StringgetOwnerClass()StringgetOwnerSimpleName()ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetReceiver()SourceTypegetType()Gets the inferred type of this expression.static FieldAccessExprinstanceField(Expression receiver, String fieldName, String ownerClass, SourceType type)Creates an instance field access.booleanisStatic()voidsetFieldName(String fieldName)voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetReceiver(Expression receiver)Replaces the receiver, reparenting the new child.static FieldAccessExprstaticField(String ownerClass, String fieldName, SourceType type)Creates a static field access with no receiver.StringtoString()FieldAccessExprwithDescriptor(String descriptor)Records the JVM field descriptor recovered from bytecode.FieldAccessExprwithReceiver(Expression receiver)Replaces the receiver, reparenting the new child and releasing the former one.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
FieldAccessExpr
public FieldAccessExpr(Expression receiver, String fieldName, String ownerClass, boolean isStatic, SourceType type, SourceLocation location)
Creates a field access and reparents the receiver if present.- Parameters:
receiver- the receiver expression, or null for static accessfieldName- the field nameownerClass- the declaring class in internal formatisStatic- true for a static field accesstype- the field typelocation- the source location, or null for unknown- Throws:
NullPointerException- if fieldName, ownerClass, or type is null
-
FieldAccessExpr
public FieldAccessExpr(Expression receiver, String fieldName, String ownerClass, boolean isStatic, SourceType type)
Creates a field access with an unknown source location.- Parameters:
receiver- the receiver expression, or null for static accessfieldName- the field nameownerClass- the declaring class in internal formatisStatic- true for a static field accesstype- the field type- Throws:
NullPointerException- if fieldName, ownerClass, or type is null
-
-
Method Detail
-
getReceiver
public Expression getReceiver()
- Returns:
- the receiver
-
setReceiver
public void setReceiver(Expression receiver)
Replaces the receiver, reparenting the new child.- Parameters:
receiver- the new receiver, or null for static access
-
getFieldName
public String getFieldName()
- Returns:
- the field name
-
setFieldName
public void setFieldName(String fieldName)
- Parameters:
fieldName- the new field name
-
getOwnerClass
public String getOwnerClass()
- Returns:
- the owner class
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
withDescriptor
public FieldAccessExpr withDescriptor(String descriptor)
Records the JVM field descriptor recovered from bytecode.- Parameters:
descriptor- the field descriptor- Returns:
- this expression
-
isStatic
public boolean isStatic()
- Returns:
- whether static
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
staticField
public static FieldAccessExpr staticField(String ownerClass, String fieldName, SourceType type)
Creates a static field access with no receiver.- Parameters:
ownerClass- the declaring class in internal formatfieldName- the field nametype- the field type- Returns:
- the new field access
-
instanceField
public static FieldAccessExpr instanceField(Expression receiver, String fieldName, String ownerClass, SourceType type)
Creates an instance field access.- Parameters:
receiver- the receiver expressionfieldName- the field nameownerClass- the declaring class in internal formattype- the field type- Returns:
- the new field access
-
getOwnerSimpleName
public String getOwnerSimpleName()
- Returns:
- the simple name of the owner class, keeping inner-class segments
-
withReceiver
public FieldAccessExpr withReceiver(Expression receiver)
Replaces the receiver, reparenting the new child and releasing the former one.- Parameters:
receiver- the new receiver, or null for static access- Returns:
- this expression
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-