Class SwitchRetrofittingTaskListener2

java.lang.Object
com.github.bsideup.jabel.SwitchRetrofittingTaskListener2
All Implemented Interfaces:
TaskListener

public class SwitchRetrofittingTaskListener2 extends Object implements TaskListener
Replaces
invalid reference
SwitchBootstraps#typeSwitch
and
invalid reference
SwitchBootstraps#enumSwitch
by a ternary chains.


Another method to adapt switches, by letting the compiler doing it's job, and adapting the condition according to the switch restart behavior.

This is not very efficient because SwitchBootstraps will generate a method that uses another switch to easily restart at the next case.
In fact, it's better to rewrite entirely the switch, because this "restart" behavior is poorly designed.
And can be better, avoiding any kind of "restart" system and dynamic method generation, just by adding a little more bytecode at compilation, as shown in SwitchRetrofittingTaskListener.

Also this implementation is very sensitive, as it needs to unwrap PoolConstant.LoadableConstants, that can be implemented a lot of ways.

  • Constructor Details

    • SwitchRetrofittingTaskListener2

      public SwitchRetrofittingTaskListener2(com.sun.tools.javac.util.Context context)
  • Method Details

    • started

      public void started(TaskEvent e)
      Specified by:
      started in interface TaskListener
    • finished

      public void finished(TaskEvent e)
      Specified by:
      finished in interface TaskListener
    • injectSwitchBootstraps

      public void injectSwitchBootstraps()
      Registers virtual symbol of missing types to make the compiler happy.
    • replaceSwitchSelector

      public com.sun.tools.javac.tree.JCTree.JCExpression replaceSwitchSelector(com.sun.tools.javac.tree.JCTree.JCExpression selector)
      Returns:
      the ternary-chain replacement if selector is a typeSwitch or enumSwitch dynamic invocation; otherwise null.
    • buildArgCondition

      public com.sun.tools.javac.tree.JCTree.JCExpression buildArgCondition(com.sun.tools.javac.tree.JCTree.JCExpression sel, Object arg, com.sun.tools.javac.code.Type enumType)