< prev index next >

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

Print this page

  63 import com.sun.tools.classfile.Record_attribute;
  64 import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
  65 import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
  66 import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute;
  67 import com.sun.tools.classfile.RuntimeParameterAnnotations_attribute;
  68 import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
  69 import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
  70 import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute;
  71 import com.sun.tools.classfile.PermittedSubclasses_attribute;
  72 import com.sun.tools.classfile.Signature_attribute;
  73 import com.sun.tools.classfile.SourceDebugExtension_attribute;
  74 import com.sun.tools.classfile.SourceFile_attribute;
  75 import com.sun.tools.classfile.SourceID_attribute;
  76 import com.sun.tools.classfile.StackMapTable_attribute;
  77 import com.sun.tools.classfile.StackMap_attribute;
  78 import com.sun.tools.classfile.Synthetic_attribute;
  79 import com.sun.tools.classfile.Type;
  80 
  81 import static com.sun.tools.classfile.AccessFlags.*;
  82 

  83 import com.sun.tools.javac.util.Assert;
  84 import com.sun.tools.javac.util.StringUtils;
  85 
  86 /*
  87  *  A writer for writing Attributes as text.
  88  *
  89  *  <p><b>This is NOT part of any supported API.
  90  *  If you write code that depends on this, you do so at your own risk.
  91  *  This code and its internal interfaces are subject to change or
  92  *  deletion without notice.</b>
  93  */
  94 public class AttributeWriter extends BasicWriter
  95         implements Attribute.Visitor<Void,Void>
  96 {
  97     public static AttributeWriter instance(Context context) {
  98         AttributeWriter instance = context.get(AttributeWriter.class);
  99         if (instance == null)
 100             instance = new AttributeWriter(context);
 101         return instance;
 102     }

1095 
1096             case StackMapTable_attribute.verification_type_info.ITEM_Object:
1097                 return "CP";
1098 
1099             case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
1100                 return "uninitialized";
1101 
1102             default:
1103                 report("unrecognized verification_type_info tag: " + tag);
1104                 return "[tag:" + tag + "]";
1105             }
1106         }
1107     }
1108 
1109     @Override
1110     public Void visitSynthetic(Synthetic_attribute attr, Void ignore) {
1111         println("Synthetic: true");
1112         return null;
1113     }
1114 





















1115     static String getJavaName(String name) {
1116         return name.replace('/', '.');
1117     }
1118 
1119     String toHex(byte b, int w) {
1120         return toHex(b & 0xff, w);
1121     }
1122 
1123     static String toHex(int i) {
1124         return StringUtils.toUpperCase(Integer.toString(i, 16));
1125     }
1126 
1127     static String toHex(int i, int w) {
1128         String s = StringUtils.toUpperCase(Integer.toHexString(i));
1129         while (s.length() < w)
1130             s = "0" + s;
1131         return StringUtils.toUpperCase(s);
1132     }
1133 
1134     static String toHex(byte[] ba) {

  63 import com.sun.tools.classfile.Record_attribute;
  64 import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
  65 import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute;
  66 import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute;
  67 import com.sun.tools.classfile.RuntimeParameterAnnotations_attribute;
  68 import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
  69 import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute;
  70 import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute;
  71 import com.sun.tools.classfile.PermittedSubclasses_attribute;
  72 import com.sun.tools.classfile.Signature_attribute;
  73 import com.sun.tools.classfile.SourceDebugExtension_attribute;
  74 import com.sun.tools.classfile.SourceFile_attribute;
  75 import com.sun.tools.classfile.SourceID_attribute;
  76 import com.sun.tools.classfile.StackMapTable_attribute;
  77 import com.sun.tools.classfile.StackMap_attribute;
  78 import com.sun.tools.classfile.Synthetic_attribute;
  79 import com.sun.tools.classfile.Type;
  80 
  81 import static com.sun.tools.classfile.AccessFlags.*;
  82 
  83 import com.sun.tools.classfile.Preload_attribute;
  84 import com.sun.tools.javac.util.Assert;
  85 import com.sun.tools.javac.util.StringUtils;
  86 
  87 /*
  88  *  A writer for writing Attributes as text.
  89  *
  90  *  <p><b>This is NOT part of any supported API.
  91  *  If you write code that depends on this, you do so at your own risk.
  92  *  This code and its internal interfaces are subject to change or
  93  *  deletion without notice.</b>
  94  */
  95 public class AttributeWriter extends BasicWriter
  96         implements Attribute.Visitor<Void,Void>
  97 {
  98     public static AttributeWriter instance(Context context) {
  99         AttributeWriter instance = context.get(AttributeWriter.class);
 100         if (instance == null)
 101             instance = new AttributeWriter(context);
 102         return instance;
 103     }

1096 
1097             case StackMapTable_attribute.verification_type_info.ITEM_Object:
1098                 return "CP";
1099 
1100             case StackMapTable_attribute.verification_type_info.ITEM_Uninitialized:
1101                 return "uninitialized";
1102 
1103             default:
1104                 report("unrecognized verification_type_info tag: " + tag);
1105                 return "[tag:" + tag + "]";
1106             }
1107         }
1108     }
1109 
1110     @Override
1111     public Void visitSynthetic(Synthetic_attribute attr, Void ignore) {
1112         println("Synthetic: true");
1113         return null;
1114     }
1115 
1116     @Override
1117     public Void visitPreload(Preload_attribute attr, Void ignore) {
1118         boolean first = true;
1119         for (int index : attr.value_class_info_index) {
1120             if (first) {
1121                 println("Classes to be preloaded:");
1122                 indent(+1);
1123                 first = false;
1124             }
1125             print("#" + index);
1126             print(";");
1127             tab();
1128             print("// value ");
1129             constantWriter.write(index);
1130             println();
1131         }
1132         if (!first)
1133             indent(-1);
1134         return null;
1135     }
1136 
1137     static String getJavaName(String name) {
1138         return name.replace('/', '.');
1139     }
1140 
1141     String toHex(byte b, int w) {
1142         return toHex(b & 0xff, w);
1143     }
1144 
1145     static String toHex(int i) {
1146         return StringUtils.toUpperCase(Integer.toString(i, 16));
1147     }
1148 
1149     static String toHex(int i, int w) {
1150         String s = StringUtils.toUpperCase(Integer.toHexString(i));
1151         while (s.length() < w)
1152             s = "0" + s;
1153         return StringUtils.toUpperCase(s);
1154     }
1155 
1156     static String toHex(byte[] ba) {
< prev index next >