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.util;
7   
8   import edu.umd.cs.findbugs.annotations.NonNull;
9   
10  import org.checkerframework.checker.index.qual.NonNegative;
11  
12  /**
13   * A reference to a method.
14   */
15  public final class MethodHandle {
16      public interface Tag {
17          int TAG_GETFIELD = 1;
18          int TAG_GETSTATIC = 2;
19          int TAG_PUTFIELD = 3;
20          int TAG_PUTSTATIC = 4;
21          int TAG_INVOKEVIRTUAL = 5;
22          int TAG_INVOKESTATIC = 6;
23          int TAG_INVOKESPECIAL = 7;
24          int TAG_NEWINVOKESPECIAL = 8;
25          int TAG_INVOKEINTERFACE = 9;
26      }
27  
28      /**
29       * The kind of method designated by this handle. Should be one of the {@link Tag Tag} constants.
30       */
31      @NonNegative
32      public final int tag;
33  
34      /**
35       * The internal name of the class that owns the method designated by this handle.
36       */
37      @NonNull
38      public final String owner;
39  
40      /**
41       * The name of the method designated by this handle.
42       */
43      @NonNull
44      public final String name;
45  
46      /**
47       * The descriptor of the method designated by this handle.
48       */
49      @NonNull
50      public final String desc;
51  
52      /**
53       * Initializes a new method handle.
54       *
55       * @param tag
56       *            the kind of method designated by this handle. Must be one of the {@link Tag} constants.
57       * @param owner
58       *            the internal name of the class that owns the method designated by this handle.
59       * @param name
60       *            the name of the method designated by this handle.
61       * @param desc
62       *            the descriptor of the method designated by this handle.
63       */
64      public MethodHandle(@NonNegative int tag, @NonNull String owner, @NonNull String name, @NonNull String desc) {
65          this.tag = tag;
66          this.owner = owner;
67          this.name = name;
68          this.desc = desc;
69      }
70  
71      @Override
72      public boolean equals(Object obj) {
73          if (obj == this) {
74              return true;
75          }
76  
77          if (!(obj instanceof MethodHandle)) {
78              return false;
79          }
80  
81          MethodHandle h = (MethodHandle) obj;
82          return tag == h.tag && owner.equals(h.owner) && name.equals(h.name) && desc.equals(h.desc);
83      }
84  
85      @Override
86      public int hashCode() {
87          return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
88      }
89  }