diff -r 5652acd48509 -r 42bc1e89134d javap/src/main/java/org/apidesign/javap/MethodData.java --- a/javap/src/main/java/org/apidesign/javap/MethodData.java Mon Feb 25 19:00:08 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,394 +0,0 @@ -/* - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package org.apidesign.javap; - - -import java.io.DataInputStream; -import java.io.IOException; -import static org.apidesign.javap.RuntimeConstants.*; - -/** - * Strores method data informastion. - * - * @author Sucheta Dambalkar (Adopted code from jdis) - */ -public class MethodData { - - ClassData cls; - int access; - int name_index; - int descriptor_index; - int attributes_count; - byte[] code; - Vector exception_table = new Vector(0); - Vector lin_num_tb = new Vector(0); - Vector loc_var_tb = new Vector(0); - StackMapTableData[] stackMapTable; - StackMapData[] stackMap; - int[] exc_index_table=null; - Vector attrs=new Vector(0); - Vector code_attrs=new Vector(0); - int max_stack, max_locals; - boolean isSynthetic=false; - boolean isDeprecated=false; - - public MethodData(ClassData cls){ - this.cls=cls; - } - - /** - * Read method info. - */ - public void read(DataInputStream in) throws IOException { - access = in.readUnsignedShort(); - name_index=in.readUnsignedShort(); - descriptor_index =in.readUnsignedShort(); - int attributes_count = in.readUnsignedShort(); - for (int i = 0; i < attributes_count; i++) { - int attr_name_index=in.readUnsignedShort(); - - readAttr: { - if (cls.getTag(attr_name_index)==CONSTANT_UTF8) { - String attr_name=cls.getString(attr_name_index); - if ( attr_name.equals("Code")){ - readCode (in); - AttrData attr=new AttrData(cls); - attr.read(attr_name_index); - attrs.addElement(attr); - break readAttr; - } else if ( attr_name.equals("Exceptions")){ - readExceptions(in); - AttrData attr=new AttrData(cls); - attr.read(attr_name_index); - attrs.addElement(attr); - break readAttr; - } else if (attr_name.equals("Synthetic")){ - if (in.readInt()!=0) - throw new ClassFormatError("invalid Synthetic attr length"); - isSynthetic=true; - AttrData attr=new AttrData(cls); - attr.read(attr_name_index); - attrs.addElement(attr); - break readAttr; - } else if (attr_name.equals("Deprecated")){ - if (in.readInt()!=0) - throw new ClassFormatError("invalid Synthetic attr length"); - isDeprecated = true; - AttrData attr=new AttrData(cls); - attr.read(attr_name_index); - attrs.addElement(attr); - break readAttr; - } - } - AttrData attr=new AttrData(cls); - attr.read(attr_name_index, in); - attrs.addElement(attr); - } - } - } - - /** - * Read code attribute info. - */ - public void readCode(DataInputStream in) throws IOException { - - int attr_length = in.readInt(); - max_stack=in.readUnsignedShort(); - max_locals=in.readUnsignedShort(); - int codelen=in.readInt(); - - code=new byte[codelen]; - int totalread = 0; - while(totalread < codelen){ - totalread += in.read(code, totalread, codelen-totalread); - } - // in.read(code, 0, codelen); - int clen = 0; - readExceptionTable(in); - int code_attributes_count = in.readUnsignedShort(); - - for (int k = 0 ; k < code_attributes_count ; k++) { - int table_name_index=in.readUnsignedShort(); - int table_name_tag=cls.getTag(table_name_index); - AttrData attr=new AttrData(cls); - if (table_name_tag==CONSTANT_UTF8) { - String table_name_tstr=cls.getString(table_name_index); - if (table_name_tstr.equals("LineNumberTable")) { - readLineNumTable(in); - attr.read(table_name_index); - } else if (table_name_tstr.equals("LocalVariableTable")) { - readLocVarTable(in); - attr.read(table_name_index); - } else if (table_name_tstr.equals("StackMapTable")) { - readStackMapTable(in); - attr.read(table_name_index); - } else if (table_name_tstr.equals("StackMap")) { - readStackMap(in); - attr.read(table_name_index); - } else { - attr.read(table_name_index, in); - } - code_attrs.addElement(attr); - continue; - } - - attr.read(table_name_index, in); - code_attrs.addElement(attr); - } - } - - /** - * Read exception table info. - */ - void readExceptionTable (DataInputStream in) throws IOException { - int exception_table_len=in.readUnsignedShort(); - exception_table=new Vector(exception_table_len); - for (int l = 0; l < exception_table_len; l++) { - exception_table.addElement(new TrapData(in, l)); - } - } - - /** - * Read LineNumberTable attribute info. - */ - void readLineNumTable (DataInputStream in) throws IOException { - int attr_len = in.readInt(); // attr_length - int lin_num_tb_len = in.readUnsignedShort(); - lin_num_tb=new Vector(lin_num_tb_len); - for (int l = 0; l < lin_num_tb_len; l++) { - lin_num_tb.addElement(new LineNumData(in)); - } - } - - /** - * Read LocalVariableTable attribute info. - */ - void readLocVarTable (DataInputStream in) throws IOException { - int attr_len=in.readInt(); // attr_length - int loc_var_tb_len = in.readUnsignedShort(); - loc_var_tb = new Vector(loc_var_tb_len); - for (int l = 0; l < loc_var_tb_len; l++) { - loc_var_tb.addElement(new LocVarData(in)); - } - } - - /** - * Read Exception attribute info. - */ - public void readExceptions(DataInputStream in) throws IOException { - int attr_len=in.readInt(); // attr_length in prog - int num_exceptions = in.readUnsignedShort(); - exc_index_table=new int[num_exceptions]; - for (int l = 0; l < num_exceptions; l++) { - int exc=in.readShort(); - exc_index_table[l]=exc; - } - } - - /** - * Read StackMapTable attribute info. - */ - void readStackMapTable(DataInputStream in) throws IOException { - int attr_len = in.readInt(); //attr_length - int stack_map_tb_len = in.readUnsignedShort(); - stackMapTable = new StackMapTableData[stack_map_tb_len]; - for (int i=0; i".equals(getName()); - } -}