KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > field_info


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997 Clark Verbrugge
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31
32 package soot.coffi;
33
34 import java.io.*;
35
36 /** Represents a single field_info object.
37  * @see ClassFile
38  * @author Clark Verbrugge
39  */

40 public class field_info {
41    /** Access flags for this field. */
42    public int access_flags;
43    /** Constant pool index of the name of this field.
44     * @see ClassFile#constant_pool
45     * @see CONSTANT_Utf8_info
46     */

47    public int name_index;
48    /** Constant pool index of the type descriptor of this field.
49     * @see ClassFile#constant_pool
50     * @see CONSTANT_Utf8_info
51     */

52    public int descriptor_index;
53    /** Count of attributes this field contains. */
54    public int attributes_count;
55    /** Array of attribute_info objects for this field.
56     * @see attribute_info
57     */

58    public attribute_info attributes[];
59
60    /** Returns the name of this field.
61     * @param constant_pool the constant_pool for this class.
62     * @return the name of this field.
63     */

64    public String JavaDoc toName(cp_info constant_pool[]) {
65       CONSTANT_Utf8_info ci;
66       ci = (CONSTANT_Utf8_info)(constant_pool[name_index]);
67       return ci.convert();
68    }
69
70    /** Returns the prototype of this field.
71     * @param constant_pool the constant_pool for this class.
72     * @return the prototype (access + type + name) of this field.
73     */

74    public String JavaDoc prototype(cp_info constant_pool[]) {
75       ConstantValue_attribute cva;
76       CONSTANT_Utf8_info cm,dm;
77       int i,j;
78       String JavaDoc s;
79
80       cm = (CONSTANT_Utf8_info)(constant_pool[name_index]);
81       dm = (CONSTANT_Utf8_info)(constant_pool[descriptor_index]);
82       s = ClassFile.access_string(access_flags," ");
83       if (s.compareTo("")!=0) s = s + " ";
84       return s + ClassFile.parseDesc(dm.convert(),"") + " " + cm.convert();
85    }
86
87    /** Locates a constant value attribute if one exists.
88      * @return the constant value attribute or <i>null</i>.
89      * @see ConstantValue_attribute
90      */

91    public ConstantValue_attribute findConstantValue_attribute() {
92       ConstantValue_attribute ca;
93       int i;
94       for (i=0;i<attributes_count;i++) {
95          if ((attributes[i]) instanceof ConstantValue_attribute)
96             return (ConstantValue_attribute)(attributes[i]);
97       }
98       return null;
99    }
100
101 }
102
Popular Tags