You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TypeAnnotationsWriter.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package javassist.bytecode.annotation;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import javassist.bytecode.ConstPool;
  5. /**
  6. * A convenience class for constructing a
  7. * {@code ..TypeAnnotations_attribute}.
  8. * See the source code of the {@link javassist.bytecode.TypeAnnotationsAttribute} class.
  9. *
  10. * @since 3.19
  11. */
  12. public class TypeAnnotationsWriter extends AnnotationsWriter {
  13. /**
  14. * Constructs with the given output stream.
  15. *
  16. * @param os the output stream.
  17. * @param cp the constant pool.
  18. */
  19. public TypeAnnotationsWriter(OutputStream os, ConstPool cp) {
  20. super(os, cp);
  21. }
  22. /**
  23. * Writes {@code num_annotations} in
  24. * {@code Runtime(In)VisibleTypeAnnotations_attribute}.
  25. * It must be followed by {@code num} instances of {@code type_annotation}.
  26. */
  27. @Override
  28. public void numAnnotations(int num) throws IOException {
  29. super.numAnnotations(num);
  30. }
  31. /**
  32. * Writes {@code target_type} and {@code type_parameter_target}
  33. * of {@code target_info} union.
  34. */
  35. public void typeParameterTarget(int targetType, int typeParameterIndex)
  36. throws IOException
  37. {
  38. output.write(targetType);
  39. output.write(typeParameterIndex);
  40. }
  41. /**
  42. * Writes {@code target_type} and {@code supertype_target}
  43. * of {@code target_info} union.
  44. */
  45. public void supertypeTarget(int supertypeIndex)
  46. throws IOException
  47. {
  48. output.write(0x10);
  49. write16bit(supertypeIndex);
  50. }
  51. /**
  52. * Writes {@code target_type} and {@code type_parameter_bound_target}
  53. * of {@code target_info} union.
  54. */
  55. public void typeParameterBoundTarget(int targetType, int typeParameterIndex, int boundIndex)
  56. throws IOException
  57. {
  58. output.write(targetType);
  59. output.write(typeParameterIndex);
  60. output.write(boundIndex);
  61. }
  62. /**
  63. * Writes {@code target_type} and {@code empty_target}
  64. * of {@code target_info} union.
  65. */
  66. public void emptyTarget(int targetType) throws IOException {
  67. output.write(targetType);
  68. }
  69. /**
  70. * Writes {@code target_type} and {@code type_parameter_target}
  71. * of {@code target_info} union.
  72. */
  73. public void formalParameterTarget(int formalParameterIndex)
  74. throws IOException
  75. {
  76. output.write(0x16);
  77. output.write(formalParameterIndex);
  78. }
  79. /**
  80. * Writes {@code target_type} and {@code throws_target}
  81. * of {@code target_info} union.
  82. */
  83. public void throwsTarget(int throwsTypeIndex)
  84. throws IOException
  85. {
  86. output.write(0x17);
  87. write16bit(throwsTypeIndex);
  88. }
  89. /**
  90. * Writes {@code target_type} and {@code localvar_target}
  91. * of {@code target_info} union.
  92. * It must be followed by {@code tableLength} calls
  93. * to {@code localVarTargetTable}.
  94. */
  95. public void localVarTarget(int targetType, int tableLength)
  96. throws IOException
  97. {
  98. output.write(targetType);
  99. write16bit(tableLength);
  100. }
  101. /**
  102. * Writes an element of {@code table[]} of {@code localvar_target}
  103. * of {@code target_info} union.
  104. */
  105. public void localVarTargetTable(int startPc, int length, int index)
  106. throws IOException
  107. {
  108. write16bit(startPc);
  109. write16bit(length);
  110. write16bit(index);
  111. }
  112. /**
  113. * Writes {@code target_type} and {@code catch_target}
  114. * of {@code target_info} union.
  115. */
  116. public void catchTarget(int exceptionTableIndex)
  117. throws IOException
  118. {
  119. output.write(0x42);
  120. write16bit(exceptionTableIndex);
  121. }
  122. /**
  123. * Writes {@code target_type} and {@code offset_target}
  124. * of {@code target_info} union.
  125. */
  126. public void offsetTarget(int targetType, int offset)
  127. throws IOException
  128. {
  129. output.write(targetType);
  130. write16bit(offset);
  131. }
  132. /**
  133. * Writes {@code target_type} and {@code type_argument_target}
  134. * of {@code target_info} union.
  135. */
  136. public void typeArgumentTarget(int targetType, int offset, int type_argument_index)
  137. throws IOException
  138. {
  139. output.write(targetType);
  140. write16bit(offset);
  141. output.write(type_argument_index);
  142. }
  143. /**
  144. * Writes {@code path_length} of {@code type_path}.
  145. */
  146. public void typePath(int pathLength) throws IOException {
  147. output.write(pathLength);
  148. }
  149. /**
  150. * Writes an element of {@code path[]} of {@code type_path}.
  151. */
  152. public void typePathPath(int typePathKind, int typeArgumentIndex)
  153. throws IOException
  154. {
  155. output.write(typePathKind);
  156. output.write(typeArgumentIndex);
  157. }
  158. }