changeset 54668:0bda2308eded

8222744: add support for generating method handles from a variable symbol Reviewed-by: mcimadamore
author vromero
date Wed, 01 May 2019 12:41:26 -0400
parents f8d2b5ce4491
children ad45b3802d4e
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
diffstat 1 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed May 01 22:02:48 2019 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed May 01 12:41:26 2019 -0400
@@ -1559,6 +1559,10 @@
             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 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;
+                    }
                 }
             }
         }