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

changeset 1521
71f35e4b93a5
parent 815
d17f37522154
child 1563
bc456436c613
     1.1 --- a/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Wed Jan 23 20:57:40 2013 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javap/AnnotationWriter.java	Wed Jan 23 13:27:24 2013 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -26,6 +26,7 @@
    1.11  package com.sun.tools.javap;
    1.12  
    1.13  import com.sun.tools.classfile.Annotation;
    1.14 +import com.sun.tools.classfile.TypeAnnotation;
    1.15  import com.sun.tools.classfile.Annotation.Annotation_element_value;
    1.16  import com.sun.tools.classfile.Annotation.Array_element_value;
    1.17  import com.sun.tools.classfile.Annotation.Class_element_value;
    1.18 @@ -76,6 +77,124 @@
    1.19              print(")");
    1.20      }
    1.21  
    1.22 +    public void write(TypeAnnotation annot) {
    1.23 +        write(annot, true, false);
    1.24 +    }
    1.25 +
    1.26 +    public void write(TypeAnnotation annot, boolean showOffsets, boolean resolveIndices) {
    1.27 +        write(annot.annotation, resolveIndices);
    1.28 +        print(": ");
    1.29 +        write(annot.position, showOffsets);
    1.30 +    }
    1.31 +
    1.32 +    public void write(TypeAnnotation.Position pos, boolean showOffsets) {
    1.33 +        print(pos.type);
    1.34 +
    1.35 +        switch (pos.type) {
    1.36 +        // type cast
    1.37 +        case CAST:
    1.38 +        // instanceof
    1.39 +        case INSTANCEOF:
    1.40 +        // new expression
    1.41 +        case NEW:
    1.42 +            if (showOffsets) {
    1.43 +                print(", offset=");
    1.44 +                print(pos.offset);
    1.45 +            }
    1.46 +            break;
    1.47 +        // local variable
    1.48 +        case LOCAL_VARIABLE:
    1.49 +        // resource variable
    1.50 +        case RESOURCE_VARIABLE:
    1.51 +            if (pos.lvarOffset == null) {
    1.52 +                print(", lvarOffset is Null!");
    1.53 +                break;
    1.54 +            }
    1.55 +            print(", {");
    1.56 +            for (int i = 0; i < pos.lvarOffset.length; ++i) {
    1.57 +                if (i != 0) print("; ");
    1.58 +                if (showOffsets) {
    1.59 +                    print("start_pc=");
    1.60 +                    print(pos.lvarOffset[i]);
    1.61 +                }
    1.62 +                print(", length=");
    1.63 +                print(pos.lvarLength[i]);
    1.64 +                print(", index=");
    1.65 +                print(pos.lvarIndex[i]);
    1.66 +            }
    1.67 +            print("}");
    1.68 +            break;
    1.69 +        // exception parameter
    1.70 +        case EXCEPTION_PARAMETER:
    1.71 +            print(", exception_index=");
    1.72 +            print(pos.exception_index);
    1.73 +            break;
    1.74 +        // method receiver
    1.75 +        case METHOD_RECEIVER:
    1.76 +            // Do nothing
    1.77 +            break;
    1.78 +        // type parameter
    1.79 +        case CLASS_TYPE_PARAMETER:
    1.80 +        case METHOD_TYPE_PARAMETER:
    1.81 +            print(", param_index=");
    1.82 +            print(pos.parameter_index);
    1.83 +            break;
    1.84 +        // type parameter bound
    1.85 +        case CLASS_TYPE_PARAMETER_BOUND:
    1.86 +        case METHOD_TYPE_PARAMETER_BOUND:
    1.87 +            print(", param_index=");
    1.88 +            print(pos.parameter_index);
    1.89 +            print(", bound_index=");
    1.90 +            print(pos.bound_index);
    1.91 +            break;
    1.92 +        // class extends or implements clause
    1.93 +        case CLASS_EXTENDS:
    1.94 +            print(", type_index=");
    1.95 +            print(pos.type_index);
    1.96 +            break;
    1.97 +        // throws
    1.98 +        case THROWS:
    1.99 +            print(", type_index=");
   1.100 +            print(pos.type_index);
   1.101 +            break;
   1.102 +        // method parameter
   1.103 +        case METHOD_FORMAL_PARAMETER:
   1.104 +            print(", param_index=");
   1.105 +            print(pos.parameter_index);
   1.106 +            break;
   1.107 +        // method/constructor/reference type argument
   1.108 +        case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
   1.109 +        case METHOD_INVOCATION_TYPE_ARGUMENT:
   1.110 +        case METHOD_REFERENCE_TYPE_ARGUMENT:
   1.111 +            if (showOffsets) {
   1.112 +                print(", offset=");
   1.113 +                print(pos.offset);
   1.114 +            }
   1.115 +            print(", type_index=");
   1.116 +            print(pos.type_index);
   1.117 +            break;
   1.118 +        // We don't need to worry about these
   1.119 +        case METHOD_RETURN:
   1.120 +        case FIELD:
   1.121 +            break;
   1.122 +        // lambda formal parameter
   1.123 +        case LAMBDA_FORMAL_PARAMETER:
   1.124 +            print(", param_index=");
   1.125 +            print(pos.parameter_index);
   1.126 +            break;
   1.127 +        case UNKNOWN:
   1.128 +            throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!");
   1.129 +        default:
   1.130 +            throw new AssertionError("AnnotationWriter: Unknown target type for position: " + pos);
   1.131 +        }
   1.132 +
   1.133 +        // Append location data for generics/arrays.
   1.134 +        if (!pos.location.isEmpty()) {
   1.135 +            print(", location=");
   1.136 +            print(pos.location);
   1.137 +        }
   1.138 +    }
   1.139 +
   1.140      public void write(Annotation.element_value_pair pair) {
   1.141          write(pair, false);
   1.142      }

mercurial