blob: 807ef080d547ba42c611d407f2d5fa5b153da98a (
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
|
/* -*- 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.AdviceDoc;
import org.aspectj.compiler.base.ast.Formals;
import org.aspectj.compiler.base.ast.NameType;
import org.aspectj.compiler.base.ast.TypeDs;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.ExecutableMemberDoc;
import com.sun.javadoc.ParamTag;
import com.sun.javadoc.Parameter;
import com.sun.javadoc.ThrowsTag;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public abstract class ExecutableMemberDocImpl
extends MemberDocImpl
implements ExecutableMemberDoc {
/*
* These three fields should be final, but can't because
* they contain calls to abstract methods that aren't
* valid until after the subclasses constructor is run.
* To compensate the accessor methods lazily evaluate
* them, and these methods are final.
*/
/** The collection of advice placed on each ExecutableMemberDoc. */
private Collection advice;
/** The List of parameters. */
private Collection parameters;
/** The List of thrown exceptions. */
private Collection thrownExceptions;
/** The full signature. */
private String signature;
/** The flat signature. */
private String flatSignature;
/**
* Constructs a new Doc with the enclosing ClassDoc.
*
* @param containingClass enclosing ClassDoc.
*/
public ExecutableMemberDocImpl(ClassDoc containingClass) {
super(containingClass);
}
/**
* Returns a non-null Collection of AdviceDoc
* representing the advice placed on the underlying Dec.
*
* @return a non-null Collection of AdviceDoc
* representing the advice placed on the
* underlying Dec.
*/
protected abstract Collection createAdvice();
/**
* Returns the Formals of the underlying Dec.
*
* @return the Formals of the underlying Dec.
*/
protected abstract Formals getFormals();
/**
* Returns the TypeDs representing the exceptions
* thrown by the underlying Dec.
*
* @return the TypeDs representing the exceptions
* thrown by the underlying Dec.
*/
protected abstract TypeDs getThrows();
/**
* Converts the passed in Formals to a Collection of
* Parameter and sets our parameters to this value.
*
* @param formals the Formals to use.
*/
public void makeParameters(Formals formals) {
parameters = createParameters(formals);
}
/**
* Converts the passed in TypeDs to a Collection of
* ClassDoc and sets our thrownExceptions to this value.
*
* @param thrown the TypeDs to use.
*/
public void makeThrownExceptions(TypeDs thrown) {
thrownExceptions = createThrownExceptions(thrown);
}
/**
* Returns the advice affecting this member.
*
* @return an array of AdviceDoc representing the advice
* affecting this member.
*/
public final AdviceDoc[] advice() {
if (advice == null) advice = createAdvice();
return (AdviceDoc[])advice.toArray(new AdviceDoc[advice.size()]);
}
/**
* Returns the exceptions this code declares to throw.
*
* @return an array of ClassDoc representing the exceptions
* this code declares to throw.
*/
public final ClassDoc[] thrownExceptions() {
if (thrownExceptions == null) makeThrownExceptions(getThrows());
return (ClassDoc[])thrownExceptions.toArray
(new ClassDoc[thrownExceptions.size()]);
}
/**
* Returns the parameters taken by this code.
*
* @return an array of Parameter representing the
* parameters this code takes.
*/
public final Parameter[] parameters() {
if (parameters == null) makeParameters(getFormals());
return (Parameter[])parameters.toArray
(new Parameter[parameters.size()]);
}
/**
* Returns the flat signature.
*
* @return the flat signature with all types unqualified.
*/
public String flatSignature() {
if (flatSignature == null) {
flatSignature = Util.flatSignature(parameters());
}
return flatSignature;
}
/**
* Returns the full signature.
*
* @return the full signature with all types qualified.
*/
public String signature() {
if (signature == null) {
signature = Util.signature(parameters());
}
return signature;
}
/**
* Returns <code>true</code> if this code is <code>synchronized</code>.
*
* @return <code>true</code> if this code is <code>synchronized</code>.
*/
public boolean isSynchronized() {
//return getModifiers().isSynchronized();
return Modifier.isSynchronized(modifierSpecifier());
}
/**
* Returns <code>true</code>if this code is <code>native</code>.
*
* @return <code>true</code>if this code is <code>native</code>.
*/
public boolean isNative() {
//return (modifierSpecifier() & Modifiers.NATIVE) != 0;
return Modifier.isNative(modifierSpecifier());
}
/**
* Returns the throw tags describing exceptions thrown
* declared by this code.
*
* @return an array of ThrowsTag representing the exception
* this code declares to throw.
*/
public ThrowsTag[] throwsTags() {
return getComment().throwsTags();
}
/**
* Returns the param tags describing parameters taken
* by this code.
*
* @return an array of ParamTag representing the
* parameters taken by this code.
*/
public ParamTag[] paramTags() {
return getComment().paramTags();
}
/**
* Returns the simple name followed the parameters
* enclosed in parens.
*
* @return the simple name followed the parameters
* enclosed in parens.
*/
public String toString() {
StringBuffer sb = new StringBuffer(name());
sb.append('(');
Parameter[] params = parameters();
for (int i = 0, N = params.length; i < N; i++) {
if (i > 0) sb.append(",");
sb.append(params[i].type().qualifiedTypeName());
sb.append(params[i].type().dimension());
}
sb.append(')');
return sb.toString();
}
/**
* Returns a Collection of Parameter corresponding to
* the Formals passed in.
*
* @param formals the Formals to use.
* @return a Collection of Parameter corresponding to
* the Formals passed in.
*/
private Collection createParameters(Formals formals) {
if (formals == null) return Collections.EMPTY_LIST;
List list = new ArrayList(formals.size());
for (int i = 0, N = formals.size(); i < N; i++) {
list.add(new ParameterImpl(formals.get(i)));
}
return list;
}
/**
* Returns a Collection of ClassDoc corresponding to
* the TypeDs passed in.
*
* @param thrown the TypeDs to use
* @return a Collection of ClassDoc corresponding to
* the TypeDs passed in.
*/
private Collection createThrownExceptions(TypeDs typeds) {
if (typeds == null) return Collections.EMPTY_LIST;
List list = new ArrayList(typeds.size());
for (int i = 0, N = typeds.size(); i < N; i++) {
list.add(ClassDocImpl.getInstance
(((NameType)typeds.get(i).getType()).getTypeDec()));
}
return list;
}
/**
* Returns <code>true</code> if the passed in Object is
* an ExecutableMemberDocImpl, its name equals ours, and
* its parameters <code>equals</code> ours.
*
* @return equality based on name and parameters.
*/
public boolean weakEquals(Object md) {
if (!(md instanceof ExecutableMemberDocImpl)) {
return false;
}
ExecutableMemberDocImpl emdi = (ExecutableMemberDocImpl)md;
if (!name().equals(emdi.name())) {
return false;
}
Parameter[] ourPds = this.parameters();
Parameter[] edsPds = emdi.parameters();
if (ourPds.length != edsPds.length) {
return false;
}
for (int i = 0, N = ourPds.length; i < N; i++) {
if (!ourPds[i].equals(edsPds[i])) {
return false;
}
}
return true;
}
}
|