Class ASTSwitchLabel

java.lang.Object
net.sourceforge.pmd.lang.ast.impl.AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel
All Implemented Interfaces:
Iterable<ASTExpression>, GenericNode<JavaNode>, JjtreeNode<JavaNode>, Node, TextAvailableNode, JavaNode, Reportable

public final class ASTSwitchLabel extends AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode> implements Iterable<ASTExpression>
Represents either a case or default label inside a switch statement or expression. Since Java 14, labels may have several expressions.

 SwitchLabel ::=  "case" Expression ("," Expression )*
                | "case" "null [ "," "default" ]
                | "case" Pattern ("," Pattern )* [ Guard ]
                | "default"

 

Note: case null and the case patterns are a Java 21 language feature

See Also:
  • Field Details

  • Method Details

    • isDefault

      public boolean isDefault()
      Returns true if this is the default label. This also returns true if this is the variant case null, default.
    • isCaseNull

      public boolean isCaseNull()
      Returns true if this is the label case null or case null, default.
      Since:
      7.20.0
    • getExprList

      public NodeStream<ASTExpression> getExprList()
      Returns the expressions of this label, or an empty list if this is the default label. This does neither contain TypePatterns nor RecordPatterns. To check for this, use isPatternLabel().
    • getGuardExpression

      public @Nullable ASTExpression getGuardExpression()
      Return the guard expression for this branch if there is one.
    • getGuard

      public @Nullable ASTGuard getGuard()
    • acceptVisitor

      protected <P, R> R acceptVisitor(JavaVisitor<? super P,? extends R> visitor, P data)
    • iterator

      public Iterator<ASTExpression> iterator()
      Specified by:
      iterator in interface Iterable<ASTExpression>
    • isPatternLabel

      public boolean isPatternLabel()
      Checks whether this label tests a ASTTypePattern or a ASTRecordPattern.
      Since:
      7.7.0
    • jjtClose

      public void jjtClose()
      Overrides:
      jjtClose in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • acceptVisitor

      public final <P, R> R acceptVisitor(AstVisitor<? super P,? extends R> visitor, P data)
      Specified by:
      acceptVisitor in interface Node
    • addChild

      protected void addChild(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child, int index)
      Overrides:
      addChild in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • insertChild

      protected void insertChild(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child, int index)
      Overrides:
      insertChild in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • removeChildAtIndex

      protected void removeChildAtIndex(int childIndex)
      Overrides:
      removeChildAtIndex in class AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setImage

      protected void setImage(String image)
      Overrides:
      setImage in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setFirstToken

      protected void setFirstToken(JavaccToken token)
      Overrides:
      setFirstToken in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setLastToken

      protected void setLastToken(JavaccToken token)
      Overrides:
      setLastToken in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • enlargeLeft

      protected void enlargeLeft(JavaccToken child)
      Overrides:
      enlargeLeft in class AbstractJjtreeNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • setChild

      protected void setChild(net.sourceforge.pmd.lang.java.ast.AbstractJavaNode child, int index)
      Overrides:
      setChild in class AbstractNode<net.sourceforge.pmd.lang.java.ast.AbstractJavaNode,JavaNode>
    • getSymbolTable

      public @NonNull JSymbolTable getSymbolTable()
      Description copied from interface: JavaNode
      Returns the symbol table for the program point represented by this node.
      Specified by:
      getSymbolTable in interface JavaNode
    • getTypeSystem

      public TypeSystem getTypeSystem()
      Description copied from interface: JavaNode
      Returns the type system with which this node was created. This is the object responsible for representing types in the compilation unit.
      Specified by:
      getTypeSystem in interface JavaNode
    • getRoot

      public final @NonNull ASTCompilationUnit getRoot()
      Specified by:
      getRoot in interface JavaNode
      Specified by:
      getRoot in interface Node
    • getXPathNodeName

      public final String getXPathNodeName()
      Specified by:
      getXPathNodeName in interface Node