KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.compiler.base.ast.*;
31
32
33 /**
34  * @author Mik Kersten
35  */

36 public class ProgramElementNode extends StructureNode {
37         
38     private List modifiers;
39     private List relations;
40
41     private Kind kind;
42     private Accessibility accessibility;
43     private String JavaDoc declaringType = "";
44     private String JavaDoc formalComment = "";
45     private String JavaDoc packageName = null;
46     private boolean member = false;
47     private boolean runnable = false;
48     private boolean implementor = false;
49     private boolean overrider = false;
50     
51     private transient ASTObject astObject = null;
52
53     /**
54      * Used during de-externalization.
55      */

56     public ProgramElementNode() { }
57
58     /**
59      * Use to create program element nodes that do not correspond to source locations.
60      */

61     public ProgramElementNode(String JavaDoc signature, Kind kind, List children) {
62         super(signature, kind.toString(), children);
63         this.kind = kind;
64     }
65     
66     /**
67      * Use to create program element nodes that correspond to source locations.
68      */

69     public ProgramElementNode(String JavaDoc signature, Kind kind, List modifiers, Accessibility accessibility,
70         String JavaDoc declaringType, String JavaDoc packageName, String JavaDoc formalComment, SourceLocation sourceLocation,
71         List relations, List children, boolean member, ASTObject astObject) {
72
73         super(signature, kind.toString(), children);
74         super.sourceLocation = sourceLocation;
75         this.kind = kind;
76         this.modifiers = modifiers;
77         this.accessibility = accessibility;
78         this.declaringType = declaringType;
79         this.packageName = packageName;
80         this.formalComment = formalComment;
81         this.relations = relations;
82         this.member = member;
83         this.astObject = astObject;
84     }
85
86     public Kind getProgramElementKind() {
87         return kind;
88     }
89
90     public List getModifiers() {
91         return modifiers;
92     }
93
94     public Accessibility getAccessibility() {
95         return accessibility;
96     }
97
98     public String JavaDoc getDeclaringType() {
99         return declaringType;
100     }
101
102     public String JavaDoc getPackageName() {
103         return packageName;
104     }
105
106     public ASTObject getAstObject() {
107         return astObject;
108     }
109     
110     public void clearAstObject() {
111         this.astObject = null;
112     }
113
114     public String JavaDoc getKind() {
115         return super.kind;
116     }
117
118     public String JavaDoc getSignature() {
119         return super.name;
120     }
121
122     public boolean isCode() {
123         return kind.equals(Kind.CODE);
124     }
125
126     public boolean isMemberKind() {
127         return member;
128     }
129
130     public void setRunnable(boolean value) {
131         this.runnable = value;
132     }
133
134     public boolean isRunnable() {
135         return runnable;
136     }
137
138     public boolean isImplementor() {
139         return implementor;
140     }
141
142     public void setImplementor(boolean value) {
143         this.implementor = value;
144     }
145     
146     public boolean isOverrider() {
147         return overrider;
148     }
149
150     public void setOverrider(boolean value) {
151         this.overrider = value;
152     }
153
154     public List getRelations() {
155         return relations;
156     }
157
158     public void setRelations(List relations) {
159         if (relations.size() > 0) {
160             this.relations = relations;
161         }
162     }
163
164     public String JavaDoc getFormalComment() {
165         return formalComment;
166     }
167
168     public String JavaDoc toString() {
169         return super.name;
170     }
171
172 // /**
173
// * Fix this to represent data-equality.
174
// */
175
// public boolean equals(ProgramElementNode node) {
176
// if (node == null) {
177
// return false;
178
// } else {
179
// if (sourceLocation != null &&
180
// name.equals(node.getName()) &&
181
// sourceLocation.getSourceFilePath().equals(node.getSourceLocation().getSourceFilePath()) &&
182
// sourceLocation.getLineNumber() == node.getSourceLocation().getLineNumber() &&
183
// sourceLocation.getColumnNumber() == node.getSourceLocation().getColumnNumber()) {
184
// return true;
185
// } else {
186
// return false;
187
// }
188
// }
189
// //super.equals(node);
190
// }
191

192     /**
193      * Uses "typesafe enum" pattern.
194      */

195     public static class Modifiers implements Serializable {
196         
197         public static final Modifiers STATIC = new Modifiers("static");
198         public static final Modifiers FINAL = new Modifiers("final");
199         public static final Modifiers ABSTRACT = new Modifiers("abstract");
200         public static final Modifiers SYNCHRONIZED = new Modifiers("synchronized");
201         public static final Modifiers VOLATILE = new Modifiers("volatile");
202         public static final Modifiers STRICTFP = new Modifiers("strictfp");
203         public static final Modifiers TRANSIENT = new Modifiers("transient");
204         public static final Modifiers NATIVE = new Modifiers("native");
205         public static final Modifiers[] ALL = { STATIC, FINAL, ABSTRACT, SYNCHRONIZED, TRANSIENT, VOLATILE, STRICTFP, NATIVE };
206         private final String JavaDoc name;
207         
208         private Modifiers(String JavaDoc name) {
209             this.name = name;
210         }
211         
212         public String JavaDoc toString() {
213             return name;
214         }
215
216         // The 4 declarations below are necessary for serialization
217
private static int nextOrdinal = 0;
218         private final int ordinal = nextOrdinal++;
219         private Object JavaDoc readResolve() throws ObjectStreamException {
220             return ALL[ordinal];
221         }
222     }
223
224     /**
225      * Uses "typesafe enum" pattern.
226      */

227     public static class Accessibility implements Serializable {
228         
229         public static final Accessibility PUBLIC = new Accessibility("public");
230         public static final Accessibility PACKAGE = new Accessibility("package");
231         public static final Accessibility PROTECTED = new Accessibility("protected");
232         public static final Accessibility PRIVATE = new Accessibility("private");
233         public static final Accessibility PRIVILEGED = new Accessibility("privileged");
234         public static final Accessibility[] ALL = { PUBLIC, PACKAGE, PROTECTED, PRIVATE, PRIVILEGED };
235         private final String JavaDoc name;
236         
237         private Accessibility(String JavaDoc name) {
238             this.name = name;
239         }
240         
241         public String JavaDoc toString() {
242             return name;
243         }
244         
245         // The 4 declarations below are necessary for serialization
246
private static int nextOrdinal = 0;
247         private final int ordinal = nextOrdinal++;
248         private Object JavaDoc readResolve() throws ObjectStreamException {
249             return ALL[ordinal];
250         }
251     }
252
253     /**
254      * Uses "typesafe enum" pattern.
255      */

256     public static class Kind implements Serializable {
257         
258         public static final Kind PROJECT = new Kind("project");
259         public static final Kind PACKAGE = new Kind("package");
260         public static final Kind FILE = new Kind("file");
261         public static final Kind FILE_JAVA = new Kind("java source file");
262         public static final Kind FILE_ASPECTJ = new Kind("aspect source file");
263         public static final Kind FILE_LST = new Kind("build configuration file");
264         public static final Kind CLASS = new Kind("class");
265         public static final Kind INTERFACE = new Kind("interface");
266         public static final Kind ASPECT = new Kind("aspect");
267         public static final Kind INITIALIZER = new Kind("initializer");
268         public static final Kind INTRODUCTION = new Kind("introduction");
269         public static final Kind CONSTRUCTOR = new Kind("constructor");
270         public static final Kind METHOD = new Kind("method");
271         public static final Kind FIELD = new Kind("field");
272         public static final Kind POINTCUT = new Kind("pointcut");
273         public static final Kind ADVICE = new Kind("advice");
274         public static final Kind DECLARE_PARENTS = new Kind("declare parents");
275         public static final Kind DECLARE_WARNING = new Kind("declare warning");
276         public static final Kind DECLARE_ERROR = new Kind("declare error");
277         public static final Kind DECLARE_SOFT = new Kind("declare soft");
278         public static final Kind CODE = new Kind("decBodyElement");
279         public static final Kind ERROR = new Kind("error");
280
281         public static final Kind[] ALL = { PROJECT, PACKAGE, FILE, FILE_JAVA,
282             FILE_ASPECTJ, FILE_LST, CLASS, INTERFACE, ASPECT,
283             INITIALIZER, INTRODUCTION, CONSTRUCTOR, METHOD, FIELD, POINTCUT, ADVICE,
284             DECLARE_PARENTS, DECLARE_WARNING, DECLARE_ERROR, DECLARE_SOFT, CODE, ERROR };
285         
286         public static Kind getKindForString(String JavaDoc kindString) {
287             for (int i = 0; i < ALL.length; i++) {
288                 if (ALL[i].toString().equals(kindString)) return ALL[i];
289             }
290             return ERROR;
291         }
292         
293         private final String JavaDoc name;
294         
295         private Kind(String JavaDoc name) {
296             this.name = name;
297         }
298         
299         public String JavaDoc toString() {
300             return name;
301         }
302         
303 // public boolean equals(Object o) {
304
// return o.equals(name);
305
// }
306

307         public static List getNonAJMemberKinds() {
308             List list = new ArrayList();
309             list.add(METHOD);
310             list.add(FIELD);
311             list.add(CONSTRUCTOR);
312             return list;
313         }
314         
315         public boolean isMemberKind() {
316             return this == FIELD
317                 || this == METHOD
318                 || this == CONSTRUCTOR
319                 || this == POINTCUT
320                 || this == ADVICE;
321         }
322         
323         public boolean isTypeKind() {
324             return this == CLASS
325                 || this == INTERFACE
326                 || this == ASPECT;
327         }
328
329         public boolean isSourceFileKind() {
330             return this == FILE_ASPECTJ
331                 || this == FILE_JAVA;
332         }
333         
334         public boolean isDeclareKind() {
335             return name.startsWith("declare");
336         }
337
338         // The 4 declarations below are necessary for serialization
339
private static int nextOrdinal = 0;
340         private final int ordinal = nextOrdinal++;
341         private Object JavaDoc readResolve() throws ObjectStreamException {
342             return ALL[ordinal];
343         }
344     }
345 }
346
347 // /**
348
// * Creates and returns a copy of this object.
349
// */
350
// public Object clone() {
351
// List cloneModifiers = new ArrayList();
352
// List cloneRelations = new ArrayList();
353
// for (Iterator it = children.iterator(); it.hasNext(); ) {
354
// cloneChildren.add(((StructureNode)it.next()).clone());
355
// }
356
// StructureNode cloneNode = new StructureNode(name, kind, cloneChildren);
357
// return cloneNode;
358
// }
359
Popular Tags