Class CastExpression

  • All Implemented Interfaces:
    Expression

    public final class CastExpression
    extends AbstractSingleEncapsulatedExpression
    The CAST function cast value to a different type. The database type is the second parameter, and can be any valid database type including size and scale.
    BNF: expression ::= CAST(scalar_expression [AS] database_type)
    Version:
    2.5
    See Also:
    DatabaseType
    Author:
    James Sutherland
    Since:
    2.4
    • Constructor Detail

      • CastExpression

        public CastExpression​(AbstractExpression parent)
        Creates a new CastExpression.
        Parameters:
        parent - The parent of this expression
    • Method Detail

      • getDatabaseType

        public Expression getDatabaseType()
        Returns the database type to cast to.
        Returns:
        The Expression representing the database type
      • hasAs

        public boolean hasAs()
        Determines whether the identifier AS was part of the query.
        Returns:
        true if the identifier AS was parsed; false otherwise
      • hasDatabaseType

        public boolean hasDatabaseType()
        Determines whether the database type was parsed or not.
        Returns:
        true if the database type was parsed; false otherwise
      • hasScalarExpression

        public boolean hasScalarExpression()
        Determines whether something was parsed after the left parenthesis and before the AS identifier.
        Returns:
        true the expression to be cast was parsed; false otherwise
        Since:
        2.5
      • hasSpaceAfterAs

        public boolean hasSpaceAfterAs()
        Determines whether a whitespace parsed after AS.
        Returns:
        true if there was a whitespace parsed after AS; false otherwise
      • hasSpaceAfterExpression

        public boolean hasSpaceAfterExpression()
        Determines whether a whitespace was parsed after the expression.
        Returns:
        true if there was a whitespace parsed after the expression; false otherwise
      • isParsingComplete

        protected boolean isParsingComplete​(WordParser wordParser,
                                            java.lang.String word,
                                            Expression expression)
        Determines whether the parsing is complete based on what is left in the given text. The text is never empty.
        Overrides:
        isParsingComplete in class AbstractEncapsulatedExpression
        Parameters:
        wordParser - The text to parse based on the current position of the cursor
        word - The word that was retrieved from the given text, which is the first word in the text
        expression - The Expression that has already been parsed
        Returns:
        true if the text no longer can't be parsed by the current expression; false if more can be parsed
      • parseEncapsulatedExpression

        protected void parseEncapsulatedExpression​(WordParser wordParser,
                                                   int whitespaceCount,
                                                   boolean tolerant)
        Parses the encapsulated expression by starting at the current position, which is part of the given WordParser.
        Overrides:
        parseEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
        Parameters:
        wordParser - The text to parse based on the current position of the cursor
        whitespaceCount - The number of whitespace characters that were parsed after '('
        tolerant - Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
      • shouldParseWithFactoryFirst

        protected boolean shouldParseWithFactoryFirst()
        Determines whether the parsing of the query should be performed using the factories first or it should automatically fallback to the fallback factory.
        Overrides:
        shouldParseWithFactoryFirst in class AbstractExpression
        Returns:
        true is returned by default so the factories are used before falling back
      • toParsedTextEncapsulatedExpression

        protected void toParsedTextEncapsulatedExpression​(java.lang.StringBuilder writer,
                                                          boolean actual)
        Generates a string representation of the encapsulated Expression.
        Overrides:
        toParsedTextEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
        Parameters:
        writer - The buffer used to append the encapsulated Expression's string representation
        actual - Determines whether to include any characters that are considered virtual, i.e. that was parsed when the query is incomplete and is needed for functionality like content assist