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

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