Class ArraySourceType

  • All Implemented Interfaces:
    ASTNode, SourceType

    public final class ArraySourceType
    extends Object
    implements SourceType
    Represents an array type in the source AST.
    • Constructor Detail

      • ArraySourceType

        public ArraySourceType​(SourceType componentType)
        Creates a one-dimensional array type.
        Parameters:
        componentType - the component type
        Throws:
        NullPointerException - if the component type is null
      • ArraySourceType

        public ArraySourceType​(SourceType componentType,
                               int dimensions)
        Creates an array type with an explicit dimension count.
        Parameters:
        componentType - the component type
        dimensions - the number of dimensions, at least 1
        Throws:
        NullPointerException - if the component type is null
        IllegalArgumentException - if the dimension count is below 1
    • Method Detail

      • getComponentType

        public SourceType getComponentType()
        Returns:
        the component type
      • getDimensions

        public int getDimensions()
        Returns:
        the dimensions
      • getElementType

        public SourceType getElementType()
        Descends through nested array component types to the non-array base.
        Returns:
        the element type, so int for int[][]
      • addDimension

        public ArraySourceType addDimension()
        Creates an array type over the same component with one additional dimension.
        Returns:
        the widened array type
      • toJavaSource

        public String toJavaSource()
        Description copied from interface: SourceType
        Converts this source type to Java source code representation.
        Specified by:
        toJavaSource in interface SourceType
        Returns:
        the Java source representation (e.g., "int", "String", "int[]")
      • getTotalDimensions

        public int getTotalDimensions()
        Sums this type's dimension count with those of any nested array component types.
        Returns:
        the total dimension count
      • toIRType

        public IRType toIRType()
        Description copied from interface: SourceType
        Converts this source type to the equivalent IR type.
        Specified by:
        toIRType in interface SourceType
        Returns:
        the corresponding IRType
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object