Class Expressions

java.lang.Object
org.sonar.python.checks.utils.Expressions

public class Expressions extends Object
  • Method Details

    • isFalsy

      public static boolean isFalsy(@Nullable Expression expression)
    • isTruthy

      public static boolean isTruthy(@Nullable Expression expression)
    • singleAssignedValue

      @CheckForNull public static Expression singleAssignedValue(Name name)
    • singleAssignedValue

      @CheckForNull public static Expression singleAssignedValue(Name name, Set<Name> visited)
    • removeParentheses

      public static Expression removeParentheses(Expression expression)
    • singleAssignedNonNameValue

      public static Optional<Expression> singleAssignedNonNameValue(Name name)
    • ifNameGetSingleAssignedNonNameValue

      public static Optional<Expression> ifNameGetSingleAssignedNonNameValue(Expression expression)
    • expressionsFromListOrTuple

      public static List<Expression> expressionsFromListOrTuple(Expression expression)
    • unescape

      public static String unescape(StringLiteral stringLiteral)
      Returns:
      concatenation of all underlying StringElement text values without quotes and with escape sequences replacement.
      See Also:
    • unescape

      public static String unescape(StringElement stringElement)
      Returns:
      the string content of the given StringElement text values without quotes and with escape sequences replacement.
      See Also:
    • unescapeString

      public static String unescapeString(String value, boolean isBytesLiteral)
      Parameters:
      value - to unescape according to python string and bytes literals conventions
      isBytesLiteral - knowing if it's a string, or an array of bytes is important because python string uses 16 bits characters and support backslash u and U escape sequences 'a' == 'a' python bytes array uses 8 bits values and does not support and unescape backslash u and U escape sequences b'a' != b'a' b'a' == b'\\u0061'
      Returns:
      unescaped value
    • getAssignedName

      public static Optional<Name> getAssignedName(Expression expression)
    • getExpressionsFromRhs

      public static List<Expression> getExpressionsFromRhs(Expression rhs)
    • isGenericTypeAnnotation

      public static boolean isGenericTypeAnnotation(Expression expression)
    • containsSpreadOperator

      public static boolean containsSpreadOperator(List<Argument> arguments)