aboutsummaryrefslogtreecommitdiff
path: root/src/main/javassist/bytecode/annotation/TypeAnnotationsWriter.java
blob: 6f765b41e3e3107627a5e4e01a42f9dd101c2c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package javassist.bytecode.annotation;

import java.io.IOException;
import java.io.OutputStream;

import javassist.bytecode.ConstPool;

/**
 * A convenience class for constructing a
 * {@code ..TypeAnnotations_attribute}.
 * See the source code of the {@link javassist.bytecode.TypeAnnotationsAttribute} class.
 *
 * @since 3.19
 */
public class TypeAnnotationsWriter extends AnnotationsWriter {
    /**
     * Constructs with the given output stream.
     *
     * @param os    the output stream.
     * @param cp    the constant pool.
     */
    public TypeAnnotationsWriter(OutputStream os, ConstPool cp) {
        super(os, cp);
    }

    /**
     * Writes {@code num_annotations} in
     * {@code Runtime(In)VisibleTypeAnnotations_attribute}.
     * It must be followed by {@code num} instances of {@code type_annotation}.
     */
    @Override
    public void numAnnotations(int num) throws IOException {
        super.numAnnotations(num);
    }

    /**
     * Writes {@code target_type} and {@code type_parameter_target}
     * of {@code target_info} union.
     */
    public void typeParameterTarget(int targetType, int typeParameterIndex)
        throws IOException
    {
        output.write(targetType);
        output.write(typeParameterIndex);
    }

    /**
     * Writes {@code target_type} and {@code supertype_target}
     * of {@code target_info} union.
     */
    public void supertypeTarget(int supertypeIndex)
        throws IOException
    {
        output.write(0x10);
        write16bit(supertypeIndex);
    }    

    /**
     * Writes {@code target_type} and {@code type_parameter_bound_target}
     * of {@code target_info} union.
     */
    public void typeParameterBoundTarget(int targetType, int typeParameterIndex, int boundIndex)
        throws IOException
    {
        output.write(targetType);
        output.write(typeParameterIndex);
        output.write(boundIndex);
    }

    /**
     * Writes {@code target_type} and {@code empty_target}
     * of {@code target_info} union.
     */
    public void emptyTarget(int targetType) throws IOException {
        output.write(targetType);
    }

    /**
     * Writes {@code target_type} and {@code type_parameter_target}
     * of {@code target_info} union.
     */
    public void formalParameterTarget(int formalParameterIndex)
        throws IOException
    {
        output.write(0x16);
        output.write(formalParameterIndex);
    }

    /**
     * Writes {@code target_type} and {@code throws_target}
     * of {@code target_info} union.
     */
    public void throwsTarget(int throwsTypeIndex)
        throws IOException
    {
        output.write(0x17);
        write16bit(throwsTypeIndex);
    } 

    /**
     * Writes {@code target_type} and {@code localvar_target}
     * of {@code target_info} union.
     * It must be followed by {@code tableLength} calls
     * to {@code localVarTargetTable}.
     */
    public void localVarTarget(int targetType, int tableLength)
        throws IOException
    {
        output.write(targetType);
        write16bit(tableLength);
    }

    /**
     * Writes an element of {@code table[]} of {@code localvar_target}
     * of {@code target_info} union.
     */
    public void localVarTargetTable(int startPc, int length, int index)
        throws IOException
    {
        write16bit(startPc);
        write16bit(length);
        write16bit(index);
    }

    /**
     * Writes {@code target_type} and {@code catch_target}
     * of {@code target_info} union.
     */
    public void catchTarget(int exceptionTableIndex)
        throws IOException
    {
        output.write(0x42);
        write16bit(exceptionTableIndex);
    } 

    /**
     * Writes {@code target_type} and {@code offset_target}
     * of {@code target_info} union.
     */
    public void offsetTarget(int targetType, int offset)
        throws IOException
    {
        output.write(targetType);
        write16bit(offset);
    }

    /**
     * Writes {@code target_type} and {@code type_argument_target}
     * of {@code target_info} union.
     */
    public void typeArgumentTarget(int targetType, int offset, int type_argument_index)
        throws IOException
    {
        output.write(targetType);
        write16bit(offset);
        output.write(type_argument_index);
    }

    /**
     * Writes {@code path_length} of {@code type_path}.
     */
    public void typePath(int pathLength) throws IOException {
        output.write(pathLength);
    }

    /**
     * Writes an element of {@code path[]} of {@code type_path}. 
     */
    public void typePathPath(int typePathKind, int typeArgumentIndex)
        throws IOException
    {
        output.write(typePathKind);
        output.write(typeArgumentIndex);
    }
}