blob: 3715e3928ba8b01f344807957a8d4f1c5a352e5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This file is part of the debugger and core tools for the AspectJ(tm)
* programming language; see http://aspectj.org
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is AspectJ.
*
* The Initial Developer of the Original Code is Xerox Corporation. Portions
* created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
* All Rights Reserved.
*/
package org.aspectj.tools.ajdoc;
import org.aspectj.ajdoc.AspectDoc;
import org.aspectj.ajdoc.PackageDoc;
import org.aspectj.compiler.base.ast.Type;
import org.aspectj.compiler.base.ast.TypeDec;
import org.aspectj.compiler.crosscuts.AspectJCompiler;
import com.sun.javadoc.ClassDoc;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Represents a package in the aspectj-world.
* A package is a passive container of classes given to it.
* It does not enforce visibility rules. However, you can
* purge packages without classes from the static list of packages.
* @author Jeff Palm
*/
public class PackageDocImpl
extends DocImpl
implements org.aspectj.ajdoc.PackageDoc {
public final static String UNNAMED_PACKAGE = ""; //unnamed-package";
private static AjdocCompiler ajdoc = Ajdoc.instance();
private static AspectJCompiler ajc = ajdoc;
public AspectJCompiler ajc() { return ajc; }
private Set allClasses = new HashSet();
private Comment comment;
private String name;
/**
* Only want to create these within the static access.
*
* @param name name of the new package.
*/
private PackageDocImpl(String name) {
this.name = name;
findDocumentation();
}
/**
* Adds a class to this package.
*
* @param classDoc The new class.
*/
public void addClass(ClassDoc classDoc) {
allClasses.add(classDoc);
}
/**
* Attempts to find a class with name <code>className</code>
* in this package.
*
* @param className name of the class to find.
*/
public ClassDoc findClass(String className) {
Type type = ajc.getTypeManager().
findType(name(), className);
if (type != null) {
return ClassDocImpl.getInstance(type.getTypeDec());
}
for (Iterator i = allClasses.iterator(); i.hasNext();) {
ClassDoc cd = (ClassDoc)i.next();
if (className.equals(cd.name())) {
return cd; //todo wes was null?
}
}
return null;
}
/**
* Returns all the classes in this package.
*
* @return an array of ClassDoc representing all
* the classes in this package.
*/
public ClassDoc[] allClasses() {
return (ClassDoc[])allClasses.toArray(new ClassDoc[allClasses.size()]);
}
/**
* Returns all the aspects in this package.
*
* @return an array of AspectDoc representing all
* the aspects in this package.
*/
public AspectDoc[] aspects() {
List list = new ArrayList();
for (Iterator i = allClasses.iterator(); i.hasNext();) {
org.aspectj.ajdoc.ClassDoc doc = (org.aspectj.ajdoc.ClassDoc)i.next();
if (doc.isAspect()) list.add(doc);
}
return (AspectDoc[])list.toArray
(new AspectDoc[list.size()]);
}
/**
* Returns all the ordinary classes in this package.
*
* @return an array of ClassDoc representing all
* the ordinary classes in this package.
*/
public ClassDoc[] ordinaryClasses() {
List list = new ArrayList();
for (Iterator i = allClasses.iterator(); i.hasNext();) {
ClassDoc doc = (ClassDoc)i.next();
if (doc.isOrdinaryClass()) list.add(doc);
}
return (ClassDoc[])list.toArray
(new ClassDoc[list.size()]);
}
/**
* Returns all the exceptions in this package.
*
* @return an array of ClassDoc representing all
* the exceptions in this package.
*/
public ClassDoc[] exceptions() {
List list = new ArrayList();
for (Iterator i = allClasses.iterator(); i.hasNext();) {
ClassDoc doc = (ClassDoc)i.next();
if (doc.isException()) list.add(doc);
}
return (ClassDoc[])list.toArray
(new ClassDoc[list.size()]);
}
/**
* Returns all the errors in this package.
*
* @return an array of ClassDoc representing all
* the errors in this package.
*/
public ClassDoc[] errors() {
List list = new ArrayList();
for (Iterator i = allClasses.iterator(); i.hasNext();) {
ClassDoc doc = (ClassDoc)i.next();
if (doc.isError()) list.add(doc);
}
return (ClassDoc[])list.toArray
(new ClassDoc[list.size()]);
}
/**
* Returns all the interfaces in this package.
*
* @return an array of ClassDoc representing all
* the interfaces in this package.
*/
public ClassDoc[] interfaces() {
List list = new ArrayList();
for (Iterator i = allClasses.iterator(); i.hasNext();) {
ClassDoc doc = (ClassDoc)i.next();
if (doc.isInterface()) list.add(doc);
}
return (ClassDoc[])list.toArray
(new ClassDoc[list.size()]);
}
/**
* Returns the name if included -- null otherwise.
*
* @return the name if included -- null otherwise.
*/
public String name() {
return isIncluded() ? name : null;
}
/**
* Compare based on <code>name()</code>.
*
* @param other other Object.
* @return <code>true</code> if the other Object is a
* PackageDocImpl and has the same name.
*/
public boolean equals(Object other) {
return other instanceof PackageDocImpl && other != null
? name().equals(((PackageDocImpl)other).name())
: super.equals(other);
}
/**
* Returns the name.
*
* @return the name.
*/
public String toString() {
return name();
}
private void findDocumentation() {
if (ajdoc == null) return;
String filename = (name.equals("")
? name
: name.replace('.',File.separatorChar)
+ File.separatorChar) + "package.html";
File html = ajdoc.findFile(filename, false);
if (html == null) return;
String rawCommentText = Util.documentation(html, ajdoc.err());
//TODO: should be done in aspect from Aspects.java
//FormalComment comment = new FormalComment(rawCommentText);
setComment(new Comment(this, rawCommentText));
}
/* ------------------------------------------------------------
* Factory stuff
* ------------------------------------------------------------
*/
private static Map namesToPackages = new HashMap();
/**
* Returns the collection of known packages.
*
* @return a Collection representing the known packages.
*/
public static Collection packages() {
return namesToPackages.values();
}
/**
* Inits the world and AspectJCompiler with these
* packages.
*
* @param world current World.
* @param ajc current compiler.
*/
public static void init(AspectJCompiler ajc) {
PackageDocImpl.ajc = ajc;
if (ajc instanceof AjdocCompiler) {
PackageDocImpl.ajdoc = (AjdocCompiler)ajc;
}
}
/**
* Returns a package for a TypeDec.
*
* @param typeDec TypeDec whose package is desired.
* @return a PackageDocImpl for a given TypeDec.
*/
public static PackageDocImpl getPackageDoc(TypeDec typeDec) {
return getPackageDoc(typeDec.getPackageName());
}
/**
* Returns a package for a name.
*
* @param packageName package name for which to look.
* @return a PackageDocImpl for a given package name.
*/
public static PackageDocImpl getPackageDoc(String packageName) {
return addPackageDoc(packageName);
}
/**
* Adds a package with name <code>name</code> if it
* already doesn't exist, and returns the new package
* (if own with the same name didn't exist) or the
* existing package.
*
* @param name name of the new package.
* @return current package mapping to
* <code>name</code>.
*/
public static PackageDocImpl addPackageDoc(String name) {
if (name == null) name = UNNAMED_PACKAGE;
PackageDocImpl packageDoc = (PackageDocImpl)namesToPackages.get(name);
if (packageDoc == null) {
packageDoc = new PackageDocImpl(name);
addPackageDoc(packageDoc);
}
return packageDoc;
}
/**
* Adds the PackageDoc if one doesn't already exist
* with the same name, and returns the existing or created
* package with the same name as the one passed in .
*
* @param packageDoc PackageDoc we want to add.
* @return package in the world with the same
* name as <code>packageDoc</code>.
*/
public static PackageDocImpl addPackageDoc(PackageDoc packageDoc) {
if (packageDoc == null) return null;
return (PackageDocImpl)namesToPackages.put(packageDoc.name(),
packageDoc);
}
/**
* Sets the include flag to false for empty packages
* todo: remove instead?
*/
public static void excludeEmptyPackages() {
for (Iterator i = packages().iterator(); i.hasNext();) {
PackageDocImpl pkg = (PackageDocImpl)i.next();
if (pkg.allClasses().length < 1) {
pkg.setIncluded(false);
}
}
}
}
|