KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > io > ProgramClassWriter


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.io;
22
23 import proguard.classfile.*;
24 import proguard.classfile.attribute.*;
25 import proguard.classfile.attribute.annotation.*;
26 import proguard.classfile.attribute.annotation.visitor.*;
27 import proguard.classfile.attribute.preverification.*;
28 import proguard.classfile.attribute.preverification.visitor.*;
29 import proguard.classfile.attribute.visitor.*;
30 import proguard.classfile.constant.*;
31 import proguard.classfile.constant.visitor.ConstantVisitor;
32 import proguard.classfile.util.*;
33 import proguard.classfile.visitor.*;
34
35 import java.io.*;
36
37 /**
38  * This ClassVisitor writes out the ProgramClass objects that it visits to the
39  * given DataOutput object.
40  *
41  * @author Eric Lafortune
42  */

43 public class ProgramClassWriter
44 extends SimplifiedVisitor
45 implements ClassVisitor,
46              MemberVisitor,
47              ConstantVisitor,
48              AttributeVisitor
49 {
50     private RuntimeDataOutput dataOutput;
51
52     private ConstantBodyWriter constantBodyWriter = new ConstantBodyWriter();
53     private AttributeBodyWriter attributeBodyWriter = new AttributeBodyWriter();
54     private StackMapFrameBodyWriter stackMapFrameBodyWriter = new StackMapFrameBodyWriter();
55     private VerificationTypeBodyWriter verificationTypeBodyWriter = new VerificationTypeBodyWriter();
56     private ElementValueBodyWriter elementValueBodyWriter = new ElementValueBodyWriter();
57
58
59     /**
60      * Creates a new ProgramClassWriter for reading from the given DataOutput.
61      */

62     public ProgramClassWriter(DataOutput dataOutput)
63     {
64         this.dataOutput = new RuntimeDataOutput(dataOutput);
65     }
66
67
68     // Implementations for ClassVisitor.
69

70     public void visitProgramClass(ProgramClass programClass)
71     {
72         // Write the magic number.
73
dataOutput.writeInt(programClass.u4magic);
74
75         // Write the version numbers.
76
dataOutput.writeShort(ClassUtil.internalMinorClassVersion(programClass.u4version));
77         dataOutput.writeShort(ClassUtil.internalMajorClassVersion(programClass.u4version));
78
79         // Write the constant pool.
80
dataOutput.writeShort(programClass.u2constantPoolCount);
81
82         programClass.constantPoolEntriesAccept(this);
83
84         // Write the general class information.
85
dataOutput.writeShort(programClass.u2accessFlags);
86         dataOutput.writeShort(programClass.u2thisClass);
87         dataOutput.writeShort(programClass.u2superClass);
88
89         // Write the interfaces.
90
dataOutput.writeShort(programClass.u2interfacesCount);
91
92         for (int index = 0; index < programClass.u2interfacesCount; index++)
93         {
94             dataOutput.writeShort(programClass.u2interfaces[index]);
95         }
96
97         // Write the fields.
98
dataOutput.writeShort(programClass.u2fieldsCount);
99
100         programClass.fieldsAccept(this);
101
102         // Write the methods.
103
dataOutput.writeShort(programClass.u2methodsCount);
104
105         programClass.methodsAccept(this);
106
107         // Write the class attributes.
108
dataOutput.writeShort(programClass.u2attributesCount);
109
110         programClass.attributesAccept(this);
111     }
112
113
114     public void visitLibraryClass(LibraryClass libraryClass)
115     {
116     }
117
118
119     // Implementations for MemberVisitor.
120

121     public void visitProgramField(ProgramClass programClass, ProgramField programField)
122     {
123         // Write the general field information.
124
dataOutput.writeShort(programField.u2accessFlags);
125         dataOutput.writeShort(programField.u2nameIndex);
126         dataOutput.writeShort(programField.u2descriptorIndex);
127
128         // Write the field attributes.
129
dataOutput.writeShort(programField.u2attributesCount);
130
131         programField.attributesAccept(programClass, this);
132     }
133
134
135     public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
136     {
137         // Write the general method information.
138
dataOutput.writeShort(programMethod.u2accessFlags);
139         dataOutput.writeShort(programMethod.u2nameIndex);
140         dataOutput.writeShort(programMethod.u2descriptorIndex);
141
142         // Write the method attributes.
143
dataOutput.writeShort(programMethod.u2attributesCount);
144
145         programMethod.attributesAccept(programClass, this);
146     }
147
148
149     public void visitLibraryMember(LibraryClass libraryClass, LibraryMember libraryMember)
150     {
151     }
152
153
154     // Implementations for ConstantVisitor.
155

156     public void visitAnyConstant(Clazz clazz, Constant constant)
157     {
158         // Write the tag.
159
dataOutput.writeByte(constant.getTag());
160
161         // Write the actual body.
162
constant.accept(clazz, constantBodyWriter);
163     }
164
165
166     private class ConstantBodyWriter
167     extends SimplifiedVisitor
168     implements ConstantVisitor
169     {
170         // Implementations for ConstantVisitor.
171

172         public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
173         {
174             dataOutput.writeInt(integerConstant.u4value);
175         }
176
177
178         public void visitLongConstant(Clazz clazz, LongConstant longConstant)
179         {
180             dataOutput.writeLong(longConstant.u8value);
181         }
182
183
184         public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
185         {
186             dataOutput.writeFloat(floatConstant.f4value);
187         }
188
189
190         public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
191         {
192             dataOutput.writeDouble(doubleConstant.f8value);
193         }
194
195
196         public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
197         {
198             dataOutput.writeShort(stringConstant.u2stringIndex);
199         }
200
201
202         public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
203         {
204             byte[] bytes = utf8Constant.getBytes();
205
206             dataOutput.writeShort(bytes.length);
207             dataOutput.write(bytes);
208         }
209
210
211         public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
212         {
213             dataOutput.writeShort(refConstant.u2classIndex);
214             dataOutput.writeShort(refConstant.u2nameAndTypeIndex);
215         }
216
217
218         public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
219         {
220             dataOutput.writeShort(classConstant.u2nameIndex);
221         }
222
223
224         public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
225         {
226             dataOutput.writeShort(nameAndTypeConstant.u2nameIndex);
227             dataOutput.writeShort(nameAndTypeConstant.u2descriptorIndex);
228         }
229     }
230
231
232     // Implementations for AttributeVisitor.
233

234     public void visitAnyAttribute(Clazz clazz, Attribute attribute)
235     {
236         // Write the attribute name index.
237
dataOutput.writeShort(attribute.u2attributeNameIndex);
238
239         // We'll write the attribute body into an array first, so we can
240
// automatically figure out its length.
241
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
242
243         // Temporarily replace the current data output.
244
RuntimeDataOutput oldDataOutput = dataOutput;
245         dataOutput = new RuntimeDataOutput(new DataOutputStream(byteArrayOutputStream));
246
247         // Write the attribute body into the array. Note that the
248
// accept method with two dummy null arguments never throws
249
// an UnsupportedOperationException.
250
attribute.accept(clazz, null, null, attributeBodyWriter);
251
252         // Restore the original data output.
253
dataOutput = oldDataOutput;
254
255         // Write the attribute length and body.
256
byte[] info = byteArrayOutputStream.toByteArray();
257
258         dataOutput.writeInt(info.length);
259         dataOutput.write(info);
260     }
261
262
263     private class AttributeBodyWriter
264     extends SimplifiedVisitor
265     implements AttributeVisitor,
266                   InnerClassesInfoVisitor,
267                   ExceptionInfoVisitor,
268                   StackMapFrameVisitor,
269                   VerificationTypeVisitor,
270                   LineNumberInfoVisitor,
271                   LocalVariableInfoVisitor,
272                   LocalVariableTypeInfoVisitor,
273                   AnnotationVisitor,
274                   ElementValueVisitor
275     {
276         // Implementations for AttributeVisitor.
277

278         public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute)
279         {
280             // Write the unknown information.
281
byte[] info = new byte[unknownAttribute.u4attributeLength];
282             dataOutput.write(info);
283             unknownAttribute.info = info;
284         }
285
286
287         public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
288         {
289             dataOutput.writeShort(sourceFileAttribute.u2sourceFileIndex);
290         }
291
292
293         public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
294         {
295             dataOutput.writeShort(sourceDirAttribute.u2sourceDirIndex);
296         }
297
298
299         public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
300         {
301             // Write the inner classes.
302
dataOutput.writeShort(innerClassesAttribute.u2classesCount);
303
304             innerClassesAttribute.innerClassEntriesAccept(clazz, this);
305         }
306
307
308         public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
309         {
310             dataOutput.writeShort(enclosingMethodAttribute.u2classIndex);
311             dataOutput.writeShort(enclosingMethodAttribute.u2nameAndTypeIndex);
312         }
313
314
315         public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute)
316         {
317             // This attribute does not contain any additional information.
318
}
319
320
321         public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute)
322         {
323             // This attribute does not contain any additional information.
324
}
325
326
327         public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
328         {
329             dataOutput.writeShort(signatureAttribute.u2signatureIndex);
330         }
331
332
333         public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute)
334         {
335             dataOutput.writeShort(constantValueAttribute.u2constantValueIndex);
336         }
337
338
339         public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
340         {
341             // Write the exceptions.
342
dataOutput.writeShort(exceptionsAttribute.u2exceptionIndexTableLength);
343
344             for (int index = 0; index < exceptionsAttribute.u2exceptionIndexTableLength; index++)
345             {
346                 dataOutput.writeShort(exceptionsAttribute.u2exceptionIndexTable[index]);
347             }
348         }
349
350
351         public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
352         {
353             // Write the stack size and local variable frame size.
354
dataOutput.writeShort(codeAttribute.u2maxStack);
355             dataOutput.writeShort(codeAttribute.u2maxLocals);
356
357             // Write the byte code.
358
dataOutput.writeInt(codeAttribute.u4codeLength);
359
360             dataOutput.write(codeAttribute.code, 0, codeAttribute.u4codeLength);
361
362             // Write the exceptions.
363
dataOutput.writeShort(codeAttribute.u2exceptionTableLength);
364
365             codeAttribute.exceptionsAccept(clazz, method, this);
366
367             // Write the code attributes.
368
dataOutput.writeShort(codeAttribute.u2attributesCount);
369
370             codeAttribute.attributesAccept(clazz, method, ProgramClassWriter.this);
371         }
372
373
374         public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
375         {
376             // Write the stack map frames (only full frames, without tag).
377
dataOutput.writeShort(stackMapAttribute.u2stackMapFramesCount);
378
379             stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, stackMapFrameBodyWriter);
380         }
381
382
383         public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
384         {
385             // Write the stack map frames.
386
dataOutput.writeShort(stackMapTableAttribute.u2stackMapFramesCount);
387
388             stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this);
389         }
390
391
392         public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
393         {
394             // Write the line numbers.
395
dataOutput.writeShort(lineNumberTableAttribute.u2lineNumberTableLength);
396
397             lineNumberTableAttribute.lineNumbersAccept(clazz, method, codeAttribute, this);
398         }
399
400
401         public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
402         {
403             // Write the local variables.
404
dataOutput.writeShort(localVariableTableAttribute.u2localVariableTableLength);
405
406             localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
407         }
408
409
410         public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
411         {
412             // Write the local variable types.
413
dataOutput.writeShort(localVariableTypeTableAttribute.u2localVariableTypeTableLength);
414
415             localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
416         }
417
418
419         public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
420         {
421             // Write the annotations.
422
dataOutput.writeShort(annotationsAttribute.u2annotationsCount);
423
424             annotationsAttribute.annotationsAccept(clazz, this);
425         }
426
427
428         public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
429         {
430             // Write the parameter annotations.
431
dataOutput.writeByte(parameterAnnotationsAttribute.u2parametersCount);
432
433             for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++)
434             {
435                 // Write the parameter annotations of the given parameter.
436
int u2annotationsCount = parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex];
437                 Annotation[] annotations = parameterAnnotationsAttribute.parameterAnnotations[parameterIndex];
438
439                 dataOutput.writeShort(u2annotationsCount);
440
441                 for (int index = 0; index < u2annotationsCount; index++)
442                 {
443                     Annotation annotation = annotations[index];
444                     this.visitAnnotation(clazz, annotation);
445                 }
446
447             }
448         }
449
450
451         public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
452         {
453             // Write the default element value.
454
annotationDefaultAttribute.defaultValue.accept(clazz, null, this);
455         }
456
457
458         // Implementations for InnerClassesInfoVisitor.
459

460         public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
461         {
462             dataOutput.writeShort(innerClassesInfo.u2innerClassIndex);
463             dataOutput.writeShort(innerClassesInfo.u2outerClassIndex);
464             dataOutput.writeShort(innerClassesInfo.u2innerNameIndex);
465             dataOutput.writeShort(innerClassesInfo.u2innerClassAccessFlags);
466         }
467
468
469         // Implementations for ExceptionInfoVisitor.
470

471         public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
472         {
473             dataOutput.writeShort(exceptionInfo.u2startPC);
474             dataOutput.writeShort(exceptionInfo.u2endPC);
475             dataOutput.writeShort(exceptionInfo.u2handlerPC);
476             dataOutput.writeShort(exceptionInfo.u2catchType);
477         }
478
479
480         // Implementations for StackMapFrameVisitor.
481

482         public void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame)
483         {
484             // Write the stack map frame tag.
485
dataOutput.writeByte(stackMapFrame.getTag());
486
487             // Write the actual body.
488
stackMapFrame.accept(clazz, method, codeAttribute, offset, stackMapFrameBodyWriter);
489         }
490
491
492         // Implementations for LineNumberInfoVisitor.
493

494         public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo)
495         {
496             dataOutput.writeShort(lineNumberInfo.u2startPC);
497             dataOutput.writeShort(lineNumberInfo.u2lineNumber);
498         }
499
500
501         // Implementations for LocalVariableInfoVisitor.
502

503         public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
504         {
505             dataOutput.writeShort(localVariableInfo.u2startPC);
506             dataOutput.writeShort(localVariableInfo.u2length);
507             dataOutput.writeShort(localVariableInfo.u2nameIndex);
508             dataOutput.writeShort(localVariableInfo.u2descriptorIndex);
509             dataOutput.writeShort(localVariableInfo.u2index);
510         }
511
512
513         // Implementations for LocalVariableTypeInfoVisitor.
514

515         public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
516         {
517             dataOutput.writeShort(localVariableTypeInfo.u2startPC);
518             dataOutput.writeShort(localVariableTypeInfo.u2length);
519             dataOutput.writeShort(localVariableTypeInfo.u2nameIndex);
520             dataOutput.writeShort(localVariableTypeInfo.u2signatureIndex);
521             dataOutput.writeShort(localVariableTypeInfo.u2index);
522         }
523
524
525         // Implementations for AnnotationVisitor.
526

527         public void visitAnnotation(Clazz clazz, Annotation annotation)
528         {
529             // Write the annotation type.
530
dataOutput.writeShort(annotation.u2typeIndex);
531
532             // Write the element value pairs.
533
dataOutput.writeShort(annotation.u2elementValuesCount);
534
535             annotation.elementValuesAccept(clazz, this);
536         }
537
538
539         // Implementations for ElementValueVisitor.
540

541         public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue)
542         {
543             // Write the element name index, if applicable.
544
int u2elementNameIndex = elementValue.u2elementNameIndex;
545             if (u2elementNameIndex != 0)
546             {
547                 dataOutput.writeShort(u2elementNameIndex);
548             }
549
550             // Write the tag.
551
dataOutput.writeByte(elementValue.getTag());
552
553             // Write the actual body.
554
elementValue.accept(clazz, annotation, elementValueBodyWriter);
555         }
556     }
557
558
559     private class StackMapFrameBodyWriter
560     extends SimplifiedVisitor
561     implements StackMapFrameVisitor,
562                   VerificationTypeVisitor
563     {
564         public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame)
565         {
566             if (sameZeroFrame.getTag() == StackMapFrame.SAME_ZERO_FRAME_EXTENDED)
567             {
568                 dataOutput.writeShort(sameZeroFrame.u2offsetDelta);
569             }
570         }
571
572
573         public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame)
574         {
575             if (sameOneFrame.getTag() == StackMapFrame.SAME_ONE_FRAME_EXTENDED)
576             {
577                 dataOutput.writeShort(sameOneFrame.u2offsetDelta);
578             }
579
580             // Write the verification type of the stack entry.
581
sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this);
582         }
583
584
585         public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame)
586         {
587             dataOutput.writeShort(lessZeroFrame.u2offsetDelta);
588         }
589
590
591         public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame)
592         {
593             dataOutput.writeShort(moreZeroFrame.u2offsetDelta);
594
595             // Write the verification types of the additional local variables.
596
moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this);
597         }
598
599
600         public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
601         {
602             dataOutput.writeShort(fullFrame.u2offsetDelta);
603
604             // Write the verification types of the local variables.
605
dataOutput.writeShort(fullFrame.variablesCount);
606             fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this);
607
608             // Write the verification types of the stack entries.
609
dataOutput.writeShort(fullFrame.stackCount);
610             fullFrame.stackAccept(clazz, method, codeAttribute, offset, this);
611         }
612
613
614         // Implementations for VerificationTypeVisitor.
615

616         public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType)
617         {
618             // Write the verification type tag.
619
dataOutput.writeByte(verificationType.getTag());
620
621             // Write the actual body.
622
verificationType.accept(clazz, method, codeAttribute, offset, verificationTypeBodyWriter);
623         }
624     }
625
626
627     private class VerificationTypeBodyWriter
628     extends SimplifiedVisitor
629     implements VerificationTypeVisitor
630     {
631         // Implementations for VerificationTypeVisitor.
632

633         public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType)
634         {
635             // Most verification types don't contain any additional information.
636
}
637
638
639         public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType)
640         {
641             dataOutput.writeShort(objectType.u2classIndex);
642         }
643
644
645         public void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType)
646         {
647             dataOutput.writeShort(uninitializedType.u2newInstructionOffset);
648         }
649     }
650
651
652     private class ElementValueBodyWriter
653     extends SimplifiedVisitor
654     implements ElementValueVisitor
655     {
656         // Implementations for ElementValueVisitor.
657

658         public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
659         {
660             dataOutput.writeShort(constantElementValue.u2constantValueIndex);
661         }
662
663
664         public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
665         {
666             dataOutput.writeShort(enumConstantElementValue.u2typeNameIndex);
667             dataOutput.writeShort(enumConstantElementValue.u2constantNameIndex);
668         }
669
670
671         public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
672         {
673             dataOutput.writeShort(classElementValue.u2classInfoIndex);
674         }
675
676
677         public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
678         {
679             // Write the annotation.
680
attributeBodyWriter.visitAnnotation(clazz, annotationElementValue.annotationValue);
681         }
682
683
684         public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
685         {
686             // Write the element values.
687
dataOutput.writeShort(arrayElementValue.u2elementValuesCount);
688
689             arrayElementValue.elementValuesAccept(clazz, annotation, attributeBodyWriter);
690         }
691     }
692 }
693
Popular Tags