jjg@284: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@284: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@284: * jjg@284: * This code is free software; you can redistribute it and/or modify it jjg@284: * 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@284: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. jjg@284: * jjg@284: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@284: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@284: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@284: * version 2 for more details (a copy is included in the LICENSE file that jjg@284: * accompanied this code). jjg@284: * jjg@284: * You should have received a copy of the GNU General Public License version jjg@284: * 2 along with this work; if not, write to the Free Software Foundation, jjg@284: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@284: * 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@284: */ jjg@284: jjg@284: package com.sun.tools.javap; jjg@284: jjg@284: import com.sun.tools.classfile.Attribute; jjg@284: import com.sun.tools.classfile.Code_attribute; jjg@284: import com.sun.tools.classfile.ConstantPool; jjg@284: import com.sun.tools.classfile.ConstantPoolException; jjg@284: import com.sun.tools.classfile.Descriptor; jjg@284: import com.sun.tools.classfile.Descriptor.InvalidDescriptor; jjg@284: import com.sun.tools.classfile.Instruction; jjg@284: import com.sun.tools.classfile.LocalVariableTable_attribute; jjg@284: import java.util.ArrayList; jjg@284: import java.util.HashMap; jjg@284: import java.util.List; jjg@284: import java.util.ListIterator; jjg@284: import java.util.Map; jjg@284: jjg@284: /** jjg@284: * Annotate instructions with details about local variables. jjg@284: * 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@284: * This code and its internal interfaces are subject to change or
jjg@284: * deletion without notice.
jjg@284: */
jjg@284: public class LocalVariableTableWriter extends InstructionDetailWriter {
jjg@284: public enum NoteKind {
jjg@284: START("start") {
jjg@284: public boolean match(LocalVariableTable_attribute.Entry entry, int pc) {
jjg@284: return (pc == entry.start_pc);
jjg@284: }
jjg@284: },
jjg@284: END("end") {
jjg@284: public boolean match(LocalVariableTable_attribute.Entry entry, int pc) {
jjg@284: return (pc == entry.start_pc + entry.length);
jjg@284: }
jjg@284: };
jjg@284: NoteKind(String text) {
jjg@284: this.text = text;
jjg@284: }
jjg@284: public abstract boolean match(LocalVariableTable_attribute.Entry entry, int pc);
jjg@284: public final String text;
jjg@284: };
jjg@284:
jjg@284: static LocalVariableTableWriter instance(Context context) {
jjg@284: LocalVariableTableWriter instance = context.get(LocalVariableTableWriter.class);
jjg@284: if (instance == null)
jjg@284: instance = new LocalVariableTableWriter(context);
jjg@284: return instance;
jjg@284: }
jjg@284:
jjg@284: protected LocalVariableTableWriter(Context context) {
jjg@284: super(context);
jjg@284: context.put(LocalVariableTableWriter.class, this);
jjg@284: classWriter = ClassWriter.instance(context);
jjg@284: }
jjg@284:
jjg@284: public void reset(Code_attribute attr) {
jjg@284: codeAttr = attr;
jjg@284: pcMap = new HashMap