src/share/classes/com/sun/tools/javap/AttributeWriter.java

Sat, 29 Dec 2012 17:33:17 -0800

author
jjg
date
Sat, 29 Dec 2012 17:33:17 -0800
changeset 1473
31780dd06ec7
parent 826
5cf6c432ef2f
child 1521
71f35e4b93a5
permissions
-rw-r--r--

8004727: Add compiler support for parameter reflection
Reviewed-by: jjg
Contributed-by: eric.mccorkle@oracle.com

     1 /*
     2  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javap;
    28 import java.util.Formatter;
    30 import com.sun.tools.classfile.AccessFlags;
    31 import com.sun.tools.classfile.AnnotationDefault_attribute;
    32 import com.sun.tools.classfile.Attribute;
    33 import com.sun.tools.classfile.Attributes;
    34 import com.sun.tools.classfile.BootstrapMethods_attribute;
    35 import com.sun.tools.classfile.CharacterRangeTable_attribute;
    36 import com.sun.tools.classfile.Code_attribute;
    37 import com.sun.tools.classfile.CompilationID_attribute;
    38 import com.sun.tools.classfile.ConstantPool;
    39 import com.sun.tools.classfile.ConstantPoolException;
    40 import com.sun.tools.classfile.ConstantValue_attribute;
    41 import com.sun.tools.classfile.DefaultAttribute;
    42 import com.sun.tools.classfile.Deprecated_attribute;
    43 import com.sun.tools.classfile.EnclosingMethod_attribute;
    44 import com.sun.tools.classfile.Exceptions_attribute;
    45 import com.sun.tools.classfile.InnerClasses_attribute;
    46 import com.sun.tools.classfile.LineNumberTable_attribute;
    47 import com.sun.tools.classfile.LocalVariableTable_attribute;
    48 import com.sun.tools.classfile.LocalVariableTypeTable_attribute;
    49 import com.sun.tools.classfile.MethodParameters_attribute;
    50 import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
    51 import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
    52 import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
    53 import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
    54 import com.sun.tools.classfile.Signature_attribute;
    55 import com.sun.tools.classfile.SourceDebugExtension_attribute;
    56 import com.sun.tools.classfile.SourceFile_attribute;
    57 import com.sun.tools.classfile.SourceID_attribute;
    58 import com.sun.tools.classfile.StackMapTable_attribute;
    59 import com.sun.tools.classfile.StackMap_attribute;
    60 import com.sun.tools.classfile.Synthetic_attribute;
    62 import static com.sun.tools.classfile.AccessFlags.*;
    64 /*
    65  *  A writer for writing Attributes as text.
    66  *
    67  *  <p><b>This is NOT part of any supported API.
    68  *  If you write code that depends on this, you do so at your own risk.
    69  *  This code and its internal interfaces are subject to change or
    70  *  deletion without notice.</b>
    71  */
    72 public class AttributeWriter extends BasicWriter
    73         implements Attribute.Visitor<Void,Void>
    74 {
    75     public static AttributeWriter instance(Context context) {
    76         AttributeWriter instance = context.get(AttributeWriter.class);
    77         if (instance == null)
    78             instance = new AttributeWriter(context);
    79         return instance;
    80     }
    82     protected AttributeWriter(Context context) {
    83         super(context);
    84         context.put(AttributeWriter.class, this);
    85         annotationWriter = AnnotationWriter.instance(context);
    86         codeWriter = CodeWriter.instance(context);
    87         constantWriter = ConstantWriter.instance(context);
    88         options = Options.instance(context);
    89     }
    91     public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
    92         if (attr != null) {
    93             // null checks
    94             owner.getClass();
    95             constant_pool.getClass();
    96             this.constant_pool = constant_pool;
    97             this.owner = owner;
    98             attr.accept(this, null);
    99         }
   100     }
   102     public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
   103         if (attrs != null) {
   104             // null checks
   105             owner.getClass();
   106             constant_pool.getClass();
   107             this.constant_pool = constant_pool;
   108             this.owner = owner;
   109             for (Attribute attr: attrs)
   110                 attr.accept(this, null);
   111         }
   112     }
   114     public Void visitDefault(DefaultAttribute attr, Void ignore) {
   115         byte[] data = attr.info;
   116         int i = 0;
   117         int j = 0;
   118         print("  ");
   119         try {
   120             print(attr.getName(constant_pool));
   121         } catch (ConstantPoolException e) {
   122             report(e);
   123             print("attribute name = #" + attr.attribute_name_index);
   124         }
   125         print(": ");
   126         println("length = 0x" + toHex(attr.info.length));
   128         print("   ");
   130         while (i < data.length) {
   131             print(toHex(data[i], 2));
   133             j++;
   134             if (j == 16) {
   135                 println();
   136                 print("   ");
   137                 j = 0;
   138             } else {
   139                 print(" ");
   140             }
   141             i++;
   142         }
   143         println();
   144         return null;
   145     }
   147     public Void visitAnnotationDefault(AnnotationDefault_attribute attr, Void ignore) {
   148         println("AnnotationDefault:");
   149         indent(+1);
   150         print("default_value: ");
   151         annotationWriter.write(attr.default_value);
   152         indent(-1);
   153         return null;
   154     }
   156     public Void visitBootstrapMethods(BootstrapMethods_attribute attr, Void p) {
   157         println(Attribute.BootstrapMethods + ":");
   158         for (int i = 0; i < attr.bootstrap_method_specifiers.length ; i++) {
   159             BootstrapMethods_attribute.BootstrapMethodSpecifier bsm = attr.bootstrap_method_specifiers[i];
   160             indent(+1);
   161             print(i + ": #" + bsm.bootstrap_method_ref + " ");
   162             println(constantWriter.stringValue(bsm.bootstrap_method_ref));
   163             indent(+1);
   164             println("Method arguments:");
   165             indent(+1);
   166             for (int j = 0; j < bsm.bootstrap_arguments.length; j++) {
   167                 print("#" + bsm.bootstrap_arguments[j] + " ");
   168                 println(constantWriter.stringValue(bsm.bootstrap_arguments[j]));
   169             }
   170             indent(-3);
   171         }
   172         return null;
   173     }
   175     public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, Void ignore) {
   176         println("CharacterRangeTable:");
   177         indent(+1);
   178         for (int i = 0; i < attr.character_range_table.length; i++) {
   179             CharacterRangeTable_attribute.Entry e = attr.character_range_table[i];
   180             print(String.format("    %2d, %2d, %6x, %6x, %4x",
   181                     e.start_pc, e.end_pc,
   182                     e.character_range_start, e.character_range_end,
   183                     e.flags));
   184             tab();
   185             print(String.format("// %2d, %2d, %4d:%02d, %4d:%02d",
   186                     e.start_pc, e.end_pc,
   187                     (e.character_range_start >> 10), (e.character_range_start & 0x3ff),
   188                     (e.character_range_end >> 10), (e.character_range_end & 0x3ff)));
   189             if ((e.flags & CharacterRangeTable_attribute.CRT_STATEMENT) != 0)
   190                 print(", statement");
   191             if ((e.flags & CharacterRangeTable_attribute.CRT_BLOCK) != 0)
   192                 print(", block");
   193             if ((e.flags & CharacterRangeTable_attribute.CRT_ASSIGNMENT) != 0)
   194                 print(", assignment");
   195             if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_CONTROLLER) != 0)
   196                 print(", flow-controller");
   197             if ((e.flags & CharacterRangeTable_attribute.CRT_FLOW_TARGET) != 0)
   198                 print(", flow-target");
   199             if ((e.flags & CharacterRangeTable_attribute.CRT_INVOKE) != 0)
   200                 print(", invoke");
   201             if ((e.flags & CharacterRangeTable_attribute.CRT_CREATE) != 0)
   202                 print(", create");
   203             if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_TRUE) != 0)
   204                 print(", branch-true");
   205             if ((e.flags & CharacterRangeTable_attribute.CRT_BRANCH_FALSE) != 0)
   206                 print(", branch-false");
   207             println();
   208         }
   209         indent(-1);
   210         return null;
   211     }
   213     public Void visitCode(Code_attribute attr, Void ignore) {
   214         codeWriter.write(attr, constant_pool);
   215         return null;
   216     }
   218     public Void visitCompilationID(CompilationID_attribute attr, Void ignore) {
   219         constantWriter.write(attr.compilationID_index);
   220         return null;
   221     }
   223     public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) {
   224         if (options.compat) // BUG 6622216 javap names some attributes incorrectly
   225             print("Constant value: ");
   226         else
   227             print("ConstantValue: ");
   228         constantWriter.write(attr.constantvalue_index);
   229         println();
   230         return null;
   231     }
   233     public Void visitDeprecated(Deprecated_attribute attr, Void ignore) {
   234         println("Deprecated: true");
   235         return null;
   236     }
   238     public Void visitEnclosingMethod(EnclosingMethod_attribute attr, Void ignore) {
   239         print("EnclosingMethod: #" + attr.class_index + ".#" + attr.method_index);
   240         tab();
   241         print("// " + getJavaClassName(attr));
   242         if (attr.method_index != 0)
   243             print("." + getMethodName(attr));
   244         println();
   245         return null;
   246     }
   248     private String getJavaClassName(EnclosingMethod_attribute a) {
   249         try {
   250             return getJavaName(a.getClassName(constant_pool));
   251         } catch (ConstantPoolException e) {
   252             return report(e);
   253         }
   254     }
   256     private String getMethodName(EnclosingMethod_attribute a) {
   257         try {
   258             return a.getMethodName(constant_pool);
   259         } catch (ConstantPoolException e) {
   260             return report(e);
   261         }
   262     }
   264     public Void visitExceptions(Exceptions_attribute attr, Void ignore) {
   265         println("Exceptions:");
   266         indent(+1);
   267         print("throws ");
   268         for (int i = 0; i < attr.number_of_exceptions; i++) {
   269             if (i > 0)
   270                 print(", ");
   271             print(getJavaException(attr, i));
   272         }
   273         println();
   274         indent(-1);
   275         return null;
   276     }
   278     private String getJavaException(Exceptions_attribute attr, int index) {
   279         try {
   280             return getJavaName(attr.getException(index, constant_pool));
   281         } catch (ConstantPoolException e) {
   282             return report(e);
   283         }
   284     }
   286     public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) {
   287         boolean first = true;
   288         if (options.compat) {
   289             writeInnerClassHeader();
   290             first = false;
   291         }
   292         for (int i = 0 ; i < attr.classes.length; i++) {
   293             InnerClasses_attribute.Info info = attr.classes[i];
   294             //access
   295             AccessFlags access_flags = info.inner_class_access_flags;
   296             if (options.compat) {
   297                 // BUG 6622215: javap ignores certain relevant access flags
   298                 access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM);
   299                 // BUG 6622232: javap gets whitespace confused
   300                 print("   ");
   301             }
   302             if (options.checkAccess(access_flags)) {
   303                 if (first) {
   304                     writeInnerClassHeader();
   305                     first = false;
   306                 }
   307                 print("   ");
   308                 for (String name: access_flags.getInnerClassModifiers())
   309                     print(name + " ");
   310                 if (info.inner_name_index!=0) {
   311                     print("#" + info.inner_name_index + "= ");
   312                 }
   313                 print("#" + info.inner_class_info_index);
   314                 if (info.outer_class_info_index != 0) {
   315                     print(" of #" + info.outer_class_info_index);
   316                 }
   317                 print("; //");
   318                 if (info.inner_name_index != 0) {
   319                     print(getInnerName(constant_pool, info) + "=");
   320                 }
   321                 constantWriter.write(info.inner_class_info_index);
   322                 if (info.outer_class_info_index != 0) {
   323                     print(" of ");
   324                     constantWriter.write(info.outer_class_info_index);
   325                 }
   326                 println();
   327             }
   328         }
   329         if (!first)
   330             indent(-1);
   331         return null;
   332     }
   334     String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) {
   335         try {
   336             return info.getInnerName(constant_pool);
   337         } catch (ConstantPoolException e) {
   338             return report(e);
   339         }
   340     }
   342     private void writeInnerClassHeader() {
   343         if (options.compat) // BUG 6622216: javap names some attributes incorrectly
   344             print("InnerClass");
   345         else
   346             print("InnerClasses");
   347         println(":");
   348         indent(+1);
   349     }
   351     public Void visitLineNumberTable(LineNumberTable_attribute attr, Void ignore) {
   352         println("LineNumberTable:");
   353         indent(+1);
   354         for (LineNumberTable_attribute.Entry entry: attr.line_number_table) {
   355             println("line " + entry.line_number + ": " + entry.start_pc);
   356         }
   357         indent(-1);
   358         return null;
   359     }
   361     public Void visitLocalVariableTable(LocalVariableTable_attribute attr, Void ignore) {
   362         println("LocalVariableTable:");
   363         indent(+1);
   364         println("Start  Length  Slot  Name   Signature");
   365         for (LocalVariableTable_attribute.Entry entry : attr.local_variable_table) {
   366             Formatter formatter = new Formatter();
   367             println(formatter.format("%8d %7d %5d %5s   %s",
   368                     entry.start_pc, entry.length, entry.index,
   369                     constantWriter.stringValue(entry.name_index),
   370                     constantWriter.stringValue(entry.descriptor_index)));
   371         }
   372         indent(-1);
   373         return null;
   374     }
   376     public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, Void ignore) {
   377         println("LocalVariableTypeTable:");
   378         indent(+1);
   379         println("Start  Length  Slot  Name   Signature");
   380         for (LocalVariableTypeTable_attribute.Entry entry : attr.local_variable_table) {
   381             println(String.format("%5d %7d %5d %5s   %s",
   382                     entry.start_pc, entry.length, entry.index,
   383                     constantWriter.stringValue(entry.name_index),
   384                     constantWriter.stringValue(entry.signature_index)));
   385         }
   386         indent(-1);
   387         return null;
   388     }
   390     private static final String format = "%-31s%s";
   392     public Void visitMethodParameters(MethodParameters_attribute attr,
   393                                       Void ignore) {
   395         final String header = String.format(format, "Name", "Flags");
   396         println("MethodParameters:");
   397         indent(+1);
   398         println(header);
   399         for (MethodParameters_attribute.Entry entry :
   400                  attr.method_parameter_table) {
   401             String flagstr =
   402                 (0 != (entry.flags & ACC_FINAL) ? " final" : "") +
   403                 (0 != (entry.flags & ACC_SYNTHETIC) ? " synthetic" : "");
   404             println(String.format(format,
   405                                   constantWriter.stringValue(entry.name_index),
   406                                   flagstr));
   407         }
   408         indent(-1);
   409         return null;
   410     }
   412     public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, Void ignore) {
   413         println("RuntimeVisibleAnnotations:");
   414         indent(+1);
   415         for (int i = 0; i < attr.annotations.length; i++) {
   416             print(i + ": ");
   417             annotationWriter.write(attr.annotations[i]);
   418             println();
   419         }
   420         indent(-1);
   421         return null;
   422     }
   424     public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, Void ignore) {
   425         println("RuntimeInvisibleAnnotations:");
   426         indent(+1);
   427         for (int i = 0; i < attr.annotations.length; i++) {
   428             print(i + ": ");
   429             annotationWriter.write(attr.annotations[i]);
   430             println();
   431         }
   432         indent(-1);
   433         return null;
   434     }
   436     public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, Void ignore) {
   437         println("RuntimeVisibleParameterAnnotations:");
   438         indent(+1);
   439         for (int param = 0; param < attr.parameter_annotations.length; param++) {
   440             println("parameter " + param + ": ");
   441             indent(+1);
   442             for (int i = 0; i < attr.parameter_annotations[param].length; i++) {
   443                 print(i + ": ");
   444                 annotationWriter.write(attr.parameter_annotations[param][i]);
   445                 println();
   446             }
   447             indent(-1);
   448         }
   449         indent(-1);
   450         return null;
   451     }
   453     public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, Void ignore) {
   454         println("RuntimeInvisibleParameterAnnotations:");
   455         indent(+1);
   456         for (int param = 0; param < attr.parameter_annotations.length; param++) {
   457             println(param + ": ");
   458             indent(+1);
   459             for (int i = 0; i < attr.parameter_annotations[param].length; i++) {
   460                 print(i + ": ");
   461                 annotationWriter.write(attr.parameter_annotations[param][i]);
   462                 println();
   463             }
   464             indent(-1);
   465         }
   466         indent(-1);
   467         return null;
   468     }
   470     public Void visitSignature(Signature_attribute attr, Void ignore) {
   471         print("Signature: #" + attr.signature_index);
   472         tab();
   473         println("// " + getSignature(attr));
   474         return null;
   475     }
   477     String getSignature(Signature_attribute info) {
   478         try {
   479             return info.getSignature(constant_pool);
   480         } catch (ConstantPoolException e) {
   481             return report(e);
   482         }
   483     }
   485     public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, Void ignore) {
   486         println("SourceDebugExtension: " + attr.getValue());
   487         return null;
   488     }
   490     public Void visitSourceFile(SourceFile_attribute attr, Void ignore) {
   491         println("SourceFile: \"" + getSourceFile(attr) + "\"");
   492         return null;
   493     }
   495     private String getSourceFile(SourceFile_attribute attr) {
   496         try {
   497             return attr.getSourceFile(constant_pool);
   498         } catch (ConstantPoolException e) {
   499             return report(e);
   500         }
   501     }
   503     public Void visitSourceID(SourceID_attribute attr, Void ignore) {
   504         constantWriter.write(attr.sourceID_index);
   505         return null;
   506     }
   508     public Void visitStackMap(StackMap_attribute attr, Void ignore) {
   509         println("StackMap: number_of_entries = " + attr.number_of_entries);
   510         indent(+1);
   511         StackMapTableWriter w = new StackMapTableWriter();
   512         for (StackMapTable_attribute.stack_map_frame entry : attr.entries) {
   513             w.write(entry);
   514         }
   515         println();
   516         indent(-1);
   517         return null;
   518     }
   520     public Void visitStackMapTable(StackMapTable_attribute attr, Void ignore) {
   521         println("StackMapTable: number_of_entries = " + attr.number_of_entries);
   522         indent(+1);
   523         StackMapTableWriter w = new StackMapTableWriter();
   524         for (StackMapTable_attribute.stack_map_frame entry : attr.entries) {
   525             w.write(entry);
   526         }
   527         println();
   528         indent(-1);
   529         return null;
   530     }
   532     class StackMapTableWriter // also handles CLDC StackMap attributes
   533             implements StackMapTable_attribute.stack_map_frame.Visitor<Void,Void> {
   534         public void write(StackMapTable_attribute.stack_map_frame frame) {
   535             frame.accept(this, null);
   536         }
   538         public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) {
   539             printHeader(frame);
   540             println(" /* same */");
   541             return null;
   542         }
   544         public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) {
   545             printHeader(frame);
   546             println(" /* same_locals_1_stack_item */");
   547             indent(+1);
   548             printMap("stack", frame.stack);
   549             indent(-1);
   550             return null;
   551         }
   553         public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) {
   554             printHeader(frame);
   555             println(" /* same_locals_1_stack_item_frame_extended */");
   556             indent(+1);
   557             println("offset_delta = " + frame.offset_delta);
   558             printMap("stack", frame.stack);
   559             indent(-1);
   560             return null;
   561         }
   563         public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) {
   564             printHeader(frame);
   565             println(" /* chop */");
   566             indent(+1);
   567             println("offset_delta = " + frame.offset_delta);
   568             indent(-1);
   569             return null;
   570         }
   572         public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) {
   573             printHeader(frame);
   574             println(" /* same_frame_extended */");
   575             indent(+1);
   576             println("offset_delta = " + frame.offset_delta);
   577             indent(-1);
   578             return null;
   579         }
   581         public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) {
   582             printHeader(frame);
   583             println(" /* append */");
   584             println("     offset_delta = " + frame.offset_delta);
   585             printMap("locals", frame.locals);
   586             return null;
   587         }
   589         public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) {
   590             printHeader(frame);
   591             if (frame instanceof StackMap_attribute.stack_map_frame) {
   592                 indent(+1);
   593                 println(" offset = " + frame.offset_delta);
   594             } else {
   595                 println(" /* full_frame */");
   596                 indent(+1);
   597                 println("offset_delta = " + frame.offset_delta);
   598             }
   599             printMap("locals", frame.locals);
   600             printMap("stack", frame.stack);
   601             indent(-1);
   602             return null;
   603         }
   605         void printHeader(StackMapTable_attribute.stack_map_frame frame) {
   606             print("   frame_type = " + frame.frame_type);
   607         }
   609         void printMap(String name, StackMapTable_attribute.verification_type_info[] map) {
   610             print(name + " = [");
   611             for (int i = 0; i < map.length; i++) {
   612                 StackMapTable_attribute.verification_type_info info = map[i];
   613                 int tag = info.tag;
   614                 switch (tag) {
   615                     case StackMapTable_attribute.verification_type_info.ITEM_Object:
   616                         print(" ");
   617                         constantWriter.write(((StackMapTable_attribute.Object_variable_info) info).cpool_index);
   618                         break;
   619                     case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
   620                         print(" " + mapTypeName(tag));
   621                         print(" " + ((StackMapTable_attribute.Uninitialized_variable_info) info).offset);
   622                         break;
   623                     default:
   624                         print(" " + mapTypeName(tag));
   625                 }
   626                 print(i == (map.length - 1) ? " " : ",");
   627             }
   628             println("]");
   629         }
   631         String mapTypeName(int tag) {
   632             switch (tag) {
   633             case StackMapTable_attribute.verification_type_info.ITEM_Top:
   634                 return "top";
   636             case StackMapTable_attribute.verification_type_info.ITEM_Integer:
   637                 return "int";
   639             case StackMapTable_attribute.verification_type_info.ITEM_Float:
   640                 return "float";
   642             case StackMapTable_attribute.verification_type_info.ITEM_Long:
   643                 return "long";
   645             case StackMapTable_attribute.verification_type_info.ITEM_Double:
   646                 return "double";
   648             case StackMapTable_attribute.verification_type_info.ITEM_Null:
   649                 return "null";
   651             case StackMapTable_attribute.verification_type_info.ITEM_UninitializedThis:
   652                 return "this";
   654             case StackMapTable_attribute.verification_type_info.ITEM_Object:
   655                 return "CP";
   657             case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
   658                 return "uninitialized";
   660             default:
   661                 report("unrecognized verification_type_info tag: " + tag);
   662                 return "[tag:" + tag + "]";
   663             }
   664         }
   665     }
   667     public Void visitSynthetic(Synthetic_attribute attr, Void ignore) {
   668         println("Synthetic: true");
   669         return null;
   670     }
   672     static String getJavaName(String name) {
   673         return name.replace('/', '.');
   674     }
   676     String toHex(byte b, int w) {
   677         if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex
   678             return toHex((int) b, w);
   679         else
   680             return toHex(b & 0xff, w);
   681     }
   683     static String toHex(int i) {
   684         return Integer.toString(i, 16).toUpperCase();
   685     }
   687     static String toHex(int i, int w) {
   688         String s = Integer.toHexString(i).toUpperCase();
   689         while (s.length() < w)
   690             s = "0" + s;
   691         return s.toUpperCase();
   692     }
   694     private AnnotationWriter annotationWriter;
   695     private CodeWriter codeWriter;
   696     private ConstantWriter constantWriter;
   697     private Options options;
   699     private ConstantPool constant_pool;
   700     private Object owner;
   701 }

mercurial