Class EnumSwitchMapRegistry
- java.lang.Object
-
- com.tonic.analysis.source.recovery.EnumSwitchMapRegistry
-
public class EnumSwitchMapRegistry extends Object
Process-wide store of recovered javac $SwitchMap$ tables, keyed by holder class and enum so two classes switching on the same enum keep separate numberings.
-
-
Constructor Summary
Constructors Constructor Description EnumSwitchMapRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Drops every registered mapping.static EnumSwitchMapRegistrygetInstance()booleanhasMapping(String holderClass, String enumClassName)StringlookupEnumConstant(String holderClass, String enumClassName, int caseValue)Resolves a switch case value back to its enum constant name.static StringparseEnumClassFromFieldName(String fieldName)Recovers the enum's internal name from a $SwitchMap$ field name, treating a segment that starts with an upper-case letter as a nested class rather than a package part.voidregisterMapping(String holderClass, String enumClassName, int caseValue, String enumConstant)Registers onecaseValue -> enumConstantentry of a switch map.
-
-
-
Method Detail
-
getInstance
public static EnumSwitchMapRegistry getInstance()
- Returns:
- the instance
-
registerMapping
public void registerMapping(String holderClass, String enumClassName, int caseValue, String enumConstant)
Registers onecaseValue -> enumConstantentry of a switch map.- Parameters:
holderClass- the class declaring the $SwitchMap$ fieldenumClassName- the enum being switched oncaseValue- the dense case value javac assignedenumConstant- the enum constant that value stands for
-
lookupEnumConstant
public String lookupEnumConstant(String holderClass, String enumClassName, int caseValue)
Resolves a switch case value back to its enum constant name.- Parameters:
holderClass- the class declaring the $SwitchMap$ fieldenumClassName- the enum being switched oncaseValue- the dense case value- Returns:
- the constant name, or null if nothing was registered for it
-
hasMapping
public boolean hasMapping(String holderClass, String enumClassName)
- Parameters:
holderClass- the class declaring the $SwitchMap$ fieldenumClassName- the enum being switched on- Returns:
- true if any entry has been registered for the pair
-
clear
public void clear()
Drops every registered mapping.
-
parseEnumClassFromFieldName
public static String parseEnumClassFromFieldName(String fieldName)
Recovers the enum's internal name from a $SwitchMap$ field name, treating a segment that starts with an upper-case letter as a nested class rather than a package part.- Parameters:
fieldName- the synthetic field name- Returns:
- the enum's internal name, or null if the name is not a $SwitchMap$ field
-
-