View Javadoc
1   package mockit.asm.constantPool;
2   
3   import edu.umd.cs.findbugs.annotations.NonNull;
4   
5   import mockit.asm.util.ByteVector;
6   
7   import org.checkerframework.checker.index.qual.NonNegative;
8   
9   public abstract class AttributeWriter {
10      @NonNull
11      protected final ConstantPoolGeneration cp;
12  
13      /**
14       * The index of the constant pool item that contains the name of the associated attribute.
15       */
16      @NonNegative
17      protected int attributeIndex;
18  
19      protected AttributeWriter(@NonNull ConstantPoolGeneration cp) {
20          this.cp = cp;
21      }
22  
23      protected AttributeWriter(@NonNull ConstantPoolGeneration cp, @NonNull String attributeName) {
24          this.cp = cp;
25          setAttribute(attributeName);
26      }
27  
28      protected final void setAttribute(@NonNull String attributeName) {
29          attributeIndex = cp.newUTF8(attributeName);
30      }
31  
32      @NonNegative
33      public abstract int getSize();
34  
35      public void put(@NonNull ByteVector out) {
36          put(out, 2);
37      }
38  
39      protected final void put(@NonNull ByteVector out, @NonNegative int size) {
40          out.putShort(attributeIndex).putInt(size);
41      }
42  }