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.classes;
7   
8   import edu.umd.cs.findbugs.annotations.NonNull;
9   
10  import mockit.asm.constantPool.AttributeWriter;
11  import mockit.asm.constantPool.ConstantPoolGeneration;
12  import mockit.asm.util.ByteVector;
13  
14  import org.checkerframework.checker.index.qual.NonNegative;
15  
16  /**
17   * Writes out into the constant pool the item index containing the name of the source file from which the class was
18   * compiled.
19   */
20  final class SourceFileWriter extends AttributeWriter {
21      @NonNegative
22      private final int sourceFileIndex;
23  
24      SourceFileWriter(@NonNull ConstantPoolGeneration cp, @NonNull String fileName) {
25          super(cp, "SourceFile");
26          sourceFileIndex = cp.newUTF8(fileName);
27      }
28  
29      @NonNegative
30      @Override
31      public int getSize() {
32          return 8;
33      }
34  
35      @Override
36      public void put(@NonNull ByteVector out) {
37          super.put(out);
38          out.putShort(sourceFileIndex);
39      }
40  }