Class NewExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.NewExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class NewExpr extends Object implements Expression
A constructor call expression - new Type(args), or outer.new Inner(args) when an enclosing instance is present.
-
-
Constructor Summary
Constructors Constructor Description NewExpr(Expression enclosingInstance, String className, List<Expression> arguments, SourceType type, SourceLocation location)Creates a constructor call, adopting the enclosing instance and arguments as children.NewExpr(String className)Creates a no-argument constructor call.NewExpr(String className, List<Expression> arguments)Creates a constructor call typed as a reference to the instantiated class.NewExpr(String className, List<Expression> arguments, SourceType type)Creates a constructor call at an unknown source location.NewExpr(String className, List<Expression> arguments, SourceType type, SourceLocation location)Creates a constructor call with no enclosing instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddArgument(Expression arg)Appends an argument, adopting it as a child.intgetArgumentCount()NodeList<Expression>getArguments()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.StringgetClassName()StringgetDescriptor()ExpressiongetEnclosingInstance()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.StringgetSimpleName()SourceTypegetType()Gets the inferred type of this expression.booleanisInnerClassCreation()voidsetEnclosingInstance(Expression enclosingInstance)Replaces the enclosing instance, reparenting the new one and releasing the old.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.StringtoString()NewExprwithDescriptor(String descriptor)Records the JVM constructor descriptor recovered from bytecode.NewExprwithEnclosingInstance(Expression enclosingInstance)Replaces the enclosing instance, reparenting the new one and releasing the old.-
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
-
NewExpr
public NewExpr(Expression enclosingInstance, String className, List<Expression> arguments, SourceType type, SourceLocation location)
Creates a constructor call, adopting the enclosing instance and arguments as children.- Parameters:
enclosingInstance- the outer instance for an inner class creation, or nullclassName- the instantiated class in internal formatarguments- the constructor arguments, or null for nonetype- the expression type; defaults to a reference type over className when nulllocation- the source location; defaults to UNKNOWN when null- Throws:
NullPointerException- if className is null
-
NewExpr
public NewExpr(String className, List<Expression> arguments, SourceType type, SourceLocation location)
Creates a constructor call with no enclosing instance.- Parameters:
className- the instantiated class in internal formatarguments- the constructor arguments, or null for nonetype- the expression type; defaults to a reference type over className when nulllocation- the source location; defaults to UNKNOWN when null- Throws:
NullPointerException- if className is null
-
NewExpr
public NewExpr(String className, List<Expression> arguments, SourceType type)
Creates a constructor call at an unknown source location.- Parameters:
className- the instantiated class in internal formatarguments- the constructor arguments, or null for nonetype- the expression type; defaults to a reference type over className when null- Throws:
NullPointerException- if className is null
-
NewExpr
public NewExpr(String className, List<Expression> arguments)
Creates a constructor call typed as a reference to the instantiated class.- Parameters:
className- the instantiated class in internal formatarguments- the constructor arguments, or null for none- Throws:
NullPointerException- if className is null
-
NewExpr
public NewExpr(String className)
Creates a no-argument constructor call.- Parameters:
className- the instantiated class in internal format- Throws:
NullPointerException- if className is null
-
-
Method Detail
-
getEnclosingInstance
public Expression getEnclosingInstance()
- Returns:
- the enclosing instance
-
setEnclosingInstance
public void setEnclosingInstance(Expression enclosingInstance)
Replaces the enclosing instance, reparenting the new one and releasing the old.- Parameters:
enclosingInstance- the outer instance, or null to drop it
-
getClassName
public String getClassName()
- Returns:
- the class name
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
withDescriptor
public NewExpr withDescriptor(String descriptor)
Records the JVM constructor descriptor recovered from bytecode.- Parameters:
descriptor- the constructor descriptor- Returns:
- this expression
-
getArguments
public NodeList<Expression> getArguments()
- Returns:
- the arguments
-
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.
-
addArgument
public void addArgument(Expression arg)
Appends an argument, adopting it as a child.- Parameters:
arg- the argument to append
-
getArgumentCount
public int getArgumentCount()
- Returns:
- the number of constructor arguments
-
getSimpleName
public String getSimpleName()
- Returns:
- the class name without its package, inner class segments kept
-
isInnerClassCreation
public boolean isInnerClassCreation()
- Returns:
- true if an enclosing instance is set
-
withEnclosingInstance
public NewExpr withEnclosingInstance(Expression enclosingInstance)
Replaces the enclosing instance, reparenting the new one and releasing the old.- Parameters:
enclosingInstance- the outer instance, or null to drop it- 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.
-
-