Interface ASTSwitchLike

All Superinterfaces:
net.sourceforge.pmd.lang.ast.impl.GenericNode<JavaNode>, Iterable<ASTSwitchBranch>, JavaNode, net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode<JavaNode>, net.sourceforge.pmd.lang.ast.Node, net.sourceforge.pmd.reporting.Reportable, net.sourceforge.pmd.lang.ast.TextAvailableNode
All Known Implementing Classes:
ASTSwitchExpression, ASTSwitchStatement

public interface ASTSwitchLike extends JavaNode, Iterable<ASTSwitchBranch>
Common supertype for switch statements and switch expressions. Their grammar is identical, and is described below. The difference is that switch expressions need to be exhaustive.

 SwitchLike        ::= SwitchExpression
                     | SwitchStatement

                   ::= "switch" "(" Expression ")" SwitchBlock

 SwitchBlock       ::= SwitchArrowBlock | SwitchNormalBlock

 SwitchArrowBlock  ::= "{" SwitchArrowBranch* "}"
 SwitchNormalBlock ::= "{" SwitchFallthroughBranch* "}"

 
  • Field Summary

    Fields inherited from interface net.sourceforge.pmd.lang.ast.Node

    COORDS_COMPARATOR
  • Method Summary

    Modifier and Type
    Method
    Description
    default net.sourceforge.pmd.lang.ast.NodeStream<ASTSwitchBranch>
    Returns a stream of all branches of this switch.
    Gets the expression tested by this switch.
    default boolean
    Returns true if this switch has a default case.
    default boolean
    Returns true if this switch block tests an expression having an enum type.
    default boolean
    Returns true if this switch block tests an expression having a sealed type or an enum type and all the possible constants or types are covered by a switch case.
    default boolean
    Returns true if this switch block tests an expression having an enum type and all the constants of this type are covered by a switch case.
    default boolean
    Returns true if this a switch which uses fallthrough branches (old school case label: break;) and not arrow branches.
     

    Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.GenericNode

    ancestors, ancestorsOrSelf, asStream, children, descendants, descendantsOrSelf, getChild, getFirstChild, getLastChild, getNextSibling, getParent, getPreviousSibling

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface net.sourceforge.pmd.lang.java.ast.JavaNode

    getEnclosingType, getRoot, getSymbolTable, getTypeSystem

    Methods inherited from interface net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode

    getFirstToken, getLastToken, tokens

    Methods inherited from interface net.sourceforge.pmd.lang.ast.Node

    acceptVisitor, ancestors, children, compareLocation, descendants, firstChild, getAstInfo, getBeginColumn, getBeginLine, getEndColumn, getEndLine, getImage, getIndexInParent, getLanguageVersion, getNumChildren, getReportLocation, getTextDocument, getUserMap, getXPathAttributesIterator, getXPathNodeName, hasImageEqualTo, isFindBoundary

    Methods inherited from interface net.sourceforge.pmd.lang.ast.TextAvailableNode

    getOriginalText, getText, getTextRegion
  • Method Details

    • hasDefaultCase

      default boolean hasDefaultCase()
      Returns true if this switch has a default case.
    • getBranches

      default net.sourceforge.pmd.lang.ast.NodeStream<ASTSwitchBranch> getBranches()
      Returns a stream of all branches of this switch.
    • getTestedExpression

      default ASTExpression getTestedExpression()
      Gets the expression tested by this switch. This is the expression between the parentheses.
    • isExhaustiveEnumSwitch

      default boolean isExhaustiveEnumSwitch()
      Returns true if this switch block tests an expression having an enum type and all the constants of this type are covered by a switch case. Returns false if the type of the tested expression could not be resolved.
    • isEnumSwitch

      default boolean isEnumSwitch()
      Returns true if this switch block tests an expression having an enum type.
    • isExhaustive

      default boolean isExhaustive()
      Returns true if this switch block tests an expression having a sealed type or an enum type and all the possible constants or types are covered by a switch case. Returns false if the type of the tested expression could not be resolved.
      See Also:
    • iterator

      default Iterator<ASTSwitchBranch> iterator()
      Specified by:
      iterator in interface Iterable<ASTSwitchBranch>
    • isFallthroughSwitch

      default boolean isFallthroughSwitch()
      Returns true if this a switch which uses fallthrough branches (old school case label: break;) and not arrow branches. If the switch has no branches, returns false.