Package org.sonar.java.model
Class ExpressionUtils
- java.lang.Object
-
- org.sonar.java.model.ExpressionUtils
-
public final class ExpressionUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IdentifierTree
extractIdentifier(AssignmentExpressionTree tree)
static Optional<Symbol>
extractIdentifierSymbol(ExpressionTree tree)
static Optional<Symbol>
getAssignedSymbol(ExpressionTree exp)
static MethodTree
getEnclosingMethod(ExpressionTree expr)
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
isSelectOnThisOrSuper(AssignmentExpressionTree tree)
static boolean
isSelectOnThisOrSuper(MemberSelectExpressionTree tree)
Checks of is the given tree is selecting withthis
orsuper
static boolean
isSimpleAssignment(AssignmentExpressionTree tree)
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
methodName(MethodInvocationTree mit)
Retrieve the identifier corresponding to the method name associated to the method invocationstatic Object
resolveAsConstant(ExpressionTree tree)
static ExpressionTree
skipParentheses(ExpressionTree tree)
-
-
-
Method Detail
-
isSimpleAssignment
public static boolean isSimpleAssignment(AssignmentExpressionTree tree)
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:
extractIdentifier(AssignmentExpressionTree)
-
isSelectOnThisOrSuper
public static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree)
- Parameters:
tree
- The tree to check.- Returns:
- true when the tree is a select on
this
orsuper
- See Also:
isSelectOnThisOrSuper(MemberSelectExpressionTree)
-
isSelectOnThisOrSuper
public static boolean isSelectOnThisOrSuper(MemberSelectExpressionTree tree)
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:
isSelectOnThisOrSuper(AssignmentExpressionTree)
-
extractIdentifier
public static IdentifierTree extractIdentifier(AssignmentExpressionTree tree)
-
extractIdentifierSymbol
public static Optional<Symbol> extractIdentifierSymbol(ExpressionTree tree)
-
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
public static ExpressionTree skipParentheses(ExpressionTree tree)
-
isNullLiteral
public static boolean isNullLiteral(ExpressionTree tree)
-
isSecuringByte
public static boolean isSecuringByte(ExpressionTree expression)
-
methodName
public static IdentifierTree methodName(MethodInvocationTree mit)
Retrieve the identifier corresponding to the method name associated to the method invocation
-
getEnclosingMethod
@CheckForNull public static MethodTree getEnclosingMethod(ExpressionTree expr)
-
getAssignedSymbol
public static Optional<Symbol> getAssignedSymbol(ExpressionTree exp)
-
isThis
public static boolean isThis(ExpressionTree expression)
Checks if the given expression refers to "this"- Parameters:
expression
- the expression to check- Returns:
- true if this expression refers to "this"
-
resolveAsConstant
@CheckForNull public static Object resolveAsConstant(ExpressionTree tree)
-
-