Class SwitchRetrofittingTaskListener2
java.lang.Object
com.github.bsideup.jabel.SwitchRetrofittingTaskListener2
- All Implemented Interfaces:
TaskListener
Replaces
and
by a ternary chains.
invalid reference
SwitchBootstraps#typeSwitch
invalid reference
SwitchBootstraps#enumSwitch
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.sun.tools.javac.tree.JCTree.JCExpressionbuildArgCondition(com.sun.tools.javac.tree.JCTree.JCExpression sel, Object arg, com.sun.tools.javac.code.Type enumType) voidvoidRegisters virtual symbol of missing types to make the compiler happy.com.sun.tools.javac.tree.JCTree.JCExpressionreplaceSwitchSelector(com.sun.tools.javac.tree.JCTree.JCExpression selector) void
-
Constructor Details
-
SwitchRetrofittingTaskListener2
public SwitchRetrofittingTaskListener2(com.sun.tools.javac.util.Context context)
-
-
Method Details
-
started
- Specified by:
startedin interfaceTaskListener
-
finished
- Specified by:
finishedin interfaceTaskListener
-
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
selectoris atypeSwitchorenumSwitchdynamic invocation; otherwisenull.
-
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)
-