jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java
changeset 26481 c5b74a88a3c0
parent 26479 a60a19ec5ce5
child 32762 253adb0f4301
equal deleted inserted replaced
26480:92d431f1ec8d 26481:c5b74a88a3c0
    52  */
    52  */
    53 /*non-public*/ abstract class BoundMethodHandle extends MethodHandle {
    53 /*non-public*/ abstract class BoundMethodHandle extends MethodHandle {
    54 
    54 
    55     /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
    55     /*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
    56         super(type, form);
    56         super(type, form);
       
    57         assert(speciesData() == speciesData(form));
    57     }
    58     }
    58 
    59 
    59     //
    60     //
    60     // BMH API and internals
    61     // BMH API and internals
    61     //
    62     //
    79         } catch (Throwable t) {
    80         } catch (Throwable t) {
    80             throw newInternalError(t);
    81             throw newInternalError(t);
    81         }
    82         }
    82     }
    83     }
    83 
    84 
       
    85     /*non-public*/
       
    86     LambdaFormEditor editor() {
       
    87         return form.editor();
       
    88     }
       
    89 
    84     static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, Object x) {
    90     static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, Object x) {
    85         return Species_L.make(type, form, x);
    91         return Species_L.make(type, form, x);
    86     }
    92     }
    87 
    93 
    88     @Override // there is a default binder in the super class, for 'L' types only
    94     @Override // there is a default binder in the super class, for 'L' types only
    89     /*non-public*/
    95     /*non-public*/
    90     BoundMethodHandle bindArgumentL(int pos, Object value) {
    96     BoundMethodHandle bindArgumentL(int pos, Object value) {
    91         MethodType type = type().dropParameterTypes(pos, pos+1);
    97         return editor().bindArgumentL(this, pos, value);
    92         LambdaForm form = internalForm().bind(1+pos, speciesData());
       
    93         return copyWithExtendL(type, form, value);
       
    94     }
    98     }
    95     /*non-public*/
    99     /*non-public*/
    96     BoundMethodHandle bindArgumentI(int pos, int value) {
   100     BoundMethodHandle bindArgumentI(int pos, int value) {
    97         MethodType type = type().dropParameterTypes(pos, pos+1);
   101         return editor().bindArgumentI(this, pos, value);
    98         LambdaForm form = internalForm().bind(1+pos, speciesData());
       
    99         return copyWithExtendI(type, form, value);
       
   100     }
   102     }
   101     /*non-public*/
   103     /*non-public*/
   102     BoundMethodHandle bindArgumentJ(int pos, long value) {
   104     BoundMethodHandle bindArgumentJ(int pos, long value) {
   103         MethodType type = type().dropParameterTypes(pos, pos+1);
   105         return editor().bindArgumentJ(this, pos, value);
   104         LambdaForm form = internalForm().bind(1+pos, speciesData());
       
   105         return copyWithExtendJ(type, form, value);
       
   106     }
   106     }
   107     /*non-public*/
   107     /*non-public*/
   108     BoundMethodHandle bindArgumentF(int pos, float value) {
   108     BoundMethodHandle bindArgumentF(int pos, float value) {
   109         MethodType type = type().dropParameterTypes(pos, pos+1);
   109         return editor().bindArgumentF(this, pos, value);
   110         LambdaForm form = internalForm().bind(1+pos, speciesData());
       
   111         return copyWithExtendF(type, form, value);
       
   112     }
   110     }
   113     /*non-public*/
   111     /*non-public*/
   114     BoundMethodHandle bindArgumentD(int pos, double value) {
   112     BoundMethodHandle bindArgumentD(int pos, double value) {
   115         MethodType type = type().dropParameterTypes(pos, pos + 1);
   113         return editor().bindArgumentD(this, pos, value);
   116         LambdaForm form = internalForm().bind(1+pos, speciesData());
       
   117         return copyWithExtendD(type, form, value);
       
   118     }
   114     }
   119 
   115 
   120     @Override
   116     @Override
   121     BoundMethodHandle rebind() {
   117     BoundMethodHandle rebind() {
   122         if (!tooComplex()) {
   118         if (!tooComplex()) {
   146     /**
   142     /**
   147      * Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a
   143      * Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a
   148      * static field containing this value, and they must accordingly implement this method.
   144      * static field containing this value, and they must accordingly implement this method.
   149      */
   145      */
   150     /*non-public*/ abstract SpeciesData speciesData();
   146     /*non-public*/ abstract SpeciesData speciesData();
       
   147 
       
   148     /*non-public*/ static SpeciesData speciesData(LambdaForm form) {
       
   149         Object c = form.names[0].constraint;
       
   150         if (c instanceof SpeciesData)
       
   151             return (SpeciesData) c;
       
   152         // if there is no BMH constraint, then use the null constraint
       
   153         return SpeciesData.EMPTY;
       
   154     }
   151 
   155 
   152     /**
   156     /**
   153      * Return the number of fields in this BMH.  Equivalent to speciesData().fieldCount().
   157      * Return the number of fields in this BMH.  Equivalent to speciesData().fieldCount().
   154      */
   158      */
   155     /*non-public*/ abstract int fieldCount();
   159     /*non-public*/ abstract int fieldCount();