8222744: add support for generating method handles from a variable symbol
Reviewed-by: mcimadamore
This commit is contained in:
parent
fee481d5a2
commit
f9bbbb6e27
@ -1559,6 +1559,10 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
|
||||
return ClassFile.CONSTANT_Fieldref;
|
||||
}
|
||||
|
||||
public MethodHandleSymbol asMethodHandle(boolean getter) {
|
||||
return new MethodHandleSymbol(this, getter);
|
||||
}
|
||||
|
||||
/** Clone this symbol with new owner.
|
||||
*/
|
||||
public VarSymbol clone(Symbol newOwner) {
|
||||
@ -2110,27 +2114,39 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
|
||||
public static class MethodHandleSymbol extends MethodSymbol implements LoadableConstant {
|
||||
|
||||
private Symbol refSym;
|
||||
private boolean getter;
|
||||
|
||||
public MethodHandleSymbol(Symbol msym) {
|
||||
this(msym, false);
|
||||
}
|
||||
|
||||
public MethodHandleSymbol(Symbol msym, boolean getter) {
|
||||
super(msym.flags_field, msym.name, msym.type, msym.owner);
|
||||
this.refSym = msym;
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind associated with this method handle.
|
||||
*/
|
||||
public int referenceKind() {
|
||||
if (refSym.isConstructor()) {
|
||||
return ClassFile.REF_newInvokeSpecial;
|
||||
if (refSym.kind == VAR) {
|
||||
return getter ?
|
||||
refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
|
||||
refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
|
||||
} else {
|
||||
if (refSym.isStatic()) {
|
||||
return ClassFile.REF_invokeStatic;
|
||||
} else if ((refSym.flags() & PRIVATE) != 0) {
|
||||
return ClassFile.REF_invokeSpecial;
|
||||
} else if (refSym.enclClass().isInterface()) {
|
||||
return ClassFile.REF_invokeInterface;
|
||||
if (refSym.isConstructor()) {
|
||||
return ClassFile.REF_newInvokeSpecial;
|
||||
} else {
|
||||
return ClassFile.REF_invokeVirtual;
|
||||
if (refSym.isStatic()) {
|
||||
return ClassFile.REF_invokeStatic;
|
||||
} else if ((refSym.flags() & PRIVATE) != 0) {
|
||||
return ClassFile.REF_invokeSpecial;
|
||||
} else if (refSym.enclClass().isInterface()) {
|
||||
return ClassFile.REF_invokeInterface;
|
||||
} else {
|
||||
return ClassFile.REF_invokeVirtual;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user