Class TypeBinder


  • public final class TypeBinder
    extends java.lang.Object
    The TypeBinder class is used to identify if an operator and operand(s) are compatible with one another.

    Using pre-defined operator combinations, the class takes an operator and operand(s) and compares them against the corresponding pre-defined set. For example, to check whether an addition operator is valid to use between an integer and double. If true, an AnnotatedOperator object is returned. If false, null is returned.

    Since:
    1.0
    • Constructor Detail

      • TypeBinder

        public TypeBinder()
    • Method Detail

      • bindUnaryOperators

        @Nullable
        public static @Nullable AnnotatedUnaryOperator bindUnaryOperators​(TokenType operatorType,
                                                                          ObjectType operandType)
        Attempts to bind an operator to an operand, returning an AnnotatedUnaryOperator object if they are compatible.

        If the operator and operand are not compatible, null is returned.

        Parameters:
        operatorType - The TokenType of the operator
        operandType - The ObjectType of the operand
        Returns:
        An AnnotatedUnaryOperator object containing the expressions type enums
      • bindBinaryOperators

        @Nullable
        public static @Nullable AnnotatedBinaryOperator bindBinaryOperators​(TokenType operatorType,
                                                                            ObjectType leftOperandType,
                                                                            ObjectType rightOperandType)
        Attempts to bind a two operands with an operator, returning an AnnotatedBinaryOperator object if they are compatible.

        If the operator and operands are not compatible, null is returned.

        Parameters:
        operatorType - The TokenType of the operator
        leftOperandType - The ObjectType of the left operand
        rightOperandType - The ObjectType of the right operand
        Returns:
        An AnnotatedBinaryOperator object containing the expressions type enums
      • bindAssignmentOperators

        @Nullable
        public static @Nullable AnnotatedAssignmentOperator bindAssignmentOperators​(TokenType operatorType,
                                                                                    ObjectType symbolType,
                                                                                    ObjectType assignmentType)
        Attempts to bind an assignment operator to a symbol and assignment, returning an AnnotatedAssignmentOperator object if they are compatible.

        If the operator, symbol, and assignment are not compatible, null is returned.

        Parameters:
        operatorType - The TokenType of the operator
        symbolType - The ObjectType of the symbol
        assignmentType - The ObjectType of the assignment
        Returns:
        An AnnotatedAssignmentOperator object containing the expressions type enums