< prev index next >

src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java

Print this page




  70     @Override
  71     public int getReferenceKind() {
  72         return referenceKind;
  73     }
  74 
  75     @Override
  76     public String toString() {
  77         return MethodHandleInfo.toString(getReferenceKind(), getDeclaringClass(), getName(), getMethodType());
  78     }
  79 
  80     @Override
  81     public <T extends Member> T reflectAs(Class<T> expected, Lookup lookup) {
  82         if (member.isMethodHandleInvoke() && !member.isVarargs()) {
  83             // This member is an instance of a signature-polymorphic method, which cannot be reflected
  84             // A method handle invoker can come in either of two forms:
  85             // A generic placeholder (present in the source code, and varargs)
  86             // and a signature-polymorphic instance (synthetic and not varargs).
  87             // For more information see comments on {@link MethodHandleNatives#linkMethod}.
  88             throw new IllegalArgumentException("cannot reflect signature polymorphic method");
  89         }
  90         Member mem = AccessController.doPrivileged(new PrivilegedAction<Member>() {
  91                 public Member run() {
  92                     try {
  93                         return reflectUnchecked();
  94                     } catch (ReflectiveOperationException ex) {
  95                         throw new IllegalArgumentException(ex);
  96                     }
  97                 }
  98             });
  99         try {
 100             Class<?> defc = getDeclaringClass();
 101             byte refKind = (byte) getReferenceKind();
 102             lookup.checkAccess(refKind, defc, convertToMemberName(refKind, mem));
 103         } catch (IllegalAccessException ex) {
 104             throw new IllegalArgumentException(ex);
 105         }
 106         return expected.cast(mem);
 107     }
 108 
 109     private Member reflectUnchecked() throws ReflectiveOperationException {
 110         byte refKind = (byte) getReferenceKind();




  70     @Override
  71     public int getReferenceKind() {
  72         return referenceKind;
  73     }
  74 
  75     @Override
  76     public String toString() {
  77         return MethodHandleInfo.toString(getReferenceKind(), getDeclaringClass(), getName(), getMethodType());
  78     }
  79 
  80     @Override
  81     public <T extends Member> T reflectAs(Class<T> expected, Lookup lookup) {
  82         if (member.isMethodHandleInvoke() && !member.isVarargs()) {
  83             // This member is an instance of a signature-polymorphic method, which cannot be reflected
  84             // A method handle invoker can come in either of two forms:
  85             // A generic placeholder (present in the source code, and varargs)
  86             // and a signature-polymorphic instance (synthetic and not varargs).
  87             // For more information see comments on {@link MethodHandleNatives#linkMethod}.
  88             throw new IllegalArgumentException("cannot reflect signature polymorphic method");
  89         }
  90         Member mem = AccessController.doPrivileged(new PrivilegedAction<>() {
  91                 public Member run() {
  92                     try {
  93                         return reflectUnchecked();
  94                     } catch (ReflectiveOperationException ex) {
  95                         throw new IllegalArgumentException(ex);
  96                     }
  97                 }
  98             });
  99         try {
 100             Class<?> defc = getDeclaringClass();
 101             byte refKind = (byte) getReferenceKind();
 102             lookup.checkAccess(refKind, defc, convertToMemberName(refKind, mem));
 103         } catch (IllegalAccessException ex) {
 104             throw new IllegalArgumentException(ex);
 105         }
 106         return expected.cast(mem);
 107     }
 108 
 109     private Member reflectUnchecked() throws ReflectiveOperationException {
 110         byte refKind = (byte) getReferenceKind();


< prev index next >