Class 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 Detail

      • EnumSwitchMapRegistry

        public EnumSwitchMapRegistry()
    • Method Detail

      • registerMapping

        public void registerMapping​(String holderClass,
                                    String enumClassName,
                                    int caseValue,
                                    String enumConstant)
        Registers one caseValue -> enumConstant entry of a switch map.
        Parameters:
        holderClass - the class declaring the $SwitchMap$ field
        enumClassName - the enum being switched on
        caseValue - the dense case value javac assigned
        enumConstant - 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$ field
        enumClassName - the enum being switched on
        caseValue - 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$ field
        enumClassName - 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