Class UnionSourceType

  • All Implemented Interfaces:
    ASTNode, SourceType

    public final class UnionSourceType
    extends Object
    implements SourceType
    Represents a union type, e.g., catch (IOException | SQLException e).
    • Constructor Detail

      • UnionSourceType

        public UnionSourceType​(List<SourceType> alternatives)
        Creates a union type from a list, copied defensively.
        Parameters:
        alternatives - the alternative types, at least 2
        Throws:
        IllegalArgumentException - if the list is null or holds fewer than 2 alternatives
      • UnionSourceType

        public UnionSourceType​(SourceType... alternatives)
        Creates a union type from a varargs list.
        Parameters:
        alternatives - the alternative types, at least 2
        Throws:
        IllegalArgumentException - if fewer than 2 alternatives are given
    • Method Detail

      • getAlternatives

        public List<SourceType> getAlternatives()
        Returns:
        the alternatives
      • getAlternativeCount

        public int getAlternativeCount()
        Returns:
        the number of alternatives, always at least 2
      • getAlternative

        public SourceType getAlternative​(int index)
        Reads one alternative by position.
        Parameters:
        index - the zero-based position
        Returns:
        the alternative type
        Throws:
        IndexOutOfBoundsException - if the index is outside the alternative list
      • getFirstAlternative

        public SourceType getFirstAlternative()
        Returns:
        the first alternative
      • 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[]")
      • 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