Class SwitchCase


  • public final class SwitchCase
    extends Object
    A case clause of a switch statement, keyed by integer labels or expression labels.
    • Constructor Detail

      • SwitchCase

        public SwitchCase​(List<Integer> labels,
                          boolean isDefault,
                          List<Statement> statements)
        Creates a case with integer labels; the statement list stays mutable for AST transforms.
        Parameters:
        labels - integer case labels, or null for none
        isDefault - whether this is the default case
        statements - the case body, or null for empty
      • SwitchCase

        public SwitchCase​(List<Integer> labels,
                          List<Expression> expressionLabels,
                          boolean isDefault,
                          List<Statement> statements)
        Creates a case with integer and expression labels.
        Parameters:
        labels - integer case labels, or null for none
        expressionLabels - expression case labels, or null for none
        isDefault - whether this is the default case
        statements - the case body, or null for empty
    • Method Detail

      • defaultCase

        public static SwitchCase defaultCase​(List<Statement> statements)
        Creates a default case.
        Parameters:
        statements - the case body
        Returns:
        the new case
      • of

        public static SwitchCase of​(int label,
                                    List<Statement> statements)
        Creates a case with a single integer label.
        Parameters:
        label - the case label
        statements - the case body
        Returns:
        the new case
      • of

        public static SwitchCase of​(List<Integer> labels,
                                    List<Statement> statements)
        Creates a case with multiple integer labels sharing one body.
        Parameters:
        labels - the case labels
        statements - the case body
        Returns:
        the new case
      • ofExpressions

        public static SwitchCase ofExpressions​(List<Expression> expressionLabels,
                                               List<Statement> statements)
        Creates a case keyed by expression labels, as used for enum switches.
        Parameters:
        expressionLabels - the case label expressions
        statements - the case body
        Returns:
        the new case
      • labels

        public List<Integer> labels()
        Returns:
        the integer case labels, unmodifiable
      • expressionLabels

        public List<Expression> expressionLabels()
        Returns:
        the expression case labels, unmodifiable
      • hasExpressionLabels

        public boolean hasExpressionLabels()
        Returns:
        true if this case is keyed by expression labels
      • isDefault

        public boolean isDefault()
        Returns:
        whether default
      • statements

        public List<Statement> statements()
        Returns:
        the case body statements, mutable
      • fallsThrough

        public boolean fallsThrough()
        Returns:
        true if control flows off the end of this case into the next
      • withFallsThrough

        public SwitchCase withFallsThrough​(boolean value)
        Marks whether this case falls through to the next.
        Parameters:
        value - the new fall-through flag
        Returns:
        this case
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object