Class InitializedArrayCreation

  • All Implemented Interfaces:
    Operation

    public final class InitializedArrayCreation
    extends CallableOperation
    InitializedArrayCreation is an Operation representing the construction of a one-dimensional array with a given element type and length. The InitializedArrayCreation operation requires a list of elements in an initializer. For instance, new int[2] is the InitializedArrayCreation in the initialization
    int[] x = new int[2] { 3, 7 };
    with the initializer list as inputs.

    In terms of the notation used for the Operation class, a creation of an array of elements of type e with length n has a signature [ e,...,e] → t, where [e,...,e] is a list of length n, and t is the array type.

    InitializedArrayCreation objects are immutable.

    • Field Detail

      • length

        private final int length
      • elementType

        private final Type elementType
    • Constructor Detail

      • InitializedArrayCreation

        InitializedArrayCreation​(ArrayType arrayType,
                                 int length)
        Creates an object representing the construction of an array that holds values of the element type and has the given length.
        Parameters:
        length - number of objects allowed in the array
        arrayType - the type of array this operation creates
    • Method Detail

      • getLength

        public int getLength()
        Returns the length of created array.
        Returns:
        length of array created by this object
      • execute

        public ExecutionOutcome execute​(Object[] statementInput)
        Performs this operation using the array of input values. Returns the results of execution as an ResultOrException object and can output results to specified PrintStream.
        Specified by:
        execute in class CallableOperation
        Parameters:
        statementInput - array containing appropriate inputs to operation
        Returns:
        NormalExecution object containing constructed array
      • appendCode

        public void appendCode​(Type declaringType,
                               TypeTuple inputTypes,
                               Type outputType,
                               List<Variable> inputVars,
                               StringBuilder b)
        Produces a Java source code representation of this statement and appends it to the given StringBuilder.
        Specified by:
        appendCode in class CallableOperation
        Parameters:
        declaringType - the declaring type for this operation
        inputTypes - the input types for this operation
        outputType - the output type for this operation
        inputVars - the list of variables that are inputs to operation
        b - the StringBuilder to which code is added
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toParsableString

        public String toParsableString​(Type declaringType,
                                       TypeTuple inputTypes,
                                       Type outputType)
        Returns a string representation of this Operation, which can be read by static parse method for class. For a class C implementing the Operation interface, this method should return a String s such that parsing the string returns an object equivalent to this object, i.e. C.parse(this.s).equals(this).

        Creates string of the form TYPE[NUMELEMS] where TYPE is the type of the array, and NUMELEMS is the number of elements.

        Example: int[3]

        Specified by:
        toParsableString in class CallableOperation
        Parameters:
        declaringType - the declaring type for this operation
        inputTypes - the input types for this operation
        outputType - the output type for this operation
        Returns:
        string descriptor for array creation
      • getName

        public String getName()
        Description copied from interface: Operation
        Returns the name for the operation.
        Returns:
        the name for this operation