Package edu.umd.cs.findbugs
Class SwitchHandler
java.lang.Object
edu.umd.cs.findbugs.SwitchHandler
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
enterSwitch
(int opCode, int pc, int[] switchOffsets, int defaultSwitchOffset, boolean exhaustive) void
enterSwitch
(DismantleBytecode dbc, XClass enumType) int
int
boolean
boolean
isTypeSwitchCaseCheckCast
(int opCode, int pc) In type switches aCHECKCAST
is inserted by the compiler for each case.boolean
isTypeSwitchCaseLoad
(Location location) In type switches anASTORE
is inserted by the compiler for each case.void
sawInvokeDynamic
(int pc, String methodName) For type switches introduced in Java 21 we are using the invocation of a bootstrap 'typeswitch()' method to detect that the switch operates on the class of the object.int
-
Constructor Details
-
SwitchHandler
public SwitchHandler()
-
-
Method Details
-
stackSize
public int stackSize() -
enterSwitch
-
enterSwitch
public void enterSwitch(int opCode, int pc, int[] switchOffsets, int defaultSwitchOffset, boolean exhaustive) - Parameters:
opCode
- The op code of the switch, should beTABLESWITCH
orLOOKUPSWITCH
pc
- The PC of the switch instructionswitchOffsets
- The PC offsets of the switch casesdefaultSwitchOffset
- The PC of the default caseexhaustive
-true
if the switch is exhaustive
-
isOnSwitchOffset
-
getNextSwitchOffset
-
getDefaultOffset
public int getDefaultOffset() -
getCurrentSwitchStatement
-
sawInvokeDynamic
For type switches introduced in Java 21 we are using the invocation of a bootstrap 'typeswitch()' method to detect that the switch operates on the class of the object.- Parameters:
pc
-methodName
-
-
isTypeSwitchCaseCheckCast
public boolean isTypeSwitchCaseCheckCast(int opCode, int pc) In type switches aCHECKCAST
is inserted by the compiler for each case. This method checks if the instruction is one of these casts and then checks if the corresponding switch is a type switch.- Parameters:
opCode
- The operation codepc
- The program counter- Returns:
true
If this instruction is a cast for a type switch
-
isTypeSwitchCaseLoad
In type switches anASTORE
is inserted by the compiler for each case. This method checks if the instruction is one of these loads and then checks if the corresponding switch is a type switch. We're looking for: an ASTORE preceded by a CHECKCAST preceded by an instruction at the offset of a switch case- Parameters:
location
- The Location- Returns:
true
If this instruction is a load for a type switch
-