Class BridgeResolver

java.lang.Object
io.micronaut.sourcegen.bytecode.core.BridgeResolver

@Internal public final class BridgeResolver extends Object
Resolves generic bridges from Sourcegen model, reflection, and annotation-processing types.

Bridge resolution is part of lowering rather than an ASM concern: the same erased inherited method must be represented by every bytecode backend. The resolver intentionally ignores a supertype represented only by a name because that form does not contain enough method metadata.

Since:
2.2
  • Method Details

    • bridgesOf

      public static List<BridgeResolver.Bridge> bridgesOf(@Nullable ObjectDef objectDef, MethodDef methodDef)
      The bridges a declared method requires, as the finished methods a writer writes with BridgeResolver.Bridge.flags(): one per inherited method that the method overrides with a different erasure, named as the method, with its access, annotations and parameter names, erased as the inherited method, declaring the exceptions the inherited method does or else the erasure of the method's, and delegating to the method, casting every parameter to its type. A bridge is always concrete - a default method of an interface - delegating to the method even when it is abstract, as the Java compiler emits: dispatch reaches the implementation through it.
      Parameters:
      objectDef - The declaring definition
      methodDef - The declared method
      Returns:
      The bridges
      Since:
      2.3
    • bridgesOf

      public static List<BridgeResolver.Bridge> bridgesOf(@Nullable ObjectDef objectDef, MethodDef methodDef, EnclosingScope enclosingScope)
      The bridges a declared method requires, as bridgesOf(ObjectDef, MethodDef) finds them, in the enclosing scope of the class being written.
      Parameters:
      objectDef - The declaring definition
      methodDef - The declared method
      enclosingScope - The enclosing scope of the class being written
      Returns:
      The bridges
      Since:
      2.3
    • inheritedBridgesOf

      public static List<BridgeResolver.Bridge> inheritedBridgesOf(ObjectDef objectDef, EnclosingScope enclosingScope)
      The bridges a class declares for the methods it inherits, as the finished methods a writer writes with BridgeResolver.Bridge.flags(): an implementation inherited from a superclass satisfies an added interface through a bridge of the class, delegating to the inherited method as bridgesOf(ObjectDef, MethodDef) bridges delegate to a declared one.
      Parameters:
      objectDef - The definition
      enclosingScope - The enclosing scope of the class being written
      Returns:
      The bridges
      Since:
      2.3
    • visibilityBridgesOf

      public static List<BridgeResolver.Bridge> visibilityBridgesOf(ObjectDef objectDef, EnclosingScope enclosingScope)
      The visibility bridges of a class, as the finished methods a writer writes with BridgeResolver.Bridge.flags(): a public method a public class inherits from a superclass that is not public is declared again, as javac does, with the inherited method's modifiers and signature, invoking the superclass's method - a virtual call would dispatch back to the bridge.
      Parameters:
      objectDef - The definition
      enclosingScope - The enclosing scope of the class being written
      Returns:
      The bridges
      Since:
      2.3
    • resolve

      public static List<BridgeResolver.BridgeMethod> resolve(@Nullable ObjectDef objectDef, MethodDef methodDef)
      Resolves the bridges required by a declared method.
      Parameters:
      objectDef - The declaring definition
      methodDef - The declared method
      Returns:
      Erased inherited method shapes requiring a bridge
    • resolve

      public static List<BridgeResolver.BridgeMethod> resolve(@Nullable ObjectDef objectDef, MethodDef methodDef, EnclosingScope enclosingScope)
      Resolves the bridges required by a declared method in the enclosing scope of the class being written.
      Parameters:
      objectDef - The declaring definition
      methodDef - The declared method
      enclosingScope - The enclosing scope of the class being written
      Returns:
      Erased inherited method shapes requiring a bridge
      Since:
      2.3
    • resolveInherited

      public static List<BridgeResolver.InheritedBridge> resolveInherited(ObjectDef objectDef)
      The bridges a class needs for methods it inherits rather than declares: an implementation inherited from a superclass satisfies an interface the class adds - String get() of a superclass for a Supplier<String> - through a bridge the class declares, as javac writes it. A bridge that the superclasses already declare is not repeated.
      Parameters:
      objectDef - The class
      Returns:
      The inherited methods, each with a bridge delegating to it
      Since:
      2.3
    • resolveInherited

      public static List<BridgeResolver.InheritedBridge> resolveInherited(ObjectDef objectDef, EnclosingScope enclosingScope)
      The bridges a class needs for methods it inherits, as resolveInherited(ObjectDef) finds them, in the enclosing scope of the class being written.
      Parameters:
      objectDef - The class
      enclosingScope - The enclosing scope of the class being written
      Returns:
      The inherited methods, each with a bridge delegating to it
      Since:
      2.3
    • resolveVisibility

      public static List<BridgeResolver.VisibilityBridge> resolveVisibility(ObjectDef objectDef, EnclosingScope enclosingScope)
      The visibility bridges of a public class, as javac writes them: each public, concrete, non-final method it inherits from a superclass that is not public - public String value() of a package-private base - and overrides nowhere is declared again, public, synthetic and a bridge, delegating to the superclass's. Otherwise reflection could not invoke the method through the public class. A public superclass declares those of its own superclasses already.
      Parameters:
      objectDef - The class
      enclosingScope - The enclosing scope of the class being written
      Returns:
      The inherited methods to bridge
      Since:
      2.3