View Javadoc
1   package mockit.asm.constantPool;
2   
3   import edu.umd.cs.findbugs.annotations.NonNull;
4   
5   import mockit.asm.types.JavaType;
6   
7   import org.checkerframework.checker.index.qual.NonNegative;
8   
9   public class TypeOrMemberItem extends Item {
10      @NonNull
11      String name;
12      @NonNull
13      String desc;
14      @NonNegative
15      private int argSize;
16  
17      TypeOrMemberItem(@NonNegative int index) {
18          super(index);
19          name = desc = "";
20      }
21  
22      TypeOrMemberItem(@NonNegative int index, @NonNull TypeOrMemberItem item) {
23          super(index, item);
24          name = item.name;
25          desc = item.desc;
26      }
27  
28      @NonNull
29      public String getName() {
30          return name;
31      }
32  
33      @NonNull
34      public String getDesc() {
35          return desc;
36      }
37  
38      /**
39       * Sets the name and type descriptor of this item, and computes its hashcode.
40       */
41      final void setValuesAndHashcode(@NonNull String name, @NonNull String desc, @NonNegative int hashCodeMultiplier) {
42          this.name = name;
43          this.desc = desc;
44          setHashCode(hashCodeMultiplier * name.hashCode() * desc.hashCode());
45      }
46  
47      @Override
48      boolean isEqualTo(@NonNull Item item) {
49          return isEqualTo((TypeOrMemberItem) item);
50      }
51  
52      final boolean isEqualTo(@NonNull TypeOrMemberItem item) {
53          return item.name.equals(name) && item.desc.equals(desc);
54      }
55  
56      /**
57       * Recovers the stack size variation from this constant pool item, computing and storing it if needed. The
58       * {@link #argSize} field stores the sizes of the arguments and of the return value corresponding to
59       * <code>desc</code>.
60       */
61      @NonNegative
62      public final int getArgSizeComputingIfNeeded(@NonNull String methodDesc) {
63          int thisArgSize = argSize;
64  
65          if (thisArgSize == 0) {
66              thisArgSize = JavaType.getArgumentsAndReturnSizes(methodDesc);
67              argSize = thisArgSize;
68          }
69  
70          return thisArgSize;
71      }
72  }