Class ExpressionUtils

java.lang.Object
org.sonar.java.model.ExpressionUtils

public final class ExpressionUtils extends Object
  • Method Details

    • 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:
    • isSelectOnThisOrSuper

      public static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree)
      Checks of is the given tree is a MemberSelectExpressionTree which is selecting with this or super
      Parameters:
      tree - The tree to check.
      Returns:
      true when the tree is a select on this or super
      See Also:
    • isSelectOnThisOrSuper

      public static boolean isSelectOnThisOrSuper(MemberSelectExpressionTree tree)
      Checks of is the given tree is selecting with this or super
      Parameters:
      tree - The tree to check.
      Returns:
      true when the tree is a select on this or super
      See Also:
    • 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)
      Return the first enclosing method or constructor containing the given expression.
    • getEnclosingElement

      @CheckForNull public static MethodTree getEnclosingElement(ExpressionTree expr, Tree.Kind... kinds)
    • 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)