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

Print this page




  74             write(annot.element_value_pairs[i], resolveIndices);
  75         }
  76         if (showParens)
  77             print(")");
  78     }
  79 
  80     public void write(TypeAnnotation annot) {
  81         write(annot, true, false);
  82     }
  83 
  84     public void write(TypeAnnotation annot, boolean showOffsets, boolean resolveIndices) {
  85         write(annot.annotation, resolveIndices);
  86         print(": ");
  87         write(annot.position, showOffsets);
  88     }
  89 
  90     public void write(TypeAnnotation.Position pos, boolean showOffsets) {
  91         print(pos.type);
  92 
  93         switch (pos.type) {
  94         // type cast
  95         case CAST:
  96         // instanceof
  97         case INSTANCEOF:
  98         // new expression
  99         case NEW:



 100             if (showOffsets) {
 101                 print(", offset=");
 102                 print(pos.offset);
 103             }
 104             break;
 105         // local variable
 106         case LOCAL_VARIABLE:
 107         // resource variable
 108         case RESOURCE_VARIABLE:
 109             if (pos.lvarOffset == null) {
 110                 print(", lvarOffset is Null!");
 111                 break;
 112             }
 113             print(", {");
 114             for (int i = 0; i < pos.lvarOffset.length; ++i) {
 115                 if (i != 0) print("; ");
 116                 if (showOffsets) {
 117                     print("start_pc=");
 118                     print(pos.lvarOffset[i]);
 119                 }


 145             print(", param_index=");
 146             print(pos.parameter_index);
 147             print(", bound_index=");
 148             print(pos.bound_index);
 149             break;
 150         // class extends or implements clause
 151         case CLASS_EXTENDS:
 152             print(", type_index=");
 153             print(pos.type_index);
 154             break;
 155         // throws
 156         case THROWS:
 157             print(", type_index=");
 158             print(pos.type_index);
 159             break;
 160         // method parameter
 161         case METHOD_FORMAL_PARAMETER:
 162             print(", param_index=");
 163             print(pos.parameter_index);
 164             break;


 165         // method/constructor/reference type argument
 166         case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
 167         case METHOD_INVOCATION_TYPE_ARGUMENT:

 168         case METHOD_REFERENCE_TYPE_ARGUMENT:
 169             if (showOffsets) {
 170                 print(", offset=");
 171                 print(pos.offset);
 172             }
 173             print(", type_index=");
 174             print(pos.type_index);
 175             break;
 176         // We don't need to worry about these
 177         case METHOD_RETURN:
 178         case FIELD:
 179             break;
 180         // lambda formal parameter
 181         case LAMBDA_FORMAL_PARAMETER:
 182             print(", param_index=");
 183             print(pos.parameter_index);
 184             break;
 185         case UNKNOWN:
 186             throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!");
 187         default:
 188             throw new AssertionError("AnnotationWriter: Unknown target type for position: " + pos);
 189         }
 190 
 191         // Append location data for generics/arrays.
 192         if (!pos.location.isEmpty()) {
 193             print(", location=");
 194             print(pos.location);
 195         }
 196     }
 197 
 198     public void write(Annotation.element_value_pair pair) {
 199         write(pair, false);
 200     }
 201 
 202     public void write(Annotation.element_value_pair pair, boolean resolveIndices) {
 203         writeIndex(pair.element_name_index, resolveIndices);




  74             write(annot.element_value_pairs[i], resolveIndices);
  75         }
  76         if (showParens)
  77             print(")");
  78     }
  79 
  80     public void write(TypeAnnotation annot) {
  81         write(annot, true, false);
  82     }
  83 
  84     public void write(TypeAnnotation annot, boolean showOffsets, boolean resolveIndices) {
  85         write(annot.annotation, resolveIndices);
  86         print(": ");
  87         write(annot.position, showOffsets);
  88     }
  89 
  90     public void write(TypeAnnotation.Position pos, boolean showOffsets) {
  91         print(pos.type);
  92 
  93         switch (pos.type) {


  94         // instanceof
  95         case INSTANCEOF:
  96         // new expression
  97         case NEW:
  98         // constructor/method reference receiver
  99         case CONSTRUCTOR_REFERENCE:
 100         case METHOD_REFERENCE:
 101             if (showOffsets) {
 102                 print(", offset=");
 103                 print(pos.offset);
 104             }
 105             break;
 106         // local variable
 107         case LOCAL_VARIABLE:
 108         // resource variable
 109         case RESOURCE_VARIABLE:
 110             if (pos.lvarOffset == null) {
 111                 print(", lvarOffset is Null!");
 112                 break;
 113             }
 114             print(", {");
 115             for (int i = 0; i < pos.lvarOffset.length; ++i) {
 116                 if (i != 0) print("; ");
 117                 if (showOffsets) {
 118                     print("start_pc=");
 119                     print(pos.lvarOffset[i]);
 120                 }


 146             print(", param_index=");
 147             print(pos.parameter_index);
 148             print(", bound_index=");
 149             print(pos.bound_index);
 150             break;
 151         // class extends or implements clause
 152         case CLASS_EXTENDS:
 153             print(", type_index=");
 154             print(pos.type_index);
 155             break;
 156         // throws
 157         case THROWS:
 158             print(", type_index=");
 159             print(pos.type_index);
 160             break;
 161         // method parameter
 162         case METHOD_FORMAL_PARAMETER:
 163             print(", param_index=");
 164             print(pos.parameter_index);
 165             break;
 166         // type cast
 167         case CAST:
 168         // method/constructor/reference type argument
 169         case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
 170         case METHOD_INVOCATION_TYPE_ARGUMENT:
 171         case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
 172         case METHOD_REFERENCE_TYPE_ARGUMENT:
 173             if (showOffsets) {
 174                 print(", offset=");
 175                 print(pos.offset);
 176             }
 177             print(", type_index=");
 178             print(pos.type_index);
 179             break;
 180         // We don't need to worry about these
 181         case METHOD_RETURN:
 182         case FIELD:





 183             break;
 184         case UNKNOWN:
 185             throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!");
 186         default:
 187             throw new AssertionError("AnnotationWriter: Unknown target type for position: " + pos);
 188         }
 189 
 190         // Append location data for generics/arrays.
 191         if (!pos.location.isEmpty()) {
 192             print(", location=");
 193             print(pos.location);
 194         }
 195     }
 196 
 197     public void write(Annotation.element_value_pair pair) {
 198         write(pair, false);
 199     }
 200 
 201     public void write(Annotation.element_value_pair pair, boolean resolveIndices) {
 202         writeIndex(pair.element_name_index, resolveIndices);