< prev index next >

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

Print this page
rev 55090 : secret-sfac


 668         case REF_invokeInterface:
 669         case REF_invokeVirtual:
 670         case REF_invokeSpecial:
 671             newRefKind = normalVirtual;
 672             break;
 673         }
 674         if (newRefKind == refKind)
 675             return this;
 676         result = clone().changeReferenceKind(newRefKind, refKind);
 677         assert(this.referenceKindIsConsistentWith(result.getReferenceKind()));
 678         return result;
 679     }
 680     /** Create a name for the given reflected constructor.  The resulting name will be in a resolved state. */
 681     @SuppressWarnings("LeakingThisInConstructor")
 682     public MemberName(Constructor<?> ctor) {
 683         Objects.requireNonNull(ctor);
 684         // fill in vmtarget, vmindex while we have ctor in hand:
 685         MethodHandleNatives.init(this, ctor);
 686         assert(isResolved() && this.clazz != null);
 687         this.name = CONSTRUCTOR_NAME;
 688         if (this.type == null)
 689             this.type = new Object[] { void.class, ctor.getParameterTypes() };






 690     }
 691     /** Create a name for the given reflected field.  The resulting name will be in a resolved state.
 692      */
 693     public MemberName(Field fld) {
 694         this(fld, false);
 695     }
 696     @SuppressWarnings("LeakingThisInConstructor")
 697     public MemberName(Field fld, boolean makeSetter) {
 698         Objects.requireNonNull(fld);
 699         // fill in vmtarget, vmindex while we have fld in hand:
 700         MethodHandleNatives.init(this, fld);
 701         assert(isResolved() && this.clazz != null);
 702         this.name = fld.getName();
 703         this.type = fld.getType();
 704         assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
 705         byte refKind = this.getReferenceKind();
 706         assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
 707         if (makeSetter) {
 708             changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
 709         }


 810     }
 811 
 812     // Construction from symbolic parts, for queries:
 813     /** Create a field or type name from the given components:
 814      *  Declaring class, name, type, reference kind.
 815      *  The declaring class may be supplied as null if this is to be a bare name and type.
 816      *  The resulting name will in an unresolved state.
 817      */
 818     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 819         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 820         initResolved(false);
 821     }
 822     /** Create a method or constructor name from the given components:
 823      *  Declaring class, name, type, reference kind.
 824      *  It will be a constructor if and only if the name is {@code "<init>"}.
 825      *  The declaring class may be supplied as null if this is to be a bare name and type.
 826      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 827      *  The resulting name will in an unresolved state.
 828      */
 829     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 830         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 831         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 832         initResolved(false);
 833     }
 834     /** Create a method, constructor, or field name from the given components:
 835      *  Reference kind, declaring class, name, type.
 836      */
 837     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 838         int kindFlags;
 839         if (MethodHandleNatives.refKindIsField(refKind)) {
 840             kindFlags = IS_FIELD;
 841             if (!(type instanceof Class))
 842                 throw newIllegalArgumentException("not a field type");
 843         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 844             kindFlags = IS_METHOD;
 845             if (!(type instanceof MethodType))
 846                 throw newIllegalArgumentException("not a method type");
 847         } else if (refKind == REF_newInvokeSpecial) {
 848             kindFlags = IS_CONSTRUCTOR;
 849             if (!(type instanceof MethodType) ||
 850                 !CONSTRUCTOR_NAME.equals(name))




 668         case REF_invokeInterface:
 669         case REF_invokeVirtual:
 670         case REF_invokeSpecial:
 671             newRefKind = normalVirtual;
 672             break;
 673         }
 674         if (newRefKind == refKind)
 675             return this;
 676         result = clone().changeReferenceKind(newRefKind, refKind);
 677         assert(this.referenceKindIsConsistentWith(result.getReferenceKind()));
 678         return result;
 679     }
 680     /** Create a name for the given reflected constructor.  The resulting name will be in a resolved state. */
 681     @SuppressWarnings("LeakingThisInConstructor")
 682     public MemberName(Constructor<?> ctor) {
 683         Objects.requireNonNull(ctor);
 684         // fill in vmtarget, vmindex while we have ctor in hand:
 685         MethodHandleNatives.init(this, ctor);
 686         assert(isResolved() && this.clazz != null);
 687         this.name = CONSTRUCTOR_NAME;
 688         if (this.type == null) {
 689             Class<?> rtype = void.class;
 690             if (isStatic()) {  // a static init factory, not a true constructor
 691                 rtype = getDeclaringClass();
 692                 // FIXME: If it's a hidden class, this sig won't work.
 693             }
 694             this.type = new Object[] { rtype, ctor.getParameterTypes() };
 695         }
 696     }
 697     /** Create a name for the given reflected field.  The resulting name will be in a resolved state.
 698      */
 699     public MemberName(Field fld) {
 700         this(fld, false);
 701     }
 702     @SuppressWarnings("LeakingThisInConstructor")
 703     public MemberName(Field fld, boolean makeSetter) {
 704         Objects.requireNonNull(fld);
 705         // fill in vmtarget, vmindex while we have fld in hand:
 706         MethodHandleNatives.init(this, fld);
 707         assert(isResolved() && this.clazz != null);
 708         this.name = fld.getName();
 709         this.type = fld.getType();
 710         assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
 711         byte refKind = this.getReferenceKind();
 712         assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
 713         if (makeSetter) {
 714             changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
 715         }


 816     }
 817 
 818     // Construction from symbolic parts, for queries:
 819     /** Create a field or type name from the given components:
 820      *  Declaring class, name, type, reference kind.
 821      *  The declaring class may be supplied as null if this is to be a bare name and type.
 822      *  The resulting name will in an unresolved state.
 823      */
 824     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 825         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 826         initResolved(false);
 827     }
 828     /** Create a method or constructor name from the given components:
 829      *  Declaring class, name, type, reference kind.
 830      *  It will be a constructor if and only if the name is {@code "<init>"}.
 831      *  The declaring class may be supplied as null if this is to be a bare name and type.
 832      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 833      *  The resulting name will in an unresolved state.
 834      */
 835     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 836         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) && type.returnType() == void.class ? IS_CONSTRUCTOR : IS_METHOD);
 837         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 838         initResolved(false);
 839     }
 840     /** Create a method, constructor, or field name from the given components:
 841      *  Reference kind, declaring class, name, type.
 842      */
 843     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 844         int kindFlags;
 845         if (MethodHandleNatives.refKindIsField(refKind)) {
 846             kindFlags = IS_FIELD;
 847             if (!(type instanceof Class))
 848                 throw newIllegalArgumentException("not a field type");
 849         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 850             kindFlags = IS_METHOD;
 851             if (!(type instanceof MethodType))
 852                 throw newIllegalArgumentException("not a method type");
 853         } else if (refKind == REF_newInvokeSpecial) {
 854             kindFlags = IS_CONSTRUCTOR;
 855             if (!(type instanceof MethodType) ||
 856                 !CONSTRUCTOR_NAME.equals(name))


< prev index next >