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 |
---|---|
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(AnnotationProvider provider,
ArrayAccessNode node)
Returns the internal representation (as
FieldAccess ) of a FieldAccessNode . |
static JavaExpression |
fromNode(AnnotationProvider provider,
Node node)
We ignore operations such as widening and narrowing when computing the internal
representation.
|
static JavaExpression |
fromNode(AnnotationProvider provider,
Node receiverNode,
boolean allowNonDeterministic)
We ignore operations such as widening and narrowing when computing the internal
representation.
|
static FieldAccess |
fromNodeFieldAccess(AnnotationProvider provider,
FieldAccessNode node)
Returns the internal representation (as
FieldAccess ) of a FieldAccessNode . |
static JavaExpression |
fromTree(AnnotationProvider provider,
ExpressionTree tree)
Converts a javac
ExpressionTree to a CF JavaExpression. |
static JavaExpression |
fromTree(AnnotationProvider provider,
ExpressionTree tree,
boolean allowNonDeterministic)
Converts a javac
ExpressionTree to a CF JavaExpression. |
static JavaExpression |
getImplicitReceiver(Element ele)
Returns the implicit receiver of ele.
|
static @Nullable List<JavaExpression> |
getParametersOfEnclosingMethod(AnnotationProvider annotationProvider,
TreePath path)
Returns the formal parameters of the method in which path is enclosed.
|
static JavaExpression |
getPseudoReceiver(TreePath path,
TypeMirror enclosingType)
Returns either a new ClassName or ThisReference JavaExpression object for the enclosingType.
|
static JavaExpression |
getReceiver(ExpressionTree accessTree,
AnnotationProvider provider)
Returns the receiver of ele, whether explicit or implicit.
|
TypeMirror |
getType() |
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 . |
abstract boolean |
syntacticEquals(JavaExpression je)
Returns true if and only if the two Java expressions are syntactically identical.
|
String |
toStringDebug()
Print 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 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
.
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 FieldAccess fromNodeFieldAccess(AnnotationProvider provider, FieldAccessNode node)
FieldAccess
) of a FieldAccessNode
.
The result may contain Unknown
as receiver.FieldAccess
) of a FieldAccessNode
.
Can contain Unknown
as receiver.public static ArrayAccess fromArrayAccess(AnnotationProvider provider, ArrayAccessNode node)
FieldAccess
) of a FieldAccessNode
.
The result may contain Unknown
as receiver.FieldAccess
) of a FieldAccessNode
.
Can contain Unknown
as receiver.public static JavaExpression fromNode(AnnotationProvider provider, Node node)
public static JavaExpression fromNode(AnnotationProvider provider, Node receiverNode, boolean allowNonDeterministic)
public static JavaExpression fromTree(AnnotationProvider provider, ExpressionTree tree)
ExpressionTree
to a CF JavaExpression. The result might contain
Unknown
.provider
- the annotation provider (for example, an AnnotatedTypeFactory
)tree
- a javac treepublic static JavaExpression fromTree(AnnotationProvider provider, ExpressionTree tree, boolean allowNonDeterministic)
ExpressionTree
to a CF JavaExpression. The result might contain
Unknown
.
We ignore operations such as widening and narrowing when computing the JavaExpression.
provider
- the annotation provider (for example, an AnnotatedTypeFactory
)tree
- a javac treeallowNonDeterministic
- if false, convert nondeterministic method calls to Unknown
public static @Nullable List<JavaExpression> getParametersOfEnclosingMethod(AnnotationProvider annotationProvider, TreePath path)
annotationProvider
- annotationProviderpath
- TreePath that is enclosed by the methodnull
otherwisepublic static JavaExpression getReceiver(ExpressionTree accessTree, AnnotationProvider provider)
accessTree
- method or constructor invocationprovider
- an AnnotationProviderpublic 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 type