Class MethodRefExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.MethodRefExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class MethodRefExpr extends Object implements Expression
A method reference expression - Type::method, expr::method or Type::new.
-
-
Constructor Summary
Constructors Constructor Description MethodRefExpr(Expression receiver, String methodName, String ownerClass, MethodRefKind kind, SourceType type)Creates a method reference with an unknown source position.MethodRefExpr(Expression receiver, String methodName, String ownerClass, MethodRefKind kind, SourceType type, SourceLocation location)Creates a method reference and adopts the receiver as a child.
-
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.static MethodRefExprarrayConstructorRef(SourceType arrayType)Creates an array constructor reference, int[]::new, taking the owner from the array type's source form.static MethodRefExprboundRef(Expression receiver, String methodName, String ownerClass, SourceType type)Creates a bound method reference, expr::method.static MethodRefExprconstructorRef(String ownerClass, SourceType type)Creates a constructor reference, ClassName::new.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.StringgetDescriptor()MethodRefKindgetKind()SourceLocationgetLocation()Gets the source location of this node.StringgetMethodName()StringgetOwnerClass()StringgetOwnerSimpleName()ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetReceiver()SourceTypegetType()Gets the inferred type of this expression.static MethodRefExprinstanceRef(String ownerClass, String methodName, SourceType type)Creates an unbound instance method reference, ClassName::instanceMethod.booleanisConstructorRef()voidsetMethodName(String methodName)Replaces the referenced method's name.voidsetParent(ASTNode parent)Sets the node this expression hangs under.voidsetReceiver(Expression receiver)Replaces the receiver, reparenting it and releasing the old one.static MethodRefExprstaticRef(String ownerClass, String methodName, SourceType type)Creates a static method reference, ClassName::staticMethod.StringtoString()MethodRefExprwithDescriptor(String descriptor)Attaches the JVM descriptor recovered for the referenced method.MethodRefExprwithMethodName(String methodName)Replaces the referenced method's name.MethodRefExprwithReceiver(Expression receiver)Replaces the receiver, reparenting it and releasing the old 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
-
MethodRefExpr
public MethodRefExpr(Expression receiver, String methodName, String ownerClass, MethodRefKind kind, SourceType type, SourceLocation location)
Creates a method reference and adopts the receiver as a child.- Parameters:
receiver- the bound receiver, or null for an unbound referencemethodName- the referenced method's name, or "new" for a constructorownerClass- internal name of the declaring classkind- which form of method reference this istype- the functional interface type the reference targetslocation- source position, or null for an unknown one- Throws:
NullPointerException- if methodName, ownerClass, kind or type is null
-
MethodRefExpr
public MethodRefExpr(Expression receiver, String methodName, String ownerClass, MethodRefKind kind, SourceType type)
Creates a method reference with an unknown source position.- Parameters:
receiver- the bound receiver, or null for an unbound referencemethodName- the referenced method's name, or "new" for a constructorownerClass- internal name of the declaring classkind- which form of method reference this istype- the functional interface type the reference targets- Throws:
NullPointerException- if methodName, ownerClass, kind or type is null
-
-
Method Detail
-
getReceiver
public Expression getReceiver()
- Returns:
- the receiver
-
setReceiver
public void setReceiver(Expression receiver)
Replaces the receiver, reparenting it and releasing the old one.- Parameters:
receiver- the new receiver, or null to unbind
-
getMethodName
public String getMethodName()
- Returns:
- the method name
-
setMethodName
public void setMethodName(String methodName)
Replaces the referenced method's name.- Parameters:
methodName- the new name
-
getOwnerClass
public String getOwnerClass()
- Returns:
- the owner class
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
withDescriptor
public MethodRefExpr withDescriptor(String descriptor)
Attaches the JVM descriptor recovered for the referenced method.- Parameters:
descriptor- the method descriptor- Returns:
- this expression
-
getKind
public MethodRefKind getKind()
- Returns:
- the kind
-
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)
Sets the node this expression hangs under.
-
staticRef
public static MethodRefExpr staticRef(String ownerClass, String methodName, SourceType type)
Creates a static method reference, ClassName::staticMethod.- Parameters:
ownerClass- internal name of the declaring classmethodName- the static method's nametype- the functional interface type the reference targets- Returns:
- the method reference
-
instanceRef
public static MethodRefExpr instanceRef(String ownerClass, String methodName, SourceType type)
Creates an unbound instance method reference, ClassName::instanceMethod.- Parameters:
ownerClass- internal name of the declaring classmethodName- the instance method's nametype- the functional interface type the reference targets- Returns:
- the method reference
-
boundRef
public static MethodRefExpr boundRef(Expression receiver, String methodName, String ownerClass, SourceType type)
Creates a bound method reference, expr::method.- Parameters:
receiver- the expression the reference is bound tomethodName- the instance method's nameownerClass- internal name of the declaring classtype- the functional interface type the reference targets- Returns:
- the method reference
-
constructorRef
public static MethodRefExpr constructorRef(String ownerClass, SourceType type)
Creates a constructor reference, ClassName::new.- Parameters:
ownerClass- internal name of the constructed classtype- the functional interface type the reference targets- Returns:
- the method reference
-
arrayConstructorRef
public static MethodRefExpr arrayConstructorRef(SourceType arrayType)
Creates an array constructor reference, int[]::new, taking the owner from the array type's source form.- Parameters:
arrayType- the array type being allocated- Returns:
- the method reference
-
withReceiver
public MethodRefExpr withReceiver(Expression receiver)
Replaces the receiver, reparenting it and releasing the old one.- Parameters:
receiver- the new receiver, or null to unbind- Returns:
- this expression
-
withMethodName
public MethodRefExpr withMethodName(String methodName)
Replaces the referenced method's name.- Parameters:
methodName- the new name- Returns:
- this expression
-
getOwnerSimpleName
public String getOwnerSimpleName()
- Returns:
- the owner class name without its package, inner class parts kept
-
isConstructorRef
public boolean isConstructorRef()
- Returns:
- true for an object or array constructor reference
-
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.
-
-