View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package mockit.asm.constantPool;
7   
8   import static mockit.asm.jvmConstants.ConstantPoolTypes.HANDLE_BASE;
9   
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  
12  import mockit.asm.util.MethodHandle;
13  
14  import org.checkerframework.checker.index.qual.NonNegative;
15  
16  public final class MethodHandleItem extends Item {
17      private MethodHandle methodHandle;
18  
19      public MethodHandleItem(@NonNegative int index) {
20          super(index);
21          type = HANDLE_BASE;
22      }
23  
24      MethodHandleItem(@NonNegative int index, @NonNull MethodHandleItem item) {
25          super(index, item);
26          methodHandle = item.methodHandle;
27      }
28  
29      /**
30       * Sets the type and hash code of this method handle item.
31       */
32      public void set(@NonNull MethodHandle methodHandle) {
33          this.methodHandle = methodHandle;
34          type = HANDLE_BASE;
35          setHashCode(methodHandle.hashCode());
36          type = HANDLE_BASE + methodHandle.tag;
37      }
38  
39      @Override
40      boolean isEqualTo(@NonNull Item item) {
41          return ((MethodHandleItem) item).methodHandle.equals(methodHandle);
42      }
43  }