KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > asm > StructureNode


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25
26 package org.aspectj.asm;
27
28 import java.util.*;
29 import java.io.*;
30
31 /**
32  * Children are non-repeating making the parent-child structure a strict
33  * tree.
34  *
35  * @author Mik Kersten
36  */

37 public abstract class StructureNode implements Serializable, Comparable JavaDoc {
38
39     protected StructureNode parent = null;
40     protected String JavaDoc name = "";
41     protected String JavaDoc kind = "";
42     protected List children = new ArrayList();
43     protected StructureMessage message = null;
44     protected SourceLocation sourceLocation = null;
45
46     /**
47      * Used during serialization.
48      */

49     public StructureNode() { }
50
51     public StructureNode(String JavaDoc name, String JavaDoc kind, List children) {
52         this.name = name;
53         this.kind = kind;
54         if (children != null) {
55             this.children = children;
56         }
57         setParents();
58     }
59
60     public StructureNode(String JavaDoc name, String JavaDoc kind) {
61         this.name = name;
62         this.kind = kind;
63     }
64
65     public String JavaDoc toString() {
66         return name;
67     }
68
69     public String JavaDoc getKind() {
70         return kind;
71     }
72
73     public List getChildren() {
74         return children;
75     }
76
77     public void addChild(StructureNode child) {
78         if (children == null) {
79             children = new ArrayList();
80         }
81         children.add(child);
82         child.setParent(this);
83     }
84     
85     public boolean removeChild(StructureNode child) {
86         child.setParent(null);
87         return children.remove(child);
88     }
89
90     public StructureNode walk(ModelWalker walker) {
91         for (Iterator it = children.iterator(); it.hasNext(); ) {
92             StructureNode child = (StructureNode)it.next();
93             walker.process(child);
94         }
95         return this;
96     }
97     
98 // public boolean equals(Object o) {
99
// if (!(o instanceof StructureNode)) return false;
100
// StructureNode sn = (StructureNode)o;
101
// return objectEqual(sn.getName(), this.getName())
102
// && objectEqual(sn.getKind(), this.getKind())
103
// && objectEqual(sn.getChildren(), this.getChildren());
104
// }
105
//
106
// protected boolean objectEqual(Object o1, Object o2) {
107
// return (o1 == null && o2 == null) || (o1 != null && o1.equals(o2));
108
// }
109

110     /**
111      * Comparison is string-name based only.
112      */

113     public int compareTo(Object JavaDoc o) throws ClassCastException JavaDoc {
114         if (this == o) {
115             return 0;
116         } else {
117             StructureNode sn = (StructureNode)o;
118             return this.getName().compareTo(sn.getName());
119         }
120     }
121
122     public String JavaDoc getName() {
123         return name;
124     }
125
126     public SourceLocation getSourceLocation() {
127         return sourceLocation;
128     }
129
130     public void setSourceLocation(SourceLocation sourceLocation) {
131         this.sourceLocation = sourceLocation;
132     }
133
134     public StructureMessage getMessage() {
135         return message;
136     }
137
138     public void setMessage(StructureMessage message) {
139         this.message = message;
140     }
141
142     public StructureNode getParent() {
143         return parent;
144     }
145
146     public void setParent(StructureNode parent) {
147         this.parent = parent;
148     }
149
150     private void setParents() {
151         if (children == null) return;
152         for (Iterator it = children.iterator(); it.hasNext(); ) {
153             ((StructureNode)it.next()).setParent(this);
154         }
155     }
156 //
157
// /**
158
// * Creates and returns a copy of this object.
159
// */
160
// public Object clone() {
161
// List cloneChildren = new ArrayList();
162
// for (Iterator it = children.iterator(); it.hasNext(); ) {
163
// cloneChildren.add(((StructureNode)it.next()).clone());
164
// }
165
// StructureNode cloneNode = new StructureNode(name, kind, cloneChildren);
166
// return cloneNode;
167
// }
168
}
169
170
171 // private void writeObject(ObjectOutputStream s) throws IOException {
172
// s.defaultWriteObject();
173
// // customized serialization code
174
// }
175
//
176
// private void readObject(ObjectInputStream s) throws IOException {
177
// s.defaultReadObject();
178
// // customized deserialization code
179
// ...
180
// // followed by code to update the object, if necessary
181
// }
182

183 // public void writeExternal(ObjectOutput out) throws IOException {
184
// if (this instanceof ProgramElementNode) {
185
// out.writeInt(1);
186
// writeString(name, out);
187
// writeString(kind, out);
188
// ((ProgramElementNode)this).writeExternal(out);
189
// } if (this instanceof RelationNode) {
190
// out.writeInt(1);
191
// writeString(name, out);
192
// writeString(kind, out);
193
// ((RelationNode)this).writeExternal(out);
194
// } if (this instanceof LinkNode) {
195
// out.writeInt(3);
196
// writeString(name, out);
197
// writeString(kind, out);
198
// ((LinkNode)this).writeExternal(out);
199
// } else {
200
// out.writeInt(0);
201
// writeString(name, out);
202
// writeString(kind, out);
203
// }
204
// }
205
//
206
// public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
207
// int kindint = in.readInt();
208
// name = readString(in);
209
// kind = readString(in);
210
//
211
// switch (kindint) {
212
// case 1:
213
// ((StructureNode)it.next()).readExternal(in);
214
// break;
215
// case 2:
216
// ((RelationNode)it.next()).readExternal(in);
217
// break;
218
// case 3:
219
// ((LinkNode)it.next()).readExternal(in);
220
// break;
221
// }
222
// }
223
//
224
// protected void writeString(String s, ObjectOutput out) throws IOException {
225
// out.writeInt(s.length());
226
// out.write(s.getBytes());
227
// }
228
//
229
// protected String readString(ObjectInput in) throws IOException {
230
// int length = in.readInt();
231
// byte[] nameArray = new byte[length];
232
// in.read(nameArray, 0, length);
233
// return new String(nameArray);
234
// }
235
//
236

237
238
Popular Tags