001    /*
002     * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.tools.javap;
027    
028    import java.util.Formatter;
029    
030    import com.sun.tools.classfile.AccessFlags;
031    import com.sun.tools.classfile.AnnotationDefault_attribute;
032    import com.sun.tools.classfile.Attribute;
033    import com.sun.tools.classfile.Attributes;
034    import com.sun.tools.classfile.CharacterRangeTable_attribute;
035    import com.sun.tools.classfile.Code_attribute;
036    import com.sun.tools.classfile.CompilationID_attribute;
037    import com.sun.tools.classfile.ConstantPool;
038    import com.sun.tools.classfile.ConstantPoolException;
039    import com.sun.tools.classfile.ConstantValue_attribute;
040    import com.sun.tools.classfile.DefaultAttribute;
041    import com.sun.tools.classfile.Deprecated_attribute;
042    import com.sun.tools.classfile.EnclosingMethod_attribute;
043    import com.sun.tools.classfile.Exceptions_attribute;
044    import com.sun.tools.classfile.Field;
045    import com.sun.tools.classfile.InnerClasses_attribute;
046    import com.sun.tools.classfile.LineNumberTable_attribute;
047    import com.sun.tools.classfile.LocalVariableTable_attribute;
048    import com.sun.tools.classfile.LocalVariableTypeTable_attribute;
049    import com.sun.tools.classfile.ModuleExportTable_attribute;
050    import com.sun.tools.classfile.ModuleMemberTable_attribute;
051    import com.sun.tools.classfile.Module_attribute;
052    import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
053    import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
054    import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
055    import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
056    import com.sun.tools.classfile.Signature_attribute;
057    import com.sun.tools.classfile.SourceDebugExtension_attribute;
058    import com.sun.tools.classfile.SourceFile_attribute;
059    import com.sun.tools.classfile.SourceID_attribute;
060    import com.sun.tools.classfile.StackMapTable_attribute;
061    import com.sun.tools.classfile.StackMap_attribute;
062    import com.sun.tools.classfile.Synthetic_attribute;
063    
064    import static com.sun.tools.classfile.AccessFlags.*;
065    
066    /*
067     *  A writer for writing Attributes as text.
068     *
069     *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
070     *  you write code that depends on this, you do so at your own risk.
071     *  This code and its internal interfaces are subject to change or
072     *  deletion without notice.</b>
073     */
074    public class AttributeWriter extends BasicWriter
075            implements Attribute.Visitor<Void,Void>
076    {
077        static AttributeWriter instance(Context context) {
078            AttributeWriter instance = context.get(AttributeWriter.class);
079            if (instance == null)
080                instance = new AttributeWriter(context);
081            return instance;
082        }
083    
084        protected AttributeWriter(Context context) {
085            super(context);
086            context.put(AttributeWriter.class, this);
087            annotationWriter = AnnotationWriter.instance(context);
088            codeWriter = CodeWriter.instance(context);
089            constantWriter = ConstantWriter.instance(context);
090            options = Options.instance(context);
091        }
092    
093        public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
094            if (attr != null) {
095                // null checks
096                owner.getClass();
097                constant_pool.getClass();
098                this.constant_pool = constant_pool;
099                this.owner = owner;
100                attr.accept(this, null);
101            }
102        }
103    
104        public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
105            if (attrs != null) {
106                // null checks
107                owner.getClass();
108                constant_pool.getClass();
109                this.constant_pool = constant_pool;
110                this.owner = owner;
111                for (Attribute attr: attrs)
112                    attr.accept(this, null);
113            }
114        }
115    
116        public Void visitDefault(DefaultAttribute attr, Void ignore) {
117            byte[] data = attr.info;
118            int i = 0;
119            int j = 0;
120            print("  ");
121            try {
122                print(attr.getName(constant_pool));
123            } catch (ConstantPoolException e) {
124                report(e);
125                print("attribute name = #" + attr.attribute_name_index);
126            }
127            print(": ");
128            println("length = 0x" + toHex(attr.info.length));
129    
130            print("   ");
131    
132            while (i < data.length) {
133                print(toHex(data[i], 2));
134    
135                j++;
136                if (j == 16) {
137                    println();
138                    print("   ");
139                    j = 0;
140                } else {
141                    print(" ");
142                }
143                i++;
144            }
145            println();
146            return null;
147        }
148    
149        public Void visitAnnotationDefault(AnnotationDefault_attribute attr, Void ignore) {
150            println("  AnnotationDefault: ");
151            print("    default_value: ");
152            annotationWriter.write(attr.default_value);
153            return null;
154        }
155    
156        public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) {
157            print("  CharacterRangeTable: ");
158            for (int i = 0; i < attr.character_range_table.length; i++) {
159                CharacterRangeTable_attribute.Entry e = attr.character_range_table[i];
160                print("    " + e.start_pc + ", " +
161                        e.end_pc + ", " +
162                        Integer.toHexString(e.character_range_start) + ", " +
163                        Integer.toHexString(e.character_range_end) + ", " +
164                        Integer.toHexString(e.flags) +
165                        "\t// ");
166                print(e.start_pc + ", " +
167                        e.end_pc + ", " +
168                        (e.character_range_start >> 10) + ":" + (e.character_range_start & 0x3ff) + ", " +
169                        (e.character_range_end >> 10) + ":" + (e.character_range_end & 0x3ff));
170                if ((e.flags & CharacterRangeTable_attribute.CRT_STATEMENT) != 0)
171                    print(", statement");
172                if ((e.flags & CharacterRangeTable_attribute.CRT_BLOCK) != 0)
173                    print(", block");
174                if ((e.flags & CharacterRangeTable_attribute.CRT_ASSIGNMENT) != 0)
175                    print(", assignment");
176                if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_CONTROLLER) != 0)
177                    print(", flow-controller");
178                if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_TARGET) != 0)
179                    print(", flow-target");
180                if ((e.flags & CharacterRangeTable_attribute.CRT_INVOKE) != 0)
181                    print(", invoke");
182                if ((e.flags & CharacterRangeTable_attribute.CRT_CREATE) != 0)
183                    print(", create");
184                if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_TRUE) != 0)
185                    print(", branch-true");
186                if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_FALSE) != 0)
187                    print(", branch-false");
188    
189    
190    
191            }
192            return null;
193        }
194    
195        public Void visitCode(Code_attribute attr, Void ignore) {
196            codeWriter.write(attr, constant_pool);
197            println();
198            return null;
199        }
200    
201        public Void visitCompilationID(CompilationID_attribute attr, Void ignore) {
202            constantWriter.write(attr.compilationID_index);
203            return null;
204        }
205    
206        public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) {
207            if (options.compat) // BUG 6622216 javap names some attributes incorrectly
208                print("  Constant value: ");
209            else
210                print("  ConstantValue: ");
211            constantWriter.write(attr.constantvalue_index);
212            if (!options.compat) // BUG 6622232 javap gets whitespace confused
213                println();
214            return null;
215        }
216    
217        public Void visitDeprecated(Deprecated_attribute attr, Void ignore) {
218            if (!(options.compat && owner instanceof Field)) // BUG 6622232 javap gets whitespace confused
219                print("  ");
220            println("Deprecated: true");
221            return null;
222        }
223    
224        public Void visitEnclosingMethod(EnclosingMethod_attribute attr, Void ignore) {
225            print("  EnclosingMethod: #" + attr.class_index + ".#" + attr.method_index
226                    + "\t// " + getJavaClassName(attr));
227            if (attr.method_index != 0)
228                print("." + getMethodName(attr));
229            println();
230            return null;
231        }
232    
233        private String getJavaClassName(EnclosingMethod_attribute a) {
234            try {
235                return getJavaName(a.getClassName(constant_pool));
236            } catch (ConstantPoolException e) {
237                return report(e);
238            }
239        }
240    
241        private String getMethodName(EnclosingMethod_attribute a) {
242            try {
243                return a.getMethodName(constant_pool);
244            } catch (ConstantPoolException e) {
245                return report(e);
246            }
247        }
248    
249        public Void visitExceptions(Exceptions_attribute attr, Void ignore) {
250            println("  Exceptions: ");
251            print("   throws ");
252            for (int i = 0; i < attr.number_of_exceptions; i++) {
253                if (i > 0)
254                    print(", ");
255                print(getJavaException(attr, i));
256            }
257            if (!options.compat) // BUG 6622232 javap gets whitespace confused
258                println();
259            return null;
260        }
261    
262        private String getJavaException(Exceptions_attribute attr, int index) {
263            try {
264                return getJavaName(attr.getException(index, constant_pool));
265            } catch (ConstantPoolException e) {
266                return report(e);
267            }
268        }
269    
270        public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) {
271            boolean first = true;
272            if (options.compat) {
273                writeInnerClassHeader();
274                first = false;
275            }
276            for (int i = 0 ; i < attr.classes.length; i++) {
277                InnerClasses_attribute.Info info = attr.classes[i];
278                //access
279                AccessFlags access_flags = info.inner_class_access_flags;
280                if (options.compat) {
281                    // BUG 6622215: javap ignores certain relevant access flags
282                    access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM);
283                    // BUG 6622232: javap gets whitespace confused
284                    print("   ");
285                }
286                if (options.checkAccess(access_flags)) {
287                    if (first) {
288                        writeInnerClassHeader();
289                        first = false;
290                    }
291                    if (!options.compat) // BUG 6622232: javap gets whitespace confused
292                        print("   ");
293                    for (String name: access_flags.getInnerClassModifiers())
294                        print(name + " ");
295                    if (info.inner_name_index!=0) {
296                        print("#" + info.inner_name_index + "= ");
297                    }
298                    print("#" + info.inner_class_info_index);
299                    if (info.outer_class_info_index != 0) {
300                        print(" of #" + info.outer_class_info_index);
301                    }
302                    print("; //");
303                    if (info.inner_name_index != 0) {
304                        print(getInnerName(constant_pool, info) + "=");
305                    }
306                    constantWriter.write(info.inner_class_info_index);
307                    if (info.outer_class_info_index != 0) {
308                        print(" of ");
309                        constantWriter.write(info.outer_class_info_index);
310                    }
311                    println();
312                }
313            }
314            return null;
315        }
316    
317        String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) {
318            try {
319                return info.getInnerName(constant_pool);
320            } catch (ConstantPoolException e) {
321                return report(e);
322            }
323        }
324    
325        private void writeInnerClassHeader() {
326            print("  ");
327            if (options.compat) // BUG 6622216: javap names some attributes incorrectly
328                print("InnerClass");
329            else
330                print("InnerClasses");
331            println(": ");
332        }
333    
334        public Void visitLineNumberTable(LineNumberTable_attribute attr, Void ignore) {
335            println("  LineNumberTable: ");
336            for (LineNumberTable_attribute.Entry entry: attr.line_number_table) {
337                println("   line " + entry.line_number + ": " + entry.start_pc);
338            }
339            return null;
340        }
341    
342        public Void visitLocalVariableTable(LocalVariableTable_attribute attr, Void ignore) {
343            println("  LocalVariableTable: ");
344            println("   Start  Length  Slot  Name   Signature");
345    
346            for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) {
347                Formatter formatter = new Formatter();
348                println(formatter.format("%8d %7d %5d %5s   %s",
349                        entry.start_pc, entry.length, entry.index,
350                        constantWriter.stringValue(entry.name_index),
351                        constantWriter.stringValue(entry.descriptor_index)));
352            }
353            return null;
354        }
355    
356        public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, Void ignore) {
357            println("  LocalVariableTypeTable: ");
358            println("   Start  Length  Slot  Name   Signature");
359    
360            for (LocalVariableTypeTable_attribute.Entry entry : attr.local_variable_table) {
361                Formatter formatter = new Formatter();
362                println(formatter.format("%8d %7d %5d %5s   %s",
363                        entry.start_pc, entry.length, entry.index,
364                        constantWriter.stringValue(entry.name_index),
365                        constantWriter.stringValue(entry.signature_index)));
366            }
367            return null;
368        }
369    
370        public Void visitModule(Module_attribute attr, Void ignore) {
371            println("  Module: #" + attr.module_name + "\t// " + getModuleName(attr));
372            return null;
373        }
374    
375        String getModuleName(Module_attribute attr) {
376            try {
377                return attr.getModuleName(constant_pool);
378            } catch (ConstantPoolException e) {
379                return report(e);
380            }
381        }
382    
383        public Void visitModuleExportTable(ModuleExportTable_attribute attr, Void ignore) {
384            println("  ModuleExportTable:");
385            println("    Types: (" + attr.export_type_table.length + ")");
386            for (int i = 0; i < attr.export_type_table.length; i++) {
387                println("      #" + attr.export_type_table[i] + "\t// " + getExportTypeName(attr, i));
388            }
389            return null;
390        }
391    
392        String getExportTypeName(ModuleExportTable_attribute attr, int index) {
393            try {
394                return attr.getExportTypeName(index, constant_pool);
395            } catch (ConstantPoolException e) {
396                return report(e);
397            }
398        }
399    
400        public Void visitModuleMemberTable(ModuleMemberTable_attribute attr, Void ignore) {
401            println("  ModuleMemberTable:");
402            println("    Packages: (" + attr.package_member_table.length + ")");
403            for (int i = 0; i < attr.package_member_table.length; i++) {
404                println("      #" + attr.package_member_table[i] + "\t// " + getPackageMemberName(attr, i));
405            }
406            return null;
407        }
408    
409        String getPackageMemberName(ModuleMemberTable_attribute attr, int index) {
410            try {
411                return attr.getPackageMemberName(index, constant_pool);
412            } catch (ConstantPoolException e) {
413                return report(e);
414            }
415        }
416    
417        public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) {
418            println("  RuntimeVisibleAnnotations: ");
419            for (int i = 0; i < attr.annotations.length; i++) {
420                print("    " + i + ": ");
421                annotationWriter.write(attr.annotations[i]);
422                println();
423            }
424            return null;
425        }
426    
427        public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, Void ignore) {
428            println("  RuntimeInvisibleAnnotations: ");
429            for (int i = 0; i < attr.annotations.length; i++) {
430                print("    " + i + ": ");
431                annotationWriter.write(attr.annotations[i]);
432                println();
433            }
434            return null;
435        }
436    
437        public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) {
438            println("  RuntimeVisibleParameterAnnotations: ");
439            for (int param = 0; param < attr.parameter_annotations.length; param++) {
440                println("    parameter " + param + ": ");
441                for (int i = 0; i < attr.parameter_annotations[param].length; i++) {
442                    print("    " + i + ": ");
443                    annotationWriter.write(attr.parameter_annotations[param][i]);
444                    println();
445                }
446            }
447            return null;
448        }
449    
450        public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) {
451            println("  RuntimeInvisibleParameterAnnotations: ");
452            for (int param = 0; param < attr.parameter_annotations.length; param++) {
453                println("    " + param + ": ");
454                for (int i = 0; i < attr.parameter_annotations[param].length; i++) {
455                    print("    " + i + ": ");
456                    annotationWriter.write(attr.parameter_annotations[param][i]);
457                    println();
458                }
459            }
460            return null;
461        }
462    
463        public Void visitSignature(Signature_attribute attr, Void ignore) {
464            println("  Signature: #" + attr.signature_index + "\t// " + getSignature(attr));
465            return null;
466        }
467    
468        String getSignature(Signature_attribute info) {
469            try {
470                return info.getSignature(constant_pool);
471            } catch (ConstantPoolException e) {
472                return report(e);
473            }
474        }
475    
476        public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) {
477            println("  SourceDebugExtension: " + attr.getValue());
478            return null;
479        }
480    
481        public Void visitSourceFile(SourceFile_attribute attr, Void ignore) {
482            println("  SourceFile: \"" + getSourceFile(attr) + "\"");
483            return null;
484        }
485    
486        private String getSourceFile(SourceFile_attribute attr) {
487            try {
488                return attr.getSourceFile(constant_pool);
489            } catch (ConstantPoolException e) {
490                return report(e);
491            }
492        }
493    
494        public Void visitSourceID(SourceID_attribute attr, Void ignore) {
495            constantWriter.write(attr.sourceID_index);
496            return null;
497        }
498    
499        public Void visitStackMap(StackMap_attribute attr, Void ignore) {
500            println("  StackMap: number_of_entries = " + attr.number_of_entries);
501    
502            StackMapTableWriter w = new StackMapTableWriter();
503            for (StackMapTable_attribute.stack_map_frame entry : attr.entries) {
504                w.write(entry);
505            }
506            println();
507            return null;
508        }
509    
510        public Void visitStackMapTable(StackMapTable_attribute attr, Void ignore) {
511            println("  StackMapTable: number_of_entries = " + attr.number_of_entries);
512    
513            StackMapTableWriter w = new StackMapTableWriter();
514            for (StackMapTable_attribute.stack_map_frame entry : attr.entries) {
515                w.write(entry);
516            }
517            println();
518            return null;
519        }
520    
521        class StackMapTableWriter // also handles CLDC StackMap attributes
522                implements StackMapTable_attribute.stack_map_frame.Visitor<Void,Void> {
523            public void write(StackMapTable_attribute.stack_map_frame frame) {
524                frame.accept(this, null);
525            }
526    
527            public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) {
528                printHeader(frame);
529                println(" /* same */");
530                return null;
531            }
532    
533            public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) {
534                printHeader(frame);
535                println(" /* same_locals_1_stack_item */");
536                printMap("stack", frame.stack);
537                return null;
538            }
539    
540            public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) {
541                printHeader(frame);
542                println(" /* same_locals_1_stack_item_frame_extended */");
543                println("     offset_delta = " + frame.offset_delta);
544                printMap("stack", frame.stack);
545                return null;
546            }
547    
548            public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) {
549                printHeader(frame);
550                println(" /* chop */");
551                println("     offset_delta = " + frame.offset_delta);
552                return null;
553            }
554    
555            public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) {
556                printHeader(frame);
557                println(" /* same_frame_extended */");
558                println("     offset_delta = " + frame.offset_delta);
559                return null;
560            }
561    
562            public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) {
563                printHeader(frame);
564                println(" /* append */");
565                println("     offset_delta = " + frame.offset_delta);
566                printMap("locals", frame.locals);
567                return null;
568            }
569    
570            public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) {
571                printHeader(frame);
572                if (frame instanceof StackMap_attribute.stack_map_frame) {
573                    println("     offset = " + frame.offset_delta);
574                } else {
575                    println(" /* full_frame */");
576                    println("     offset_delta = " + frame.offset_delta);
577                }
578                printMap("locals", frame.locals);
579                printMap("stack", frame.stack);
580                return null;
581            }
582    
583            void printHeader(StackMapTable_attribute.stack_map_frame frame) {
584                print("   frame_type = " + frame.frame_type);
585            }
586    
587            void printMap(String name, StackMapTable_attribute.verification_type_info[] map) {
588                print("     " + name + " = [");
589                for (int i = 0; i < map.length; i++) {
590                    StackMapTable_attribute.verification_type_info info = map[i];
591                    int tag = info.tag;
592                    switch (tag) {
593                        case StackMapTable_attribute.verification_type_info.ITEM_Object:
594                            print(" ");
595                            constantWriter.write(((StackMapTable_attribute.Object_variable_info) info).cpool_index);
596                            break;
597                        case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
598                            print(" " + mapTypeName(tag));
599                            print(" " + ((StackMapTable_attribute.Uninitialized_variable_info) info).offset);
600                            break;
601                        default:
602                            print(" " + mapTypeName(tag));
603                    }
604                    print(i == (map.length - 1) ? " " : ",");
605                }
606                println("]");
607            }
608    
609            String mapTypeName(int tag) {
610                switch (tag) {
611                case StackMapTable_attribute.verification_type_info.ITEM_Top:
612                    return "top";
613    
614                case StackMapTable_attribute.verification_type_info.ITEM_Integer:
615                    return "int";
616    
617                case StackMapTable_attribute.verification_type_info.ITEM_Float:
618                    return "float";
619    
620                case StackMapTable_attribute.verification_type_info.ITEM_Long:
621                    return "long";
622    
623                case StackMapTable_attribute.verification_type_info.ITEM_Double:
624                    return "double";
625    
626                case StackMapTable_attribute.verification_type_info.ITEM_Null:
627                    return "null";
628    
629                case StackMapTable_attribute.verification_type_info.ITEM_UninitializedThis:
630                    return "this";
631    
632                case StackMapTable_attribute.verification_type_info.ITEM_Object:
633                    return "CP";
634    
635                case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
636                    return "uninitialized";
637    
638                default:
639                    report("unrecognized verification_type_info tag: " + tag);
640                    return "[tag:" + tag + "]";
641                }
642            }
643        }
644    
645        public Void visitSynthetic(Synthetic_attribute attr, Void ignore) {
646            println("Synthetic: true");
647            return null;
648        }
649    
650        static String getJavaName(String name) {
651            return name.replace('/', '.');
652        }
653    
654        String toHex(byte b, int w) {
655            if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex
656                return toHex((int) b, w);
657            else
658                return toHex(b & 0xff, w);
659        }
660    
661        static String toHex(int i) {
662            return Integer.toString(i, 16).toUpperCase();
663        }
664    
665        static String toHex(int i, int w) {
666            String s = Integer.toHexString(i).toUpperCase();
667            while (s.length() < w)
668                s = "0" + s;
669            return s.toUpperCase();
670        }
671    
672        private AnnotationWriter annotationWriter;
673        private CodeWriter codeWriter;
674        private ConstantWriter constantWriter;
675        private Options options;
676    
677        private ConstantPool constant_pool;
678        private Object owner;
679    }