Package edu.umd.cs.findbugs
Class SwitchHandler
- java.lang.Object
-
- edu.umd.cs.findbugs.SwitchHandler
-
public class SwitchHandler extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwitchHandler.SwitchDetails
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<SwitchHandler.SwitchDetails>switchOffsetStackprivate java.util.Set<java.lang.Integer>typeSwitchPCThe set of program counters for the 'switch' instruction of each of the type switches
-
Constructor Summary
Constructors Constructor Description SwitchHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenterSwitch(int opCode, int pc, int[] switchOffsets, int defaultSwitchOffset, boolean exhaustive)voidenterSwitch(DismantleBytecode dbc, XClass enumType)private SwitchHandler.SwitchDetailsfindSwitchDetailsByPc(int... possiblePC)Finds a switch from the first PC of a caseSourceLineAnnotationgetCurrentSwitchStatement(BytecodeScanningDetector detector)intgetDefaultOffset()SwitchHandler.SwitchDetailsgetNextSwitchDetails(DismantleBytecode dbc)intgetNextSwitchOffset(DismantleBytecode dbc)booleanisOnSwitchOffset(DismantleBytecode dbc)booleanisTypeSwitchCaseCheckCast(int opCode, int pc)In type switches aCHECKCASTis inserted by the compiler for each case.booleanisTypeSwitchCaseLoad(Location location)In type switches anASTOREis inserted by the compiler for each case.(package private) intnumEnumValues(XClass c)voidsawInvokeDynamic(int pc, java.lang.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.intstackSize()
-
-
-
Field Detail
-
switchOffsetStack
private final java.util.List<SwitchHandler.SwitchDetails> switchOffsetStack
-
typeSwitchPC
private final java.util.Set<java.lang.Integer> typeSwitchPC
The set of program counters for the 'switch' instruction of each of the type switches
-
-
Method Detail
-
stackSize
public int stackSize()
-
numEnumValues
int numEnumValues(@CheckForNull XClass c)
-
enterSwitch
public void enterSwitch(DismantleBytecode dbc, @CheckForNull XClass enumType)
-
enterSwitch
public void enterSwitch(int opCode, int pc, int[] switchOffsets, int defaultSwitchOffset, boolean exhaustive)- Parameters:
opCode- The op code of the switch, should beTABLESWITCHorLOOKUPSWITCHpc- The PC of the switch instructionswitchOffsets- The PC offsets of the switch casesdefaultSwitchOffset- The PC of the default caseexhaustive-trueif the switch is exhaustive
-
isOnSwitchOffset
public boolean isOnSwitchOffset(DismantleBytecode dbc)
-
getNextSwitchOffset
public int getNextSwitchOffset(DismantleBytecode dbc)
-
getNextSwitchDetails
@CheckForNull public SwitchHandler.SwitchDetails getNextSwitchDetails(DismantleBytecode dbc)
-
getDefaultOffset
public int getDefaultOffset()
-
getCurrentSwitchStatement
public SourceLineAnnotation getCurrentSwitchStatement(BytecodeScanningDetector detector)
-
sawInvokeDynamic
public void sawInvokeDynamic(int pc, java.lang.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.- Parameters:
pc-methodName-
-
isTypeSwitchCaseCheckCast
public boolean isTypeSwitchCaseCheckCast(int opCode, int pc)In type switches aCHECKCASTis 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:
trueIf this instruction is a cast for a type switch
-
isTypeSwitchCaseLoad
public boolean isTypeSwitchCaseLoad(Location location)
In type switches anASTOREis 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:
trueIf this instruction is a load for a type switch
-
findSwitchDetailsByPc
private SwitchHandler.SwitchDetails findSwitchDetailsByPc(int... possiblePC)
Finds a switch from the first PC of a case- Parameters:
possiblePC- The possible first PC of a switch case- Returns:
- The
SwitchDetailsof the switch corresponding to the case or null if there was no case at this PC
-
-