KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > file > Method


1 package alt.jiapi.file;
2
3 import java.util.List JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 /**
7  * This class represents a method, as described in Java Virtual
8  * Machine Specification, 2nd edition, chapter 4.6.
9  */

10 public class Method {
11     public static final short ACC_PUBLIC = 0x0001;
12     public static final short ACC_PRIVATE = 0x0002;
13     public static final short ACC_PROTECTED = 0x0004;
14     public static final short ACC_STATIC = 0x0008;
15     public static final short ACC_FINAL = 0x0010;
16     public static final short ACC_SYNCHRONIZED = 0x0020;
17     public static final short ACC_NATIVE = 0x0100;
18     public static final short ACC_ABSTRACT = 0x0400;
19     public static final short ACC_STRICT = 0x0800;
20
21     private ConstantPool cp;
22     private short access_flags;
23     private short name_index;
24     private short descriptor_index;
25     private List JavaDoc attributes;
26
27     private transient Configuration config = new Configuration();
28
29     public Method(ConstantPool cp, short access_flags, String JavaDoc name,
30                   String JavaDoc descriptor, List JavaDoc attributes) {
31         this.cp = cp;
32         this.access_flags = access_flags;
33         this.name_index = cp.addUtf8Info(name).getEntryIndex();
34         this.descriptor_index = cp.addUtf8Info(descriptor).getEntryIndex();
35         this.attributes = attributes;
36     }
37
38     Method(ConstantPool cp, short access_flags, short name_index,
39                   short descriptor_index, List JavaDoc attributes) {
40         this.cp = cp;
41         this.access_flags = access_flags;
42         this.name_index = name_index;
43         this.descriptor_index = descriptor_index;
44         this.attributes = attributes;
45     }
46
47
48     public ConstantPool getConstantPool() {
49         return cp;
50     }
51
52     public short getAccessFlags() {
53         return access_flags;
54     }
55
56     public Attribute getAttribute(String JavaDoc name) {
57         Iterator JavaDoc i = attributes.iterator();
58         while(i.hasNext()) {
59             Attribute a = (Attribute)i.next();
60             if (a.getName().equals(name)) {
61                 return a;
62             }
63         }
64
65         return null;
66     }
67
68     public List JavaDoc getAttributes() {
69 // if (config.getBoolean("alt.jiapi.file.strip-optional-attributes",true)){
70
// java.util.LinkedList attrs = new java.util.LinkedList();
71
// attrs.add(getAttribute("Code"));
72
// return attrs;
73
// }
74

75         return attributes;
76     }
77
78     public String JavaDoc getName() {
79         return cp.getUtf8(name_index);
80     }
81
82     public String JavaDoc getDescriptor() {
83         return cp.getUtf8(descriptor_index);
84     }
85
86     short getNameIndex() {
87         return name_index;
88     }
89
90     short getDescriptorIndex() {
91         return descriptor_index;
92     }
93 }
94
95
Popular Tags