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