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 org.apidesign.javap;
32 * Strores field data informastion.
34 * @author Sucheta Dambalkar (Adopted code from jdis)
37 public class FieldData implements RuntimeConstants {
45 boolean isSynthetic=false;
46 boolean isDeprecated=false;
49 public FieldData(ClassData cls){
54 * Read and store field info.
56 public void read(DataInputStream in) throws IOException {
57 access = in.readUnsignedShort();
58 name_index = in.readUnsignedShort();
59 descriptor_index = in.readUnsignedShort();
60 // Read the attributes
61 int attributes_count = in.readUnsignedShort();
62 attrs=new Vector(attributes_count);
63 for (int i = 0; i < attributes_count; i++) {
64 int attr_name_index=in.readUnsignedShort();
65 if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
66 String attr_name=cls.getString(attr_name_index);
67 if (attr_name.equals("ConstantValue")){
69 throw new ClassFormatError("invalid ConstantValue attr length");
70 value_cpx=in.readUnsignedShort();
71 AttrData attr=new AttrData(cls);
72 attr.read(attr_name_index);
73 attrs.addElement(attr);
74 } else if (attr_name.equals("Synthetic")){
76 throw new ClassFormatError("invalid Synthetic attr length");
78 AttrData attr=new AttrData(cls);
79 attr.read(attr_name_index);
80 attrs.addElement(attr);
81 } else if (attr_name.equals("Deprecated")){
83 throw new ClassFormatError("invalid Synthetic attr length");
85 AttrData attr=new AttrData(cls);
86 attr.read(attr_name_index);
87 attrs.addElement(attr);
89 AttrData attr=new AttrData(cls);
90 attr.read(attr_name_index, in);
91 attrs.addElement(attr);
97 public boolean isStatic() {
98 return (access & ACC_STATIC) != 0;
102 * Returns access of a field.
104 public String[] getAccess(){
105 Vector v = new Vector();
106 if ((access & ACC_PUBLIC) !=0) v.addElement("public");
107 if ((access & ACC_PRIVATE) !=0) v.addElement("private");
108 if ((access & ACC_PROTECTED) !=0) v.addElement("protected");
109 if ((access & ACC_STATIC) !=0) v.addElement("static");
110 if ((access & ACC_FINAL) !=0) v.addElement("final");
111 if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
112 if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
113 String[] accflags = new String[v.size()];
114 v.copyInto(accflags);
119 * Returns name of a field.
121 public String getName(){
122 return cls.getStringValue(name_index);
126 * Returns internal signature of a field
128 public String getInternalSig(){
129 return cls.getStringValue(descriptor_index);
133 * Returns true if field is synthetic.
135 public boolean isSynthetic(){
140 * Returns true if field is deprecated.
142 public boolean isDeprecated(){
147 * Returns index of constant value in cpool.
149 public int getConstantValueIndex(){
154 * Returns list of attributes of field.
156 public Vector getAttributes(){
160 public byte[] findAnnotationData(boolean classRetention) {
161 String n = classRetention ?
162 "RuntimeInvisibleAnnotations" : // NOI18N
163 "RuntimeVisibleAnnotations"; // NOI18N
164 AttrData[] arr = new AttrData[attrs.size()];
166 return ClassData.findAttr(n, arr);