Class ConstantExpression


  • public class ConstantExpression
    extends Expression
    Represents a parenthesis expression.
    Author:
    Holger Eichelberger
    • Field Detail

      • value

        private java.lang.Object value
    • Constructor Detail

      • ConstantExpression

        ConstantExpression()
        Constructor for serialization.
      • ConstantExpression

        public ConstantExpression​(TypeDescriptor<?> type,
                                  java.lang.Object value,
                                  TypeRegistry registry)
                           throws VilException
        Creates a new constant expression.
        Parameters:
        type - the type of this constant
        value - the assigned value of this constant
        registry - the type registry to resolve (local) types
        Throws:
        VilException - in case of type incompatibilities
    • Method Detail

      • checkAndConvert

        private boolean checkAndConvert​(TypeDescriptor<?> checkFor)
        Checks the given type for compatibility with value and converts value if necessary and possible.
        Parameters:
        checkFor - the type to check for (as one of the possible types of value)
        Returns:
        true if value can be assigned to type, false else
      • getValue

        public java.lang.Object getValue()
        Returns the value of this expression. Value complies to getType().
        Returns:
        the expression
      • getType

        public TypeDescriptor<?> getType()
        Returns the type of this expression.
        Returns:
        the type
      • inferType

        public TypeDescriptor<?> inferType()
                                    throws VilException
        Description copied from class: Expression
        Infers the type of this expression including the type of the contained sub-expressions.
        Specified by:
        inferType in class Expression
        Returns:
        the type of this expression
        Throws:
        VilException - in case that inferring the type fails
      • accept

        public java.lang.Object accept​(IExpressionVisitor visitor)
                                throws VilException
        Description copied from class: Expression
        Visits the expression.
        Specified by:
        accept in class Expression
        Parameters:
        visitor - the visitor
        Returns:
        the result of visiting this expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)