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