Almost rewritten to javap: @JavaScriptBody and double/long may not yet be supported
2 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
27 package sun.tools.javap;
33 * Strores field data informastion.
35 * @author Sucheta Dambalkar (Adopted code from jdis)
38 public class FieldData implements RuntimeConstants {
46 boolean isSynthetic=false;
47 boolean isDeprecated=false;
50 public FieldData(ClassData cls){
55 * Read and store field info.
57 public void read(DataInputStream in) throws IOException {
58 access = in.readUnsignedShort();
59 name_index = in.readUnsignedShort();
60 descriptor_index = in.readUnsignedShort();
61 // Read the attributes
62 int attributes_count = in.readUnsignedShort();
63 attrs=new Vector(attributes_count);
64 for (int i = 0; i < attributes_count; i++) {
65 int attr_name_index=in.readUnsignedShort();
66 if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
67 String attr_name=cls.getString(attr_name_index);
68 if (attr_name.equals("ConstantValue")){
70 throw new ClassFormatError("invalid ConstantValue attr length");
71 value_cpx=in.readUnsignedShort();
72 AttrData attr=new AttrData(cls);
73 attr.read(attr_name_index);
74 attrs.addElement(attr);
75 } else if (attr_name.equals("Synthetic")){
77 throw new ClassFormatError("invalid Synthetic attr length");
79 AttrData attr=new AttrData(cls);
80 attr.read(attr_name_index);
81 attrs.addElement(attr);
82 } else if (attr_name.equals("Deprecated")){
84 throw new ClassFormatError("invalid Synthetic attr length");
86 AttrData attr=new AttrData(cls);
87 attr.read(attr_name_index);
88 attrs.addElement(attr);
90 AttrData attr=new AttrData(cls);
91 attr.read(attr_name_index, in);
92 attrs.addElement(attr);
98 public boolean isStatic() {
99 return (access & ACC_STATIC) != 0;
103 * Returns access of a field.
105 public String[] getAccess(){
106 Vector v = new Vector();
107 if ((access & ACC_PUBLIC) !=0) v.addElement("public");
108 if ((access & ACC_PRIVATE) !=0) v.addElement("private");
109 if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
110 if ((access & ACC_STATIC) !=0) v.addElement("static");
111 if ((access & ACC_FINAL) !=0) v.addElement("final");
112 if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
113 if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
114 String[] accflags = new String[v.size()];
115 v.copyInto(accflags);
120 * Returns name of a field.
122 public String getName(){
123 return cls.getStringValue(name_index);
127 * Returns internal signature of a field
129 public String getInternalSig(){
130 return cls.getStringValue(descriptor_index);
134 * Returns java type signature of a field.
136 public String getType(){
137 return new TypeSignature(getInternalSig()).getFieldType();
141 * Returns true if field is synthetic.
143 public boolean isSynthetic(){
148 * Returns true if field is deprecated.
150 public boolean isDeprecated(){
155 * Returns index of constant value in cpool.
157 public int getConstantValueIndex(){
162 * Returns list of attributes of field.
164 public Vector getAttributes(){