Package org.sonar.java.model
Class ExpressionUtils
java.lang.Object
org.sonar.java.model.ExpressionUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic IdentifierTree
static MethodTree
getEnclosingElement
(ExpressionTree expr, Tree.Kind... kinds) static MethodTree
Return the first enclosing method or constructor containing the given expression.static boolean
isInvocationOnVariable
(MethodInvocationTree mit, Symbol variable, boolean defaultReturn) Return whether we are sure that the method invocation is on a given variable.static boolean
isNullLiteral
(ExpressionTree tree) static boolean
isSecuringByte
(ExpressionTree expression) static boolean
static boolean
Checks of is the given tree is selecting withthis
orsuper
static boolean
In case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result.static boolean
isThis
(ExpressionTree expression) Checks if the given expression refers to "this"static IdentifierTree
Retrieve the identifier corresponding to the method name associated to the method invocationstatic Object
static ExpressionTree
-
Method Details
-
isSimpleAssignment
In case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result. For SE-Based checks, only a single value should be unstacked if its the case. For other cases, two values should be unstacked. See JLS8-15.26- Parameters:
tree
- The assignment tree- Returns:
- true if the tree is a simple assignment
- See Also:
-
isSelectOnThisOrSuper
- Parameters:
tree
- The tree to check.- Returns:
- true when the tree is a select on
this
orsuper
- See Also:
-
isSelectOnThisOrSuper
Checks of is the given tree is selecting withthis
orsuper
- Parameters:
tree
- The tree to check.- Returns:
- true when the tree is a select on
this
orsuper
- See Also:
-
extractIdentifier
-
extractIdentifierSymbol
-
isInvocationOnVariable
public static boolean isInvocationOnVariable(MethodInvocationTree mit, @Nullable Symbol variable, boolean defaultReturn) Return whether we are sure that the method invocation is on a given variable. If unsure (variable is null, or we can not extract an identifier from the method invocation), return a default value -
skipParentheses
-
isNullLiteral
-
isSecuringByte
-
methodName
Retrieve the identifier corresponding to the method name associated to the method invocation -
getEnclosingMethod
Return the first enclosing method or constructor containing the given expression. -
getEnclosingElement
-
getAssignedSymbol
-
isThis
Checks if the given expression refers to "this"- Parameters:
expression
- the expression to check- Returns:
- true if this expression refers to "this"
-
resolveAsConstant
-