@Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { TypeAnnotationNode an = new TypeAnnotationNode(typeRef, typePath, desc); if (visible) { if (visibleTypeAnnotations == null) { visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1); } visibleTypeAnnotations.add(an); } else { if (invisibleTypeAnnotations == null) { invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1); } invisibleTypeAnnotations.add(an); } return an; }
@Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { LocalVariableAnnotationNode an = new LocalVariableAnnotationNode( typeRef, typePath, getLabelNodes(start), getLabelNodes(end), index, desc); if (visible) { if (visibleLocalVariableAnnotations == null) { visibleLocalVariableAnnotations = new ArrayList<LocalVariableAnnotationNode>( 1); } visibleLocalVariableAnnotations.add(an); } else { if (invisibleLocalVariableAnnotations == null) { invisibleLocalVariableAnnotations = new ArrayList<LocalVariableAnnotationNode>( 1); } invisibleLocalVariableAnnotations.add(an); } return an; }
@Override public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { TryCatchBlockNode tcb = tryCatchBlocks.get((typeRef & 0x00FFFF00) >> 8); TypeAnnotationNode an = new TypeAnnotationNode(typeRef, typePath, desc); if (visible) { if (tcb.visibleTypeAnnotations == null) { tcb.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>( 1); } tcb.visibleTypeAnnotations.add(an); } else { if (tcb.invisibleTypeAnnotations == null) { tcb.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>( 1); } tcb.invisibleTypeAnnotations.add(an); } return an; }
@Override public Printer visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { buf.setLength(0); buf.append(tab2).append("LOCALVARIABLE @"); appendDescriptor(FIELD_DESCRIPTOR, desc); buf.append('('); text.add(buf.toString()); Textifier t = createTextifier(); text.add(t.getText()); buf.setLength(0); buf.append(") : "); appendTypeReference(typeRef); buf.append(", ").append(typePath); for (int i = 0; i < start.length; ++i) { buf.append(" [ "); appendLabel(start[i]); buf.append(" - "); appendLabel(end[i]); buf.append(" - ").append(index[i]).append(" ]"); } buf.append(visible ? "\n" : " // invisible\n"); text.add(buf.toString()); return t; }
@Override public void begin(final String name, final Attributes attrs) { String desc = attrs.getValue("desc"); boolean visible = Boolean.valueOf(attrs.getValue("visible")) .booleanValue(); int typeRef = Integer.parseInt(attrs.getValue("typeRef")); TypePath typePath = TypePath.fromString(attrs.getValue("typePath")); Object v = peek(); if (v instanceof ClassVisitor) { push(((ClassVisitor) v).visitTypeAnnotation(typeRef, typePath, desc, visible)); } else if (v instanceof FieldVisitor) { push(((FieldVisitor) v).visitTypeAnnotation(typeRef, typePath, desc, visible)); } else if (v instanceof MethodVisitor) { push(((MethodVisitor) v).visitTypeAnnotation(typeRef, typePath, desc, visible)); } }
public ASMifier visitTypeAnnotation(final String method, final int typeRef, final TypePath typePath, final String desc, final boolean visible) { buf.setLength(0); buf.append("{\n").append("av0 = ").append(name).append(".") .append(method).append("("); buf.append(typeRef); if (typePath == null) { buf.append(", null, "); } else { buf.append(", TypePath.fromString(\"").append(typePath).append("\"), "); } appendConstant(desc); buf.append(", ").append(visible).append(");\n"); text.add(buf.toString()); ASMifier a = createASMifier("av", 0); text.add(a.getText()); text.add("}\n"); return a; }
@Override public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { checkState(); int sort = typeRef >>> 24; if (sort != TypeReference.CLASS_TYPE_PARAMETER && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND && sort != TypeReference.CLASS_EXTENDS) { throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort)); } checkTypeRefAndPath(typeRef, typePath); CheckMethodAdapter.checkDesc(desc, false); return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible)); }
@Override public Printer visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { buf.setLength(0); buf.append(tab2).append("TRYCATCHBLOCK @"); appendDescriptor(FIELD_DESCRIPTOR, desc); buf.append('('); text.add(buf.toString()); Textifier t = createTextifier(); text.add(t.getText()); buf.setLength(0); buf.append(") : "); appendTypeReference(typeRef); buf.append(", ").append(typePath); buf.append(visible ? "\n" : " // invisible\n"); text.add(buf.toString()); return t; }
/** * Prints a disassembled view of the given type annotation. * * @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 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. * @param desc * the class descriptor of the annotation class. * @param visible * <tt>true</tt> if the annotation is visible at runtime. * @return a visitor to visit the annotation values. */ public Textifier visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { buf.setLength(0); buf.append(tab).append('@'); appendDescriptor(FIELD_DESCRIPTOR, desc); buf.append('('); text.add(buf.toString()); Textifier t = createTextifier(); text.add(t.getText()); buf.setLength(0); buf.append(") : "); appendTypeReference(typeRef); buf.append(", ").append(typePath); buf.append(visible ? "\n" : " // invisible\n"); text.add(buf.toString()); return t; }
@Override public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { checkEndMethod(); int sort = typeRef >>> 24; if (sort != TypeReference.METHOD_TYPE_PARAMETER && sort != TypeReference.METHOD_TYPE_PARAMETER_BOUND && sort != TypeReference.METHOD_RETURN && sort != TypeReference.METHOD_RECEIVER && sort != TypeReference.METHOD_FORMAL_PARAMETER && sort != TypeReference.THROWS) { throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath); CheckMethodAdapter.checkDesc(desc, false); return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible)); }
@Override public AnnotationVisitor visitInsnAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) { checkStartCode(); checkEndCode(); int sort = typeRef >>> 24; if (sort != TypeReference.INSTANCEOF && sort != TypeReference.NEW && sort != TypeReference.CONSTRUCTOR_REFERENCE && sort != TypeReference.METHOD_REFERENCE && sort != TypeReference.CAST && sort != TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT && sort != TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT && sort != TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT && sort != TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT) { throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort)); } CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath); CheckMethodAdapter.checkDesc(desc, false); return new CheckAnnotationAdapter(super.visitInsnAnnotation(typeRef, typePath, desc, visible)); }
@Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); return av == null ? av : new RemappingAnnotationAdapter(av, remapper); }
@Override public void begin(final String name, final Attributes attrs) { String desc = attrs.getValue("desc"); boolean visible = Boolean.valueOf(attrs.getValue("visible")) .booleanValue(); int typeRef = Integer.parseInt(attrs.getValue("typeRef")); TypePath typePath = TypePath.fromString(attrs.getValue("typePath")); push(((MethodVisitor) peek()).visitInsnAnnotation(typeRef, typePath, desc, visible)); }
@Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); return av == null ? av : new AnnotationRemapper(av, remapper); }
@Override public AnnotationVisitor visitLocalVariableAnnotation(final int typeRef, final TypePath typePath, final Label[] start, final Label[] end, final int[] index, final String desc, final boolean visible) { fsmCursor.transition("visitLocalVariableAnnotation"); final AnnotationVisitor annotationVisitor = super .visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible); return annotationVisitor; // TODO: add CheckAnnotationVisitorFsm }
@Override public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { AnnotationVisitor av = super.visitInsnAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); return av == null ? av : new AnnotationRemapper(av, remapper); }
@Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { AnnotationVisitor av = super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, remapper.mapDesc(desc), visible); return av == null ? av : new AnnotationRemapper(av, remapper); }
@Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); return av == null ? null : createAnnotationRemapper(av); }
@Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { Printer p = this.p.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible); AnnotationVisitor av = mv == null ? null : mv .visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible); return new TraceAnnotationVisitor(av, p); }
@Override public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { cp.newUTF8(desc); if (visible) { cp.newUTF8("RuntimeVisibleTypeAnnotations"); } else { cp.newUTF8("RuntimeInvisibleTypeAnnotations"); } return new AnnotationConstantsCollector(mv.visitInsnAnnotation(typeRef, typePath, desc, visible), cp); }