Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: lib/dartdoc/mirrors/mirrors.dart

Issue 10692040: Mirrors prototype added to dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
gbracha 2012/06/30 01:27:32 All my comments are already at: https://docs.goog
5 #library('mirrors');
6
7 #import('dart:uri');
8 #import('dart2js_mirror.dart');
9
10 /**
11 * [Compilation] encapsulates the compilation of a program.
12 */
13 class Compilation {
14 /**
15 * Creates a new compilation which has [script] as its entry point.
16 */
17 factory Compilation(String script, String libraryRoot,
18 [String packageRoot, List<String> opts = const []])
19 {
20 return new Dart2jsCompilation(script, libraryRoot, packageRoot, opts);
21 }
22
23 /**
24 * Returns the mirror system for this compilation.
25 */
26 abstract MirrorSystem mirrors();
27 }
28
29 /**
30 * The main interface for the whole mirror system.
31 */
32 interface MirrorSystem {
33 /**
34 * Returns an unmodifiable map of all libraries in this mirror system.
35 */
36 Map<Object,LibraryMirror> libraries();
37 }
38
39
40 /**
41 * An entity in the mirror system.
42 */
43 interface Mirror {
44 /**
45 * The simple name of the entity. The simple name is in most cases the
46 * the declared single identifier name of the entity, such as 'method' for
47 * a method [:void method() {...}:].
48 */
49 String simpleName();
50
51 /**
52 * Returns the name of this entity qualified by is enclosing context. For
53 * instance, the qualified name of a method 'method' in class 'Class' in
54 * library 'library' is 'library.Class.method'.
55 */
56 String qualifiedName();
57 }
58
59 /**
60 * Common interface for a type and library.
61 */
62 interface ObjectMirror extends Mirror {
63
64 /**
65 * Returns an unmodifiable map of the members of declared in this type or
66 * library.
67 */
68 Map<Object,MemberMirror> declaredMembers();
69 }
70
71 /**
72 * A library.
73 */
74 interface LibraryMirror extends ObjectMirror {
75 /**
76 * The name of the library, as given in #library().
77 */
78 String simpleName();
79
80 /**
81 * Returns an iterable over all types in the library.
82 */
83 Map<Object,InterfaceMirror> types();
84
85 /**
86 * Returns the source location for this library.
87 */
88 Location location();
89 }
90
91 /**
92 * Common interface for classes, interfaces, typedefs and type variables.
93 */
94 interface TypeMirror extends Mirror {
95 /**
96 * Returns the source location for this type.
97 */
98 Location location();
99
100 /**
101 * Returns the library in which this member resides.
102 */
103 LibraryMirror library();
104
105 /**
106 * Returns [:true:] iff this type is the [:Object:] type.
107 */
108 final bool isObject;
109
110 /**
111 * Returns [:true:] iff this type is the [:Dynamic:] type.
112 */
113 final bool isDynamic;
114
115 /**
116 * Returns [:true:] iff this type is the void type.
117 */
118 final bool isVoid;
119
120 /**
121 * Returns [:true:] iff this type is a type variable.
122 */
123 final bool isTypeVariable;
124
125 /**
126 * Returns [:true:] iff this type is a typedef.
127 */
128 final bool isTypedef;
129
130 /**
131 * Returns [:true:] iff this type is a function type.
132 */
133 final bool isFunction;
134 }
135
136 /**
137 * A class or interface type.
138 */
139 interface InterfaceMirror extends TypeMirror, ObjectMirror {
140 /**
141 * Returns the defining type, i.e. declaration of a type.
142 */
143 final InterfaceMirror declaration;
144
145 /**
146 * Returns the super class of this type, or null if this type is [Object] or a
147 * typedef.
148 */
149 InterfaceMirror superclass();
150
151 /**
152 * Returns an iterable over the interfaces directly implemented by this type.
153 */
154 // TODO(johnniwinther): Semantics is unclear. Should List<String> return
155 // Collection<String> (that is, perform substitution) or Collection<E>
156 // (the declaration)? And for [:interface NumList<num> extends List<num>:]
157 // should List<num> or List<E> be returned?
158 Map<Object,InterfaceMirror> interfaces();
159
160 /**
161 * Returns an iterable over the type declarations directly inheriting from
162 * this type.
163 */
164 // An iterable is returned because this information should probably be
165 // computed on the fly.
166 Iterable<InterfaceMirror> computeSubdeclarations();
167
168 /**
169 * Returns [:true:] iff this type is a class.
170 */
171 final bool isClass;
172
173 /**
174 * Returns [:true:] iff this type is an interface.
175 */
176 final bool isInterface;
177
178 /**
179 * Returns [:true:] if this type is private.
180 */
181 final bool isPrivate;
182
183 /**
184 * Returns [:true:] if this type is the declaration of a type.
185 */
186 final bool isDeclaration;
187
188 /**
189 * Returns a list of the type arguments for this type.
190 */
191 // Return a list instead of a map since the order of type arguments matters.
192 // Also, there is no clear candidate for the keys, other than the indices,
193 // which again is an argument for returning a list.
194 List<TypeMirror> typeArguments();
195
196 /**
197 * Returns the list of type variables for this type.
198 */
199 // Return a list instead of a map since the order of type variable matters.
200 // Even though the type variable name is a candidate for the key, the index
201 // of a type variable has a more stable semantics, which is an argument for
202 // returning a list instead of a map.
203 List<TypeVariableMirror> typeVariables();
204
205 /**
206 * Returns an immutable map of the constructors in this interface.
207 */
208 Map<Object,MethodMirror> constructors();
209
210 /**
211 * Returns the default type for this interface.
212 */
213 InterfaceMirror defaultType();
214 }
215
216 /**
217 * A type parameter as declared on a generic type.
218 */
219 interface TypeVariableMirror extends TypeMirror {
220 /**
221 * Return a mirror on the class, interface, or typedef that declared the
222 * type variable.
223 */
224 // Should not be called [declaration] as we then would have two [TypeMirror]
225 // subtypes ([InterfaceMirror] and [TypeVariableMirror]) which have
226 // [declaration()] methods but with different semantics.
227 InterfaceMirror declarer();
228
229 /**
230 * Returns the bound of the type parameter.
231 */
232 TypeMirror bound();
233 }
234
235 /**
236 * A function type.
237 */
238 interface FunctionTypeMirror extends InterfaceMirror {
239 /**
240 * Returns the return type of this function type.
241 */
242 TypeMirror returnType();
243
244 /**
245 * Returns the parameters for this function type.
246 */
247 List<ParameterMirror> parameters();
248
249 /**
250 * Returns the call method for this function type.
251 */
252 MethodMirror callMethod();
253 }
254
255 /**
256 * A typedef.
257 */
258 interface TypedefMirror extends InterfaceMirror {
259 /**
260 * Returns the defining type for this typedef. For instance [:void f(int):]
261 * for a [:typedef void f(int):].
262 */
263 TypeMirror definition();
264 }
265
266 /**
267 * A member of a type, i.e. a field, method or constructor.
268 */
269 interface MemberMirror extends Mirror {
270 /**
271 * Returns the source location for this member.
272 */
273 Location location();
274
275 /**
276 * Returns a mirror on the declaration immediately surrounding the reflectee.
277 * This could be a class, interface, library or another method or function.
278 */
279 ObjectMirror surroundingDeclaration();
280
281 /**
282 * Returns true if this is a top level member, i.e. a member not within a
283 * type.
284 */
285 final bool isTopLevel;
286
287 /**
288 * Returns true if this member is a constructor.
289 */
290 final bool isConstructor;
291
292 /**
293 * Returns true if this member is a field.
294 */
295 final bool isField;
296
297 /**
298 * Returns true if this member is a method.
299 */
300 final bool isMethod;
301
302 /**
303 * Returns true if this member is private.
304 */
305 final bool isPrivate;
306
307 /**
308 * Returns true if this member is static.
309 */
310 final bool isStatic;
311 }
312
313 /**
314 * A field.
315 */
316 interface FieldMirror extends MemberMirror {
317
318 /**
319 * Returns true if this field is final.
320 */
321 final bool isFinal;
322
323 /**
324 * Returns the type of this field.
325 */
326 TypeMirror type();
327 }
328
329 /**
330 * A constructor or method.
331 */
332 interface MethodMirror extends MemberMirror {
333 /**
334 * Returns the list of parameters for this method.
335 */
336 List<ParameterMirror> parameters();
337
338 /**
339 * Returns the return type of this method.
340 */
341 TypeMirror returnType();
342
343 /**
344 * Returns [:true:] if this method is a constant constructor.
345 */
346 final bool isConst;
347
348 /**
349 * Returns [:true:] if this method is a factory method.
350 */
351 final bool isFactory;
352
353 /**
354 * Returns the constructor name for named constructors and factory methods,
355 * e.g. [:'bar':] for constructor [:Foo.bar:] of type [:Foo:].
356 */
357 final String constructorName;
358
359 /**
360 * Returns [:true:] if this method is a getter method.
361 */
362 final bool isGetter;
363
364 /**
365 * Returns [:true:] if this method is a setter method.
366 */
367 final bool isSetter;
368
369 /**
370 * Returns [:true:] if this method is an operator method.
371 */
372 final bool isOperator;
373
374 /**
375 * Returns the operator name for operator methods, e.g. [:'<':] for
376 * [:operator <:]
377 */
378 final String operatorName;
379 }
380
381 /**
382 * A formal parameter.
383 */
384 interface ParameterMirror extends Mirror {
385 /**
386 * Returns the type of this parameter.
387 */
388 TypeMirror type();
389
390 /**
391 * Returns the default value for this parameter.
392 */
393 String defaultValue();
394
395 /**
396 * Returns true if this parameter has a default value.
397 */
398 bool hasDefaultValue();
399
400 /**
401 * Returns true if this parameter is optional.
402 */
403 bool isOptional();
404 }
405
406 /**
407 * A [Location] describes the span of an entity in Dart source code.
408 * A [Location] should be the minimum span that encloses the declaration of the
409 * mirrored entity.
410 */
411 interface Location {
412 /**
413 * The character index where the location begins.
414 */
415 int start();
416
417 /**
418 * The character index where the location ends.
419 */
420 int end();
421
422 /**
423 * Returns the [Source] in which this [Location] indexes.
424 * If [:loc:] is a location, [:loc.source().text()[loc.start()] is where it
425 * starts, and [:loc.source().text()[loc.end()] is where it ends.
426 */
427 Source source();
428
429 /**
430 * The text of the location span.
431 */
432 String text();
433 }
434
435 /**
436 * A [Source] describes the source code of a compilation unit in Dart source
437 * code.
438 */
439 interface Source {
440 /**
441 * Returns the URI where the source originated.
442 */
443 Uri uri();
444
445 /**
446 * Returns the text of this source.
447 */
448 String text();
449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698