Class BridgeResolver
java.lang.Object
io.micronaut.sourcegen.bytecode.core.BridgeResolver
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA finished bridge method.static final recordThe erased method shape used by a bridge.static final recordA bridge a class declares for a method it inherits.static final recordA visibility bridge: a public method a public class inherits from a superclass that is not public, which javac declares again in the class, delegating to the superclass's, so that reflection can invoke it through the class. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<BridgeResolver.Bridge> The bridges a declared method requires, as the finished methods a writer writes withBridgeResolver.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.static List<BridgeResolver.Bridge> bridgesOf(@Nullable ObjectDef objectDef, MethodDef methodDef, EnclosingScope enclosingScope) The bridges a declared method requires, asbridgesOf(ObjectDef, MethodDef)finds them, in the enclosing scope of the class being written.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 withBridgeResolver.Bridge.flags(): an implementation inherited from a superclass satisfies an added interface through a bridge of the class, delegating to the inherited method asbridgesOf(ObjectDef, MethodDef)bridges delegate to a declared one.static List<BridgeResolver.BridgeMethod> Resolves the bridges required by a declared method.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.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 aSupplier<String>- through a bridge the class declares, as javac writes it.static List<BridgeResolver.InheritedBridge> resolveInherited(ObjectDef objectDef, EnclosingScope enclosingScope) The bridges a class needs for methods it inherits, asresolveInherited(ObjectDef)finds them, in the enclosing scope of the class being written.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.static List<BridgeResolver.Bridge> visibilityBridgesOf(ObjectDef objectDef, EnclosingScope enclosingScope) Thevisibility bridgesof a class, as the finished methods a writer writes withBridgeResolver.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.
-
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 withBridgeResolver.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 definitionmethodDef- 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, asbridgesOf(ObjectDef, MethodDef)finds them, in the enclosing scope of the class being written.- Parameters:
objectDef- The declaring definitionmethodDef- The declared methodenclosingScope- 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 withBridgeResolver.Bridge.flags(): an implementation inherited from a superclass satisfies an added interface through a bridge of the class, delegating to the inherited method asbridgesOf(ObjectDef, MethodDef)bridges delegate to a declared one.- Parameters:
objectDef- The definitionenclosingScope- 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) Thevisibility bridgesof a class, as the finished methods a writer writes withBridgeResolver.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 definitionenclosingScope- 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 definitionmethodDef- 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 definitionmethodDef- The declared methodenclosingScope- The enclosing scope of the class being written- Returns:
- Erased inherited method shapes requiring a bridge
- Since:
- 2.3
-
resolveInherited
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 aSupplier<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, asresolveInherited(ObjectDef)finds them, in the enclosing scope of the class being written.- Parameters:
objectDef- The classenclosingScope- 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 classenclosingScope- The enclosing scope of the class being written- Returns:
- The inherited methods to bridge
- Since:
- 2.3
-