Class FlexibleMainRetrofittingTaskListener

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

public class FlexibleMainRetrofittingTaskListener extends Object implements TaskListener
Will adapts flexible entry points (void main();, void main(String[]);, static void main();, static void main(String[])) by attempting to create a bridge.

This is pretty limited as non-static main entry points with arguments cannot be adapted, due to a signature duplication with the static one.

Moreover, classes containing multiple entry points with ones that are private, will not work properly on older JVMs.
For example this code:

class Main {
  static void main() {}
  private static void main(String[] args) {}
}
The first main method will be selected by Java 25's JVM, because the standard one is private, whereas on an older JVM, an error will be displayed.
And Jabel cannot create a bridge for the first main, because there would be a signature duplication with the second declared main.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMainBridge(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl, boolean toLocalMain)
    Creates a main bridge in the specified class.
    void
     
    boolean
    isMain(com.sun.tools.javac.tree.JCTree.JCMethodDecl method)
     
    boolean
    isPrivate(com.sun.tools.javac.tree.JCTree.JCMethodDecl m)
     
    boolean
    isStatic(com.sun.tools.javac.tree.JCTree.JCMethodDecl m)
     
    com.sun.tools.javac.tree.JCTree.JCMethodDecl
    makeMainBridge(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl, boolean toLocalMain)
    If toLocalMain is true, a zero-arg constructor must be present.
    void
     
    void
    transformClass(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • transformClass

      public void transformClass(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl)
    • isPrivate

      public boolean isPrivate(com.sun.tools.javac.tree.JCTree.JCMethodDecl m)
    • isStatic

      public boolean isStatic(com.sun.tools.javac.tree.JCTree.JCMethodDecl m)
    • isMain

      public boolean isMain(com.sun.tools.javac.tree.JCTree.JCMethodDecl method)
    • makeMainBridge

      public com.sun.tools.javac.tree.JCTree.JCMethodDecl makeMainBridge(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl, boolean toLocalMain)
      If toLocalMain is true, a zero-arg constructor must be present.
    • addMainBridge

      public void addMainBridge(com.sun.tools.javac.tree.JCTree.JCClassDecl classDecl, boolean toLocalMain)
      Creates a main bridge in the specified class.