Class JavaExpression
- java.lang.Object
-
- org.checkerframework.dataflow.expression.JavaExpression
-
- Direct Known Subclasses:
ArrayAccess,ArrayCreation,BinaryOperation,ClassName,FieldAccess,FormalParameter,LocalVariable,MethodCall,ThisReference,UnaryOperation,Unknown,ValueLiteral
public abstract class JavaExpression extends java.lang.ObjectThis class represents a Java expression and its type. It does not represent all possible Java expressions (for example, it does not represent a ternary conditional expression?:; useUnknownfor 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.lang.model.type.TypeMirrortypeThe type of this expression.
-
Constructor Summary
Constructors Modifier Constructor Description protectedJavaExpression(javax.lang.model.type.TypeMirror type)Create a JavaExpression.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <R,P>
Raccept(JavaExpressionVisitor<R,P> visitor, P p)Accept method of the visitor pattern.JavaExpressionatConstructorInvocation(com.sun.source.tree.NewClassTree newClassTree)Viewpoint-adaptsthisto thenewClassTree.JavaExpressionatFieldAccess(JavaExpression receiver)Viewpoint-adaptsthisto a field access with receiverreceiver.JavaExpressionatMethodBody(com.sun.source.tree.MethodTree methodTree)Viewpoint-adaptsthisto themethodTreeby converting anyFormalParameterintoLocalVariables.JavaExpressionatMethodInvocation(com.sun.source.tree.MethodInvocationTree methodInvocationTree)Viewpoint-adaptsthisto themethodInvocationTree.JavaExpressionatMethodInvocation(MethodInvocationNode invocationNode)Viewpoint-adaptsthisto theinvocationNode.booleancontainsModifiableAliasOf(Store<?> store, JavaExpression other)Returns true if and only ifotherappears anywhere in this or an expression appears in this such thatothermight alias this expression, and that expression is modifiable.abstract booleancontainsOfClass(java.lang.Class<? extends JavaExpression> clazz)abstract booleancontainsSyntacticEqualJavaExpression(JavaExpression other)Returns true if and only if this contains a JavaExpression that is syntactically equal toother.booleancontainsUnknown()static ArrayAccessfromArrayAccess(ArrayAccessNode node)Returns the internal representation (asFieldAccess) of aFieldAccessNode.static JavaExpressionfromNode(Node receiverNode)We ignore operations such as widening and narrowing when computing the internal representation.static JavaExpressionfromNodeFieldAccess(FieldAccessNode node)Returns the Java expression for aFieldAccessNode.static JavaExpressionfromTree(com.sun.source.tree.ExpressionTree tree)Converts a javacExpressionTreeto a CF JavaExpression.static JavaExpressionfromVariableTree(com.sun.source.tree.VariableTree tree)Returns the Java expression corresponding to the given variable treetree.static java.util.List<FormalParameter>getFormalParameters(javax.lang.model.element.ExecutableElement methodEle)Returns the parameters ofmethodEleasFormalParameters.static JavaExpressiongetImplicitReceiver(javax.lang.model.element.Element ele)Returns the implicit receiver of ele.static java.util.List<JavaExpression>getParametersAsLocalVariables(javax.lang.model.element.ExecutableElement methodEle)Returns the parameters ofmethodEleasLocalVariables.static JavaExpressiongetPseudoReceiver(com.sun.source.util.TreePath path, javax.lang.model.type.TypeMirror enclosingType)Returns either a new ClassName or ThisReference JavaExpression object for the enclosingType.static JavaExpressiongetReceiver(com.sun.source.tree.ExpressionTree accessTree)Returns the receiver of the given invocation.javax.lang.model.type.TypeMirrorgetType()abstract booleanisDeterministic(AnnotationProvider provider)Returns true if the expression is deterministic.abstract booleanisUnassignableByOtherCode()Returns true if and only if the value this expression stands for cannot be changed (with respect to ==) by a method call.abstract booleanisUnmodifiableByOtherCode()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 booleanlistContainsSyntacticEqualJavaExpression(java.util.List<? extends @Nullable JavaExpression> list, JavaExpression other)Returns true if the given list contains a JavaExpression that is syntactically equal toother.static booleanlistIsDeterministic(java.util.List<? extends @Nullable JavaExpression> list, AnnotationProvider provider)Returns true if all the expressions in the list are deterministic.abstract booleansyntacticEquals(JavaExpression je)Returns true if and only if the two Java expressions are syntactically identical.static booleansyntacticEqualsList(java.util.List<? extends @Nullable JavaExpression> lst1, java.util.List<? extends @Nullable JavaExpression> lst2)Returns true if the corresponding list elements satisfysyntacticEquals(org.checkerframework.dataflow.expression.JavaExpression).java.lang.StringtoStringDebug()Format this verbosely, for debugging.
-
-
-
Method Detail
-
getType
public javax.lang.model.type.TypeMirror getType()
-
containsOfClass
public abstract boolean containsOfClass(java.lang.Class<? extends JavaExpression> clazz)
-
containsUnknown
public boolean containsUnknown()
-
isDeterministic
public abstract boolean isDeterministic(AnnotationProvider provider)
Returns true if the expression is deterministic.- Parameters:
provider- an annotation provider (a type factory)- Returns:
- true if this expression is deterministic
-
listIsDeterministic
public static boolean listIsDeterministic(java.util.List<? extends @Nullable JavaExpression> list, AnnotationProvider provider)
Returns true if all the expressions in the list are deterministic.- Parameters:
list- the list whose elements to testprovider- an annotation provider (a type factory)- Returns:
- true if all the expressions in the list are deterministic
-
isUnassignableByOtherCode
public 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. This is the case for local variables, the self reference, final field accesses whose receiver isisUnassignableByOtherCode(), and operations whose operands are allisUnmodifiableByOtherCode().- See Also:
isUnmodifiableByOtherCode()
-
isUnmodifiableByOtherCode
public 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.Approximately, this returns true if the expression is
isUnassignableByOtherCode()and its type is immutable.- See Also:
isUnassignableByOtherCode()
-
syntacticEquals
@EqualsMethod public abstract boolean syntacticEquals(JavaExpression je)
Returns true if and only if the two Java expressions are syntactically identical.This exists for use by
containsSyntacticEqualJavaExpression(org.checkerframework.dataflow.expression.JavaExpression).- Parameters:
je- the other Java expression to compare to this one- Returns:
- true if and only if the two Java expressions are syntactically identical
-
syntacticEqualsList
public static boolean syntacticEqualsList(java.util.List<? extends @Nullable JavaExpression> lst1, java.util.List<? extends @Nullable JavaExpression> lst2)
Returns true if the corresponding list elements satisfysyntacticEquals(org.checkerframework.dataflow.expression.JavaExpression).- Parameters:
lst1- the first list to comparelst2- the second list to compare- Returns:
- true if the corresponding list elements satisfy
syntacticEquals(org.checkerframework.dataflow.expression.JavaExpression)
-
containsSyntacticEqualJavaExpression
public abstract boolean containsSyntacticEqualJavaExpression(JavaExpression other)
Returns true if and only if this contains a JavaExpression that is syntactically equal toother.- Parameters:
other- the JavaExpression to search for- Returns:
- true if and only if this contains a JavaExpression that is syntactically equal to
other
-
listContainsSyntacticEqualJavaExpression
public static boolean listContainsSyntacticEqualJavaExpression(java.util.List<? extends @Nullable JavaExpression> list, JavaExpression other)
Returns true if the given list contains a JavaExpression that is syntactically equal toother.- Parameters:
list- the list in which to search for a matchother- the JavaExpression to search for- Returns:
- true if and only if the list contains a JavaExpression that is syntactically equal to
other
-
containsModifiableAliasOf
public boolean containsModifiableAliasOf(Store<?> store, JavaExpression other)
Returns true if and only ifotherappears anywhere in this or an expression appears in this such thatothermight 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'.
-
toStringDebug
public java.lang.String toStringDebug()
Format this verbosely, for debugging.- Returns:
- a verbose string representation of this
-
fromNodeFieldAccess
public static JavaExpression fromNodeFieldAccess(FieldAccessNode node)
Returns the Java expression for aFieldAccessNode. The result may containUnknownas receiver.- Parameters:
node- the FieldAccessNode to convert to a JavaExpression- Returns:
- the
FieldAccessorClassNamethat corresponds tonode
-
fromArrayAccess
public static ArrayAccess fromArrayAccess(ArrayAccessNode node)
Returns the internal representation (asFieldAccess) of aFieldAccessNode. The result may containUnknownas receiver.- Parameters:
node- the ArrayAccessNode to convert to a JavaExpression- Returns:
- the internal representation (as
FieldAccess) of aFieldAccessNode. Can containUnknownas receiver.
-
fromNode
public static JavaExpression fromNode(Node receiverNode)
We ignore operations such as widening and narrowing when computing the internal representation.- Parameters:
receiverNode- a node to convert to a JavaExpression- Returns:
- the internal representation of the given node. Might contain
Unknown.
-
fromTree
public static JavaExpression fromTree(com.sun.source.tree.ExpressionTree tree)
Converts a javacExpressionTreeto a CF JavaExpression. The result might containUnknown.We ignore operations such as widening and narrowing when computing the JavaExpression.
- Parameters:
tree- a javac tree- Returns:
- a JavaExpression for the given javac tree
-
fromVariableTree
public static JavaExpression fromVariableTree(com.sun.source.tree.VariableTree tree)
Returns the Java expression corresponding to the given variable treetree.- Parameters:
tree- a variable tree- Returns:
- a JavaExpression for
tree
-
getParametersAsLocalVariables
public static java.util.List<JavaExpression> getParametersAsLocalVariables(javax.lang.model.element.ExecutableElement methodEle)
Returns the parameters ofmethodEleasLocalVariables.- Parameters:
methodEle- the method element- Returns:
- list of parameters as
LocalVariables
-
getFormalParameters
public static java.util.List<FormalParameter> getFormalParameters(javax.lang.model.element.ExecutableElement methodEle)
Returns the parameters ofmethodEleasFormalParameters.- Parameters:
methodEle- the method element- Returns:
- list of parameters as
FormalParameters
-
getReceiver
public static JavaExpression getReceiver(com.sun.source.tree.ExpressionTree accessTree)
Returns the receiver of the given invocation.- Parameters:
accessTree- a method or constructor invocation- Returns:
- the receiver of the given invocation
-
getImplicitReceiver
public static JavaExpression getImplicitReceiver(javax.lang.model.element.Element ele)
Returns the implicit receiver of 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.
When this returns a ThisReference, its type is the class that declares
ele, which is not necessarily the type ofthisat the invocation site.- Parameters:
ele- a field, method, or class- Returns:
- either a new ClassName or a new ThisReference depending on whether ele is static or not
-
getPseudoReceiver
public static JavaExpression getPseudoReceiver(com.sun.source.util.TreePath path, javax.lang.model.type.TypeMirror enclosingType)
Returns either a new ClassName or ThisReference JavaExpression object for the 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.
- Parameters:
path- a tree pathenclosingType- type of the enclosing type- Returns:
- a new
ClassNameorThisReferencethat is a JavaExpression object for the enclosingType
-
accept
public abstract <R,P> R accept(JavaExpressionVisitor<R,P> visitor, P p)
Accept method of the visitor pattern.- Type Parameters:
R- result type of the operationP- parameter type- Parameters:
visitor- the visitor to be applied to this JavaExpressionp- the parameter for this operation- Returns:
- the result of visiting this
-
atFieldAccess
public JavaExpression atFieldAccess(JavaExpression receiver)
Viewpoint-adaptsthisto a field access with receiverreceiver.- Parameters:
receiver- receiver of the field access- Returns:
- viewpoint-adapted version of this
-
atMethodBody
public final JavaExpression atMethodBody(com.sun.source.tree.MethodTree methodTree)
Viewpoint-adaptsthisto themethodTreeby converting anyFormalParameterintoLocalVariables.- Parameters:
methodTree- method declaration tree- Returns:
- viewpoint-adapted version of this
-
atMethodInvocation
public final JavaExpression atMethodInvocation(com.sun.source.tree.MethodInvocationTree methodInvocationTree)
Viewpoint-adaptsthisto themethodInvocationTree.- Parameters:
methodInvocationTree- method invocation- Returns:
- viewpoint-adapted version of this
-
atMethodInvocation
public final JavaExpression atMethodInvocation(MethodInvocationNode invocationNode)
Viewpoint-adaptsthisto theinvocationNode.- Parameters:
invocationNode- method invocation- Returns:
- viewpoint-adapted version of this
-
atConstructorInvocation
public JavaExpression atConstructorInvocation(com.sun.source.tree.NewClassTree newClassTree)
Viewpoint-adaptsthisto thenewClassTree.- Parameters:
newClassTree- constructor invocation- Returns:
- viewpoint-adapted version of this
-
-