• Home
  • Raw
  • Download

Lines Matching full:code

17 <li><a href="#classfile">Obtaining a <code>ClassFile</code> object</a>
45 <code>javassist.bytecode.ClassFileWriter</code> might provide
47 <code>javassist.bytecode.ClassFile</code> although its API
51 <h3>5.1 Obtaining a <code>ClassFile</code> object</h3>
53 <p>A <code>javassist.bytecode.ClassFile</code> object represents
54 a class file. To obtian this object, <code>getClassFile()</code>
55 in <code>CtClass</code> should be called.
58 <code>javassist.bytecode.ClassFile</code> directly from a class file.
68 This code snippet creats a <code>ClassFile</code> object from
69 <code>Point.class</code>.
72 A <code>ClassFile</code> object can be written back to a
73 class file. <code>write()</code> in <code>ClassFile</code>
75 <code>DataOutputStream</code>.
83 <code>ClassFile</code> provides <code>addField()</code> and
84 <code>addMethod()</code> for adding a field or a method (note that
86 It also provides <code>addAttribute()</code> for adding an attribute
90 Note that <code>FieldInfo</code>, <code>MethodInfo</code>, and
91 <code>AttributeInfo</code> objects include a link to a
92 <code>ConstPool</code> (constant pool table) object. The <code>ConstPool</code>
93 object must be common to the <code>ClassFile</code> object and
94 a <code>FieldInfo</code> (or <code>MethodInfo</code> etc.) object
95 that is added to that <code>ClassFile</code> object.
96 In other words, a <code>FieldInfo</code> (or <code>MethodInfo</code> etc.) object
97 must not be shared among different <code>ClassFile</code> objects.
100 To remove a field or a method from a <code>ClassFile</code> object,
101 you must first obtain a <code>java.util.List</code>
102 object containing all the fields of the class. <code>getFields()</code>
103 and <code>getMethods()</code> return the lists. A field or a method can
104 be removed by calling <code>remove()</code> on the <code>List</code> object.
106 Call <code>getAttributes()</code> in <code>FieldInfo</code> or
107 <code>MethodInfo</code> to obtain the list of attributes,
118 <code>CodeIterator</code> is useful. To otbain this object,
129 A <code>CodeIterator</code> object allows you to visit every
132 <code>CodeIterator</code>:
135 <li><code>void begin()</code><br>
137 <li><code>void move(int index)</code><br>
139 <li><code>boolean hasNext()</code><br>
141 <li><code>int next()</code><br>
145 <li><code>int byteAt(int index)</code><br>
147 <li><code>int u16bitAt(int index)</code><br>
149 <li><code>int write(byte[] code, int index)</code><br>
151 <li><code>void insert(int index, byte[] code)</code><br>
156 <p>The following code snippet displays all the instructions included
174 A <code>Bytecode</code> object represents a sequence of bytecode
176 Here is a sample code snippet:
187 This produces the code attribute representing the following sequence:
196 calling <code>get()</code> in <code>Bytecode</code>. The
197 obtained array can be inserted in another code attribute.
200 While <code>Bytecode</code> provides a number of methods for adding a
202 <code>addOpcode()</code> for adding an 8bit opcode and
203 <code>addIndex()</code> for adding an index.
204 The 8bit value of each opcode is defined in the <code>Opcode</code>
208 <code>addOpcode()</code> and other methods for adding a specific
211 This value can be obtained by calling <code>getMaxStack()</code>
212 on the <code>Bytecode</code> object.
213 It is also reflected on the <code>CodeAttribute</code> object
214 constructed from the <code>Bytecode</code> object.
216 call <code>computeMaxStack()</code> in <code>CodeAttribute</code>.
225 These attributes can be obtained from <code>ClassFile</code>,
226 <code>MethodInfo</code>, or <code>FieldInfo</code> objects.
227 Call <code>getAttribute(AnnotationsAttribute.invisibleTag)</code>
229 of <code>javassist.bytecode.AnnotationsAttribute</code> class
230 and the <code>javassist.bytecode.annotation</code> package.
234 If you want to access annotations through <code>CtClass</code>,
235 call <code>getAnnotations()</code> in <code>CtClass</code> or
236 <code>CtBehavior</code>.
244 API such as <code>CtClass</code> does not directly support
250 example, suppose that your source code declares a parameterized
251 type <code>Vector&lt;String&gt;</code>:
259 <p>The compiled bytecode is equivalent to the following code:
277 <p>and want to add an interface <code>Getter&lt;T&gt;</code> to the
278 class <code>Wrapper&lt;T&gt;</code>:
286 <p>Then the interface you really have to add is <code>Getter</code>
287 (the type parameters <code>&lt;T&gt;</code> drops off)
288 and the method you also have to add to the <code>Wrapper</code>
309 <p>The following code using Javassist will make the method shown above:
318 <p>The parameter type <code>int...</code> is changed into <code>int[]</code>
319 and <code>Modifier.VARARGS</code> is added to the method modifiers.
341 <code>javassist.bytecode.MethodInfo.doPreverify</code> is true.
345 For a given method represented by a <code>CtMethod</code> object <code>m</code>,
352 <p>Here, <code>cpool</code> is a <code>ClassPool</code> object, which is
353 available by calling <code>getClassPool()</code> on a <code>CtClass</code>
354 object. A <code>ClassPool</code> object is responsible for finding
355 class files from given class pathes. To obtain all the <code>CtMethod</code>
356 objects, call the <code>getDeclaredMethods</code> method on a <code>CtClass</code> object.