--- old/src/share/classes/jdk/internal/org/objectweb/asm/AnnotationWriter.java Thu Apr 25 10:08:28 2013 +++ new/src/share/classes/jdk/internal/org/objectweb/asm/AnnotationWriter.java Thu Apr 25 10:08:28 2013 @@ -119,21 +119,21 @@ /** * Constructs a new {@link AnnotationWriter}. * - * @param cw the class writer to which this annotation must be added. - * @param named true if values are named, false otherwise. - * @param bv where the annotation values must be stored. - * @param parent where the number of annotation values must be stored. - * @param offset where in parent the number of annotation values must - * be stored. + * @param cw + * the class writer to which this annotation must be added. + * @param named + * true if values are named, false otherwise. + * @param bv + * where the annotation values must be stored. + * @param parent + * where the number of annotation values must be stored. + * @param offset + * where in parent the number of annotation values must + * be stored. */ - AnnotationWriter( - final ClassWriter cw, - final boolean named, - final ByteVector bv, - final ByteVector parent, - final int offset) - { - super(Opcodes.ASM4); + AnnotationWriter(final ClassWriter cw, final boolean named, + final ByteVector bv, final ByteVector parent, final int offset) { + super(Opcodes.ASM5); this.cw = cw; this.named = named; this.bv = bv; @@ -219,11 +219,8 @@ } @Override - public void visitEnum( - final String name, - final String desc, - final String value) - { + public void visitEnum(final String name, final String desc, + final String value) { ++size; if (named) { bv.putShort(cw.newUTF8(name)); @@ -232,10 +229,8 @@ } @Override - public AnnotationVisitor visitAnnotation( - final String name, - final String desc) - { + public AnnotationVisitor visitAnnotation(final String name, + final String desc) { ++size; if (named) { bv.putShort(cw.newUTF8(name)); @@ -288,7 +283,8 @@ * Puts the annotations of this annotation writer list into the given byte * vector. * - * @param out where the annotations must be put. + * @param out + * where the annotations must be put. */ void put(final ByteVector out) { int n = 0; @@ -315,15 +311,15 @@ /** * Puts the given annotation lists into the given byte vector. * - * @param panns an array of annotation writer lists. - * @param off index of the first annotation to be written. - * @param out where the annotations must be put. + * @param panns + * an array of annotation writer lists. + * @param off + * index of the first annotation to be written. + * @param out + * where the annotations must be put. */ - static void put( - final AnnotationWriter[] panns, - final int off, - final ByteVector out) - { + static void put(final AnnotationWriter[] panns, final int off, + final ByteVector out) { int size = 1 + 2 * (panns.length - off); for (int i = off; i < panns.length; ++i) { size += panns[i] == null ? 0 : panns[i].getSize(); @@ -348,4 +344,57 @@ } } } + + /** + * Puts the given type reference and type path into the given bytevector. + * LOCAL_VARIABLE and RESOURCE_VARIABLE target types are not supported. + * + * @param typeRef + * a reference to the annotated type. See {@link TypeReference}. + * @param typePath + * the path to the annotated type argument, wildcard bound, array + * element type, or static inner type within 'typeRef'. May be + * null if the annotation targets 'typeRef' as a whole. + * @param out + * where the type reference and type path must be put. + */ + static void putTarget(int typeRef, TypePath typePath, ByteVector out) { + switch (typeRef >>> 24) { + case 0x00: // CLASS_TYPE_PARAMETER + case 0x01: // METHOD_TYPE_PARAMETER + case 0x16: // METHOD_FORMAL_PARAMETER + out.putShort(typeRef >>> 16); + break; + case 0x13: // FIELD + case 0x14: // METHOD_RETURN + case 0x15: // METHOD_RECEIVER + out.putByte(typeRef >>> 24); + break; + case 0x47: // CAST + case 0x48: // CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT + case 0x49: // METHOD_INVOCATION_TYPE_ARGUMENT + case 0x4A: // CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT + case 0x4B: // METHOD_REFERENCE_TYPE_ARGUMENT + out.putInt(typeRef); + break; + // case 0x10: // CLASS_EXTENDS + // case 0x11: // CLASS_TYPE_PARAMETER_BOUND + // case 0x12: // METHOD_TYPE_PARAMETER_BOUND + // case 0x17: // THROWS + // case 0x42: // EXCEPTION_PARAMETER + // case 0x43: // INSTANCEOF + // case 0x44: // NEW + // case 0x45: // CONSTRUCTOR_REFERENCE + // case 0x46: // METHOD_REFERENCE + default: + out.put12(typeRef >>> 24, (typeRef & 0xFFFF00) >> 8); + break; + } + if (typePath == null) { + out.putByte(0); + } else { + int length = typePath.b[typePath.offset] * 2 + 1; + out.putByteArray(typePath.b, typePath.offset, length); + } + } }