Class ExpressionUtils
java.lang.Object
org.sonar.java.model.ExpressionUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringannotationAttributeName(ExpressionTree expression) static booleanareVariablesSame(Tree tree1, Tree tree2, boolean defaultValue) static IdentifierTreestatic MethodTreeReturn the first enclosing method or constructor containing the given expression.static TreegetEnclosingTree(Tree expr, Tree.Kind... kinds) static TreegetParentOfType(Tree tree, Tree.Kind... kinds) static booleanisInvocationOnVariable(MethodInvocationTree mit, Symbol variable, boolean defaultReturn) Return whether we are sure that the method invocation is on a given variable.static booleanisNullLiteral(ExpressionTree tree) static booleanisSecuringByte(ExpressionTree expression) static booleanstatic booleanChecks of is the given tree is selecting withthisorsuperstatic booleanIn case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result.static booleanisThis(ExpressionTree expression) Checks if the given expression refers to "this"static IdentifierTreeRetrieve the identifier corresponding to the method name associated to the method invocationstatic Objectstatic ExpressionTreestatic TreeskipParenthesesUpwards(Tree tree)
-
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
thisorsuper - See Also:
-
isSelectOnThisOrSuper
Checks of is the given tree is selecting withthisorsuper- Parameters:
tree- The tree to check.- Returns:
- true when the tree is a select on
thisorsuper - 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
-
skipParenthesesUpwards
-
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. -
getEnclosingTree
-
getParentOfType
-
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
-
areVariablesSame
-
annotationAttributeName
-