public abstract class JavaExpression extends Object
?:
; use
Unknown
for unrepresentable expressions).
This class's representation is like an AST: subparts are also expressions. For declared names (fields, local variables, and methods), it also contains an Element.
Each subclass represents a different type of expression, such as MethodCall
, ArrayAccess
, LocalVariable
, etc.
Modifier and Type | Field and Description |
---|---|
protected TypeMirror |
type
The type of this expression.
|
Modifier | Constructor and Description |
---|---|
protected |
JavaExpression(TypeMirror type)
Create a JavaExpression.
|
Modifier and Type | Method and Description |
---|---|
abstract <R,P> R |
accept(JavaExpressionVisitor<R,P> visitor,
P p)
Accept method of the visitor pattern.
|
JavaExpression |
atConstructorInvocation(NewClassTree newClassTree)
Viewpoint-adapts
this to the newClassTree . |
JavaExpression |
atFieldAccess(JavaExpression receiver)
Viewpoint-adapts
this to a field access with receiver receiver . |
JavaExpression |
atMethodBody(MethodTree methodTree)
Viewpoint-adapts
this to the methodTree by converting any FormalParameter into LocalVariable s. |
JavaExpression |
atMethodInvocation(MethodInvocationNode invocationNode)
Viewpoint-adapts
this to the invocationNode . |
JavaExpression |
atMethodInvocation(MethodInvocationTree methodInvocationTree)
Viewpoint-adapts
this to the methodInvocationTree . |
boolean |
containsModifiableAliasOf(Store<?> store,
JavaExpression other)
Returns true if and only if
other appears anywhere in this or an expression appears in
this such that other might alias this expression, and that expression is modifiable. |
abstract boolean |
containsOfClass(Class<? extends JavaExpression> clazz) |
abstract boolean |
containsSyntacticEqualJavaExpression(JavaExpression other)
Returns true if and only if this contains a JavaExpression that is syntactically equal to
other . |
boolean |
containsUnknown() |
static ArrayAccess |
fromArrayAccess(ArrayAccessNode node)
Returns the internal representation (as
FieldAccess ) of a FieldAccessNode . |
static JavaExpression |
fromNode(Node receiverNode)
We ignore operations such as widening and narrowing when computing the internal representation.
|
static JavaExpression |
fromNodeFieldAccess(FieldAccessNode node)
Returns the Java expression for a
FieldAccessNode . |
static JavaExpression |
fromTree(ExpressionTree tree)
Converts a javac
ExpressionTree to a CF JavaExpression. |
static JavaExpression |
fromVariableTree(VariableTree tree)
Returns the Java expression corresponding to the given variable tree
tree . |
static List<FormalParameter> |
getFormalParameters(ExecutableElement methodEle)
Returns the parameters of
methodEle as FormalParameter s. |
static JavaExpression |
getImplicitReceiver(Element ele)
Returns the implicit receiver of ele.
|
static List<JavaExpression> |
getParametersAsLocalVariables(ExecutableElement methodEle)
Returns the parameters of
methodEle as LocalVariable s. |
static JavaExpression |
getPseudoReceiver(TreePath path,
TypeMirror enclosingType)
Returns either a new ClassName or ThisReference JavaExpression object for the enclosingType.
|
static JavaExpression |
getReceiver(ExpressionTree accessTree)
Returns the receiver of the given invocation
|
TypeMirror |
getType() |
abstract boolean |
isDeterministic(AnnotationProvider provider)
Returns true if the expression is deterministic.
|
abstract boolean |
isUnassignableByOtherCode()
Returns true if and only if the value this expression stands for cannot be changed (with
respect to ==) by a method call.
|
abstract boolean |
isUnmodifiableByOtherCode()
Returns true if and only if the value this expression stands for cannot be changed by a method
call, including changes to any of its fields.
|
static boolean |
listContainsSyntacticEqualJavaExpression(List<? extends JavaExpression> list,
JavaExpression other)
Returns true if the given list contains a JavaExpression that is syntactically equal to
other . |
static boolean |
listIsDeterministic(List<? extends JavaExpression> list,
AnnotationProvider provider)
Returns true if all the expressions in the list are deterministic.
|
abstract boolean |
syntacticEquals(JavaExpression je)
Returns true if and only if the two Java expressions are syntactically identical.
|
String |
toStringDebug()
Format this verbosely, for debugging.
|
protected final TypeMirror type
protected JavaExpression(TypeMirror type)
type
- the type of the expressionpublic TypeMirror getType()
public abstract boolean containsOfClass(Class<? extends JavaExpression> clazz)
public boolean containsUnknown()
public abstract boolean isDeterministic(AnnotationProvider provider)
provider
- an annotation provider (a type factory)public static boolean listIsDeterministic(List<? extends JavaExpression> list, AnnotationProvider provider)
list
- the list whose elements to testprovider
- an annotation provider (a type factory)public abstract boolean isUnassignableByOtherCode()
isUnassignableByOtherCode()
, and operations whose
operands are all isUnmodifiableByOtherCode()
.isUnmodifiableByOtherCode()
public abstract boolean isUnmodifiableByOtherCode()
Approximately, this returns true if the expression is isUnassignableByOtherCode()
and
its type is immutable.
isUnassignableByOtherCode()
@EqualsMethod public abstract boolean syntacticEquals(JavaExpression je)
This exists for use by containsSyntacticEqualJavaExpression(org.checkerframework.dataflow.expression.JavaExpression)
.
je
- the other Java expression to compare to this onepublic abstract boolean containsSyntacticEqualJavaExpression(JavaExpression other)
other
.other
- the JavaExpression to search forother
public static boolean listContainsSyntacticEqualJavaExpression(List<? extends JavaExpression> list, JavaExpression other)
other
.list
- the list in which to search for a matchother
- the JavaExpression to search forother
public boolean containsModifiableAliasOf(Store<?> store, JavaExpression other)
other
appears anywhere in this or an expression appears in
this such that other
might alias this expression, and that expression is modifiable.
This is always true, except for cases where the Java type information prevents aliasing and none of the subexpressions can alias 'other'.
public String toStringDebug()
public static JavaExpression fromNodeFieldAccess(FieldAccessNode node)
FieldAccessNode
. The result may contain Unknown
as receiver.node
- the FieldAccessNode to convert to a JavaExpressionFieldAccess
or ClassName
that corresponds to node
public static ArrayAccess fromArrayAccess(ArrayAccessNode node)
FieldAccess
) of a FieldAccessNode
. The
result may contain Unknown
as receiver.node
- the ArrayAccessNode to convert to a JavaExpressionFieldAccess
) of a FieldAccessNode
. Can
contain Unknown
as receiver.public static JavaExpression fromNode(Node receiverNode)
receiverNode
- a node to convert to a JavaExpressionUnknown
.public static JavaExpression fromTree(ExpressionTree tree)
ExpressionTree
to a CF JavaExpression. The result might contain Unknown
.
We ignore operations such as widening and narrowing when computing the JavaExpression.
tree
- a javac treepublic static JavaExpression fromVariableTree(VariableTree tree)
tree
.tree
- a variable treetree
public static List<JavaExpression> getParametersAsLocalVariables(ExecutableElement methodEle)
methodEle
as LocalVariable
s.methodEle
- the method elementLocalVariable
spublic static List<FormalParameter> getFormalParameters(ExecutableElement methodEle)
methodEle
as FormalParameter
s.methodEle
- the method elementFormalParameter
spublic static JavaExpression getReceiver(ExpressionTree accessTree)
accessTree
- method or constructor invocationpublic static JavaExpression getImplicitReceiver(Element ele)
Returns either a new ClassName or a new ThisReference depending on whether ele is static or not. The passed element must be a field, method, or class.
ele
- a field, method, or classpublic static JavaExpression getPseudoReceiver(TreePath path, TypeMirror enclosingType)
The Tree should be an expression or a statement that does not have a receiver or an implicit receiver. For example, a local variable declaration.
path
- TreePath to treeenclosingType
- type of the enclosing typepublic abstract <R,P> R accept(JavaExpressionVisitor<R,P> visitor, P p)
R
- result type of the operationP
- parameter typevisitor
- the visitor to be applied to this JavaExpressionp
- the parameter for this operationpublic JavaExpression atFieldAccess(JavaExpression receiver)
this
to a field access with receiver receiver
.receiver
- receiver of the field accesspublic final JavaExpression atMethodBody(MethodTree methodTree)
this
to the methodTree
by converting any FormalParameter
into LocalVariable
s.methodTree
- method declaration treepublic final JavaExpression atMethodInvocation(MethodInvocationTree methodInvocationTree)
this
to the methodInvocationTree
.methodInvocationTree
- method invocationpublic final JavaExpression atMethodInvocation(MethodInvocationNode invocationNode)
this
to the invocationNode
.invocationNode
- method invocationpublic JavaExpression atConstructorInvocation(NewClassTree newClassTree)
this
to the newClassTree
.newClassTree
- constructor invocation