KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > CtMember


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */

15
16 package javassist;
17
18 /**
19  * An instance of <code>CtMember</code> represents a field, a constructor,
20  * or a method.
21  */

22 public abstract class CtMember {
23     protected CtMember next; // for internal use
24
protected CtClass declaringClass;
25
26     protected CtMember(CtClass clazz) { declaringClass = clazz; }
27
28     static CtMember append(CtMember list, CtMember tail) {
29         tail.next = null;
30         if (list == null)
31             return tail;
32         else {
33             CtMember lst = list;
34             while (lst.next != null)
35                 lst = lst.next;
36
37             lst.next = tail;
38             return list;
39         }
40     }
41
42     static int count(CtMember f) {
43         int n = 0;
44         while (f != null) {
45             ++n;
46             f = f.next;
47         }
48
49         return n;
50     }
51
52     static CtMember remove(CtMember list, CtMember m) {
53         CtMember top = list;
54         if (list == null)
55             return null;
56         else if (list == m)
57             return list.next;
58         else
59             while (list.next != null) {
60                 if (list.next == m) {
61                     list.next = list.next.next;
62                     break;
63                 }
64
65                 list = list.next;
66             }
67
68         return top;
69     }
70
71     public String JavaDoc toString() {
72         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(getClass().getName());
73         buffer.append("@");
74         buffer.append(Integer.toHexString(hashCode()));
75         buffer.append("[");
76         buffer.append(Modifier.toString(getModifiers()));
77         extendToString(buffer);
78         buffer.append("]");
79         return buffer.toString();
80     }
81
82     /**
83      * Invoked by {@link #toString()} to add to the buffer and provide the
84      * complete value. Subclasses should invoke this method, adding a
85      * space before each token. The modifiers for the member are
86      * provided first; subclasses should provide additional data such
87      * as return type, field or method name, etc.
88      */

89     protected abstract void extendToString(StringBuffer JavaDoc buffer);
90
91     /**
92      * Returns the class that declares this member.
93      */

94     public CtClass getDeclaringClass() { return declaringClass; }
95
96     /**
97      * Obtains the modifiers of the member.
98      *
99      * @return modifiers encoded with
100      * <code>javassist.Modifier</code>.
101      * @see Modifier
102      */

103     public abstract int getModifiers();
104
105     /**
106      * Sets the encoded modifiers of the member.
107      *
108      * @see Modifier
109      */

110     public abstract void setModifiers(int mod);
111
112     /**
113      * Obtains the name of the member.
114      *
115      * <p>As for constructor names, see <code>getName()</code>
116      * in <code>CtConstructor</code>.
117      *
118      * @see CtConstructor#getName()
119      */

120     public abstract String JavaDoc getName();
121
122     /**
123      * Obtains an attribute with the given name.
124      * If that attribute is not found in the class file, this
125      * method returns null.
126      *
127      * @param name attribute name
128      */

129     public abstract byte[] getAttribute(String JavaDoc name);
130
131     /**
132      * Adds an attribute. The attribute is saved in the class file.
133      *
134      * @param name attribute name
135      * @param data attribute value
136      */

137     public abstract void setAttribute(String JavaDoc name, byte[] data);
138 }
139
Popular Tags