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