01: /*
02:
03: Derby - Class org.apache.derby.iapi.services.classfile.ClassMember
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.iapi.services.classfile;
23:
24: import java.lang.reflect.Modifier;
25:
26: import java.io.IOException;
27:
28: public class ClassMember {
29: protected ClassHolder cpt;
30: protected int access_flags;
31: protected int name_index;
32: protected int descriptor_index;
33: protected Attributes attribute_info; // can be null
34:
35: ClassMember(ClassHolder cpt, int modifier, int name, int descriptor) {
36: this .cpt = cpt;
37: name_index = name;
38: descriptor_index = descriptor;
39: access_flags = modifier;
40: }
41:
42: /*
43: ** Public methods from ClassMember
44: */
45:
46: public int getModifier() {
47: return access_flags;
48: }
49:
50: public String getDescriptor() {
51: return cpt.nameIndexToString(descriptor_index);
52: }
53:
54: public String getName() {
55: return cpt.nameIndexToString(name_index);
56: }
57:
58: public void addAttribute(String attributeName,
59: ClassFormatOutput info) {
60:
61: if (attribute_info == null)
62: attribute_info = new Attributes(1);
63:
64: attribute_info.addEntry(new AttributeEntry(cpt
65: .addUtf8(attributeName), info));
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: }
|