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)
Since:
2.4
Version:
2.5
See Also:
  • Constructor Details

    • CastExpression

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

    • accept

      public void accept(ExpressionVisitor visitor)
      Description copied from interface: Expression
      Visits this Expression by the given visitor.
      Parameters:
      visitor - The ExpressionVisitor to visit this object
    • addOrderedEncapsulatedExpressionTo

      protected void addOrderedEncapsulatedExpressionTo(List<Expression> children)
      Description copied from class: AbstractEncapsulatedExpression
      Adds the Expressions representing the encapsulated Expression.
      Overrides:
      addOrderedEncapsulatedExpressionTo in class AbstractSingleEncapsulatedExpression
      Parameters:
      children - The list used to store the string representation of the encapsulated Expression
    • getEncapsulatedExpressionQueryBNFId

      public String getEncapsulatedExpressionQueryBNFId()
      Description copied from class: AbstractSingleEncapsulatedExpression
      Returns the BNF used to parse the encapsulated expression.
      Specified by:
      getEncapsulatedExpressionQueryBNFId in class AbstractSingleEncapsulatedExpression
      Returns:
      The BNF used to parse the encapsulated expression
    • getDatabaseType

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

      public JPQLQueryBNF getQueryBNF()
      Description copied from interface: Expression
      Returns the BNF of this Expression.
      Returns:
      The JPQLQueryBNF, which represents the grammar of this Expression
    • 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
    • hasEncapsulatedExpression

      public boolean hasEncapsulatedExpression()
      Description copied from class: AbstractEncapsulatedExpression
      Determines whether something was parsed after the left parenthesis.
      Overrides:
      hasEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
      Returns:
      true if something 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, String word, Expression expression)
      Description copied from class: AbstractExpression
      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)
      Description copied from class: AbstractEncapsulatedExpression
      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
    • removeEncapsulatedExpression

      protected void removeEncapsulatedExpression()
      Description copied from class: AbstractEncapsulatedExpression
      Removes the encapsulated Expression that was parsed, it should not be part of this one. This happens when the parsed information does not have both '(' and ')'.
      Overrides:
      removeEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
    • shouldParseWithFactoryFirst

      protected boolean shouldParseWithFactoryFirst()
      Description copied from class: AbstractExpression
      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(StringBuilder writer, boolean actual)
      Description copied from class: AbstractEncapsulatedExpression
      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