jjg@338: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@338: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@338: * jjg@338: * This code is free software; you can redistribute it and/or modify it jjg@338: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this jjg@338: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. jjg@338: * jjg@338: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@338: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@338: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@338: * version 2 for more details (a copy is included in the LICENSE file that jjg@338: * accompanied this code). jjg@338: * jjg@338: * You should have received a copy of the GNU General Public License version jjg@338: * 2 along with this work; if not, write to the Free Software Foundation, jjg@338: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@338: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@338: */ jjg@338: package com.sun.tools.javap; jjg@338: jjg@338: import com.sun.tools.classfile.Attribute; jjg@338: import com.sun.tools.classfile.Code_attribute; jjg@338: import com.sun.tools.classfile.ExtendedAnnotation; jjg@338: import com.sun.tools.classfile.ExtendedAnnotation.Position; jjg@338: import com.sun.tools.classfile.Instruction; jjg@338: import com.sun.tools.classfile.Method; jjg@338: import com.sun.tools.classfile.RuntimeInvisibleTypeAnnotations_attribute; jjg@338: import com.sun.tools.classfile.RuntimeTypeAnnotations_attribute; jjg@338: import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute; jjg@338: import java.util.ArrayList; jjg@338: import java.util.HashMap; jjg@338: import java.util.List; jjg@338: import java.util.Map; jjg@338: jjg@338: /** jjg@338: * Annotate instructions with details about type annotations. jjg@338: * jjg@581: *
This is NOT part of any supported API.
jjg@581: * If you write code that depends on this, you do so at your own risk.
jjg@338: * This code and its internal interfaces are subject to change or
jjg@338: * deletion without notice.
jjg@338: */
jjg@338: public class TypeAnnotationWriter extends InstructionDetailWriter {
jjg@338: public enum NoteKind { VISIBLE, INVISIBLE };
jjg@338: public static class Note {
jjg@338: Note(NoteKind kind, ExtendedAnnotation anno) {
jjg@338: this.kind = kind;
jjg@338: this.anno = anno;
jjg@338: }
jjg@338: public final NoteKind kind;
jjg@338: public final ExtendedAnnotation anno;
jjg@338: }
jjg@338:
jjg@338: static TypeAnnotationWriter instance(Context context) {
jjg@338: TypeAnnotationWriter instance = context.get(TypeAnnotationWriter.class);
jjg@338: if (instance == null)
jjg@338: instance = new TypeAnnotationWriter(context);
jjg@338: return instance;
jjg@338: }
jjg@338:
jjg@338: protected TypeAnnotationWriter(Context context) {
jjg@338: super(context);
jjg@338: context.put(TypeAnnotationWriter.class, this);
jjg@338: annotationWriter = AnnotationWriter.instance(context);
jjg@338: classWriter = ClassWriter.instance(context);
jjg@338: }
jjg@338:
jjg@338: public void reset(Code_attribute attr) {
jjg@338: Method m = classWriter.getMethod();
jjg@338: pcMap = new HashMap