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

      public static Expression singleAssignedValue(Name name)
    • singleAssignedValue

      public static Expression singleAssignedValue(Name name, Set<Name> visited)
    • singleAssignedNonNameValue

      public static Expression singleAssignedNonNameValue(Name name)
    • removeParentheses

      public static Expression removeParentheses(@Nullable 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