public abstract class Linker extends Object
The idea of a linker is as follows: normally, java compiler determines the exact method/field that are referenced
in the compiled source code, and at runtime, the said method/field must exist in its exact signature.
no-more-tears relaxes this constraint. At compile time, the exact signature is computed just like before,
but at runtime, Linker
instances get to choose the actual method/field that are linked, based on the
signature information calculated at the compile time.
This is handy for example to modular systems where the version of the library used for the compilation and the version of the library used at runtime is different. In such environment, the method/field of the exact same signature might not exist, but a lax "linker" can pick up other methods/fields that superseded the original one. (Such as resolving "X Foo.getX()" to "X2 Foo.getX()" provided that X2 extends from X.)
To register a linker, add an instance to LINKERS
. This list by default contains the
default linker, which tries to link to the method/field of the exact signature.
Normally, you should insert your linkers after this default linker.
Different call back method is provided for each kind of operation that the no-more-tears can defer the linking. The meaning of the parameters is as follows:
MethodHandles.Lookup.lookupClass()
in particular.
Member.getName()
Modifier and Type | Field and Description |
---|---|
static List<Linker> |
LINKERS
Registered linkers that get consulted.
|
Constructor and Description |
---|
Linker() |
Modifier and Type | Method and Description |
---|---|
abstract CallSite |
getField(MethodHandles.Lookup caller,
String fieldName,
Class<?> fieldType,
Class<?> owner) |
abstract CallSite |
getStatic(MethodHandles.Lookup caller,
String fieldName,
Class<?> fieldType,
Class<?> owner) |
abstract CallSite |
invokeConstructor(MethodHandles.Lookup caller,
MethodType signature,
Class<?> owner) |
abstract CallSite |
invokeInterface(MethodHandles.Lookup caller,
String methodName,
MethodType signature,
Class<?> owner) |
abstract CallSite |
invokeSpecial(MethodHandles.Lookup caller,
String methodName,
MethodType signature,
Class<?> owner) |
abstract CallSite |
invokeStatic(MethodHandles.Lookup caller,
String methodName,
MethodType signature,
Class<?> owner) |
abstract CallSite |
invokeVirtual(MethodHandles.Lookup caller,
String methodName,
MethodType signature,
Class<?> owner) |
abstract CallSite |
putField(MethodHandles.Lookup caller,
String fieldName,
Class<?> fieldType,
Class<?> owner) |
abstract CallSite |
putStatic(MethodHandles.Lookup caller,
String fieldName,
Class<?> fieldType,
Class<?> owner) |
void |
register() |
void |
unregister() |
public abstract CallSite invokeVirtual(MethodHandles.Lookup caller, String methodName, MethodType signature, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite invokeStatic(MethodHandles.Lookup caller, String methodName, MethodType signature, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite invokeInterface(MethodHandles.Lookup caller, String methodName, MethodType signature, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite invokeSpecial(MethodHandles.Lookup caller, String methodName, MethodType signature, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite invokeConstructor(MethodHandles.Lookup caller, MethodType signature, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite getField(MethodHandles.Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite putField(MethodHandles.Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite getStatic(MethodHandles.Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public abstract CallSite putStatic(MethodHandles.Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException
ReflectiveOperationException
public void register()
public void unregister()
Copyright © 2013. All rights reserved.