1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.classfile.ClassMember |
4 | |
5 | Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.classfile; |
22 | |
23 | import java.lang.reflect.Modifier; |
24 | |
25 | import java.io.IOException; |
26 | |
27 | |
28 | |
29 | public class ClassMember { |
30 | protected ClassHolder cpt; |
31 | protected int access_flags; |
32 | protected int name_index; |
33 | protected int descriptor_index; |
34 | protected Attributes attribute_info; // can be null |
35 | |
36 | ClassMember(ClassHolder cpt, int modifier, int name, int descriptor) { |
37 | this.cpt = cpt; |
38 | name_index = name; |
39 | descriptor_index = descriptor; |
40 | access_flags = modifier; |
41 | } |
42 | |
43 | /* |
44 | ** Public methods from ClassMember |
45 | */ |
46 | |
47 | public int getModifier() { |
48 | return access_flags; |
49 | } |
50 | |
51 | public String getDescriptor() { |
52 | return cpt.nameIndexToString(descriptor_index); |
53 | } |
54 | |
55 | public String getName() { |
56 | return cpt.nameIndexToString(name_index); |
57 | } |
58 | |
59 | public void addAttribute(String attributeName, ClassFormatOutput info) { |
60 | |
61 | if (attribute_info == null) |
62 | attribute_info = new Attributes(1); |
63 | |
64 | attribute_info.addEntry(new AttributeEntry(cpt.addUtf8(attributeName), info)); |
65 | } |
66 | |
67 | |
68 | /* |
69 | ** ---- |
70 | */ |
71 | |
72 | void put(ClassFormatOutput out) throws IOException { |
73 | out.putU2(access_flags); |
74 | out.putU2(name_index); |
75 | out.putU2(descriptor_index); |
76 | |
77 | if (attribute_info != null) { |
78 | out.putU2(attribute_info.size()); |
79 | attribute_info.put(out); |
80 | } else { |
81 | out.putU2(0); |
82 | } |
83 | } |
84 | |
85 | int classFileSize() { |
86 | int size = 2 + 2 + 2 + 2; |
87 | if (attribute_info != null) |
88 | size += attribute_info.classFileSize(); |
89 | return size; |
90 | } |
91 | } |