Class GuardedPattern


public class GuardedPattern extends Pattern
GuardedPattern pattern AST node type.
 GuardedPattern:
      Pattern when Expression
 
Since:
3.27
Restriction:
This class is not intended to be referenced by clients.
Restriction:
This class is not intended to be instantiated by clients.
  • Field Details

    • PATTERN_PROPERTY

      public static final ChildPropertyDescriptor PATTERN_PROPERTY
      The "pattern" structural property of this node type (child type: Pattern). (added in JEP 406).
    • EXPRESSION_PROPERTY

      public static final ChildPropertyDescriptor EXPRESSION_PROPERTY
      The "expression" structural property of this node type (child type: Expression). (added in JEP 406).
  • Method Details

    • propertyDescriptors

      public static List propertyDescriptors(int apiLevel)
      Returns a list of structural property descriptors for this node type. Clients must not modify the result.
      Parameters:
      apiLevel - the API level; one of the AST.JLS* constants
      Returns:
      a list of property descriptors (element type: StructuralPropertyDescriptor)
    • propertyDescriptors

      public static List propertyDescriptors(int apiLevel, boolean previewEnabled)
      Returns a list of structural property descriptors for this node type. Clients must not modify the result.
      Parameters:
      apiLevel - the API level; one of the AST.JLS* constants
      previewEnabled - the previewEnabled flag
      Returns:
      a list of property descriptors (element type: StructuralPropertyDescriptor)
      Restriction:
      This method is not intended to be referenced by clients.
    • getExpression

      public Expression getExpression()
      Returns the conditional expression of this pattern, or null if there is none (the "default:" case).
      Returns:
      the expression node, or null if there is none
    • getPattern

      public Pattern getPattern()
      Returns the pattern of this Guarded Pattern, or empty if there is none.
      Returns:
      the pattern node (element type: Pattern)
      Throws:
      UnsupportedOperationException - if this operation is used other than JLS18
      UnsupportedOperationException - if this expression is used with previewEnabled flag as false
      Restriction:
      This method is not intended to be referenced by clients as it is a part of Java preview feature.
    • setExpression

      public void setExpression(Expression expression)
      Sets the conditional expression of this pattern, or clears it (turns it into the "default:" case).
      Parameters:
      expression - the expression node, or null to turn it into the "default:" case
      Throws:
      IllegalArgumentException - if:
      • the node belongs to a different AST
      • the node already has a parent
      • a cycle in would be created
    • setPattern

      public void setPattern(Pattern pattern)
      Sets the pattern of this switch case.
      Throws:
      UnsupportedOperationException - if this operation is used not for JLS18
      UnsupportedOperationException - if this operation is used without previewEnabled
      Restriction:
      This method is not intended to be referenced by clients.
    • setRestrictedIdentifierStartPosition

      protected void setRestrictedIdentifierStartPosition(int restrictedIdentifierStartPosition)
      A character index into the original restricted identifier source string, or -1 if no restricted identifier source position information is available for this node; -1 by default.
      Restriction:
      since 3.30
    • getRestrictedIdentifierStartPosition

      public int getRestrictedIdentifierStartPosition()
      A character index into the original restricted identifier source string, or -1 if no restricted identifier source position information is available for this node; -1 by default.
      Since:
      3.30
      Restriction: