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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart

Issue 119913002: Align source mirrors with runtime mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments + small fix. Created 6 years, 10 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
5 library mirrors;
6
7 /**
8 * The main interface for the whole mirror system.
9 */
10 abstract class MirrorSystem {
11 /**
12 * Returns an unmodifiable map of all libraries in this mirror system.
13 */
14 Map<Uri, LibraryMirror> get libraries;
15
16 /**
17 * Returns an iterable of all libraries in the mirror system whose library
18 * name is [libraryName].
19 */
20 LibraryMirror findLibrary(String libraryName) {
21 return libraries.values.singleWhere(
22 (library) => library.simpleName == libraryName);
23 }
24
25 /**
26 * A mirror on the [:dynamic:] type.
27 */
28 TypeMirror get dynamicType;
29
30 /**
31 * A mirror on the [:void:] type.
32 */
33 TypeMirror get voidType;
34 }
35
36
37 /**
38 * An entity in the mirror system.
39 */
40 abstract class Mirror {
41 static const String UNARY_MINUS = 'unary-';
42
43 // TODO(johnniwinther): Do we need this on all mirrors?
44 /**
45 * Returns the mirror system which contains this mirror.
46 */
47 MirrorSystem get mirrors;
48 }
49
50 abstract class DeclarationMirror implements Mirror {
51 /**
52 * The simple name of the entity. The simple name is unique within the
53 * scope of the entity declaration.
54 *
55 * The simple name is in most cases the declared single identifier name of
56 * the entity, such as 'method' for a method [:void method() {...}:]. For an
57 * unnamed constructor for [:class Foo:] the simple name is ''. For a
58 * constructor for [:class Foo:] named 'named' the simple name is 'named'.
59 * For a property [:foo:] the simple name of the getter method is 'foo' and
60 * the simple name of the setter is 'foo='. For operators the simple name is
61 * the operator itself, for example '+' for [:operator +:].
62 *
63 * The simple name for the unary minus operator is [Mirror.UNARY_MINUS].
64 */
65 String get simpleName;
66
67 /// Returns `true` if the name of this declaration is generated by the
68 /// provider of the mirror system.
69 bool get isNameSynthetic;
70
71 /**
72 * Returns the name of this entity qualified by is enclosing context. For
73 * instance, the qualified name of a method 'method' in class 'Class' in
74 * library 'library' is 'library.Class.method'.
75 */
76 String get qualifiedName;
77
78 /**
79 * The source location of this Dart language entity.
80 */
81 SourceLocation get location;
82
83 /**
84 * A mirror on the owner of this function. This is the declaration immediately
85 * surrounding the reflectee.
86 *
87 * Note that for libraries, the owner will be [:null:].
88 */
89 DeclarationMirror get owner;
90
91 /**
92 * Is this declaration private?
93 *
94 * Note that for libraries, this will be [:false:].
95 */
96 bool get isPrivate;
97
98 /**
99 * Is this declaration top-level?
100 *
101 * This is defined to be equivalent to:
102 * [:mirror.owner != null && mirror.owner is LibraryMirror:]
103 */
104 bool get isTopLevel;
105
106 /**
107 * A list of the metadata associated with this declaration.
108 */
109 List<InstanceMirror> get metadata;
110
111 /**
112 * Looks up [name] in the scope of this declaration.
113 *
114 * [name] may be either a single identifier, like 'foo', or of the
115 * a prefixed identifier, like 'foo.bar', where 'foo' must be a prefix.
116 * For methods and constructors, the scope includes the parameters. For
117 * classes and typedefs, the scope includes the type variables.
118 * For classes and class members, the scope includes inherited members.
119 *
120 * See also:
121 *
122 * * [Lexical Scope](https://www.dartlang.org/docs/dart-up-and-running/content s/ch02.html#ch02-lexical-scope)
123 * in Dart Up and Running.
124 * * [Lexical Scoping](http://www.dartlang.org/docs/spec/latest/dart-language- specification.html#h.jb82efuudrc5)
125 * in the Dart Specification.
126 */
127 DeclarationMirror lookupInScope(String name);
128 }
129
130 abstract class ObjectMirror implements Mirror {
131 /**
132 * Invokes a getter and returns a mirror on the result. The getter
133 * can be the implicit getter for a field or a user-defined getter
134 * method.
135 */
136 InstanceMirror getField(String fieldName);
137 }
138
139 /**
140 * An [InstanceMirror] reflects an instance of a Dart language object.
141 */
142 abstract class InstanceMirror implements ObjectMirror {
143 /**
144 * A mirror on the type of the reflectee.
145 */
146 ClassMirror get type;
147
148 /**
149 * Does [reflectee] contain the instance reflected by this mirror?
150 * This will always be true in the local case (reflecting instances
151 * in the same isolate), but only true in the remote case if this
152 * mirror reflects a simple value.
153 *
154 * A value is simple if one of the following holds:
155 * - the value is null
156 * - the value is of type [num]
157 * - the value is of type [bool]
158 * - the value is of type [String]
159 */
160 bool get hasReflectee;
161
162 /**
163 * If the [InstanceMirror] reflects an instance it is meaningful to
164 * have a local reference to, we provide access to the actual
165 * instance here.
166 *
167 * If you access [reflectee] when [hasReflectee] is false, an
168 * exception is thrown.
169 */
170 get reflectee;
171 }
172
173 /**
174 * Specialized [InstanceMirror] used for reflection on constant lists.
175 */
176 abstract class ListInstanceMirror implements InstanceMirror {
177 /**
178 * Returns an instance mirror of the value at [index] or throws a [RangeError]
179 * if the [index] is out of bounds.
180 */
181 InstanceMirror operator[](int index);
182
183 /**
184 * The number of elements in the list.
185 */
186 int get length;
187 }
188
189 /**
190 * Specialized [InstanceMirror] used for reflection on constant maps.
191 */
192 abstract class MapInstanceMirror implements InstanceMirror {
193 /**
194 * Returns a collection containing all the keys in the map.
195 */
196 Iterable<String> get keys;
197
198 /**
199 * Returns an instance mirror of the value for the given key or
200 * null if key is not in the map.
201 */
202 InstanceMirror operator[](String key);
203
204 /**
205 * The number of {key, value} pairs in the map.
206 */
207 int get length;
208 }
209
210 /**
211 * Specialized [InstanceMirror] used for reflection on type constants.
212 */
213 abstract class TypeInstanceMirror implements InstanceMirror {
214 /**
215 * Returns the type mirror for the type represented by the reflected type
216 * constant.
217 */
218 TypeMirror get representedType;
219 }
220
221 /**
222 * Specialized [InstanceMirror] used for reflection on comments as metadata.
223 */
224 abstract class CommentInstanceMirror implements InstanceMirror {
225 /**
226 * The comment text as written in the source text.
227 */
228 String get text;
229
230 /**
231 * The comment text without the start, end, and padding text.
232 *
233 * For example, if [text] is [: /** Comment text. */ :] then the [trimmedText]
234 * is [: Comment text. :].
235 */
236 String get trimmedText;
237
238 /**
239 * Is [:true:] if this comment is a documentation comment.
240 *
241 * That is, that the comment is either enclosed in [: /** ... */ :] or starts
242 * with [: /// :].
243 */
244 bool get isDocComment;
245 }
246
247 /**
248 * Common interface for classes and libraries.
249 */
250 abstract class ContainerMirror implements Mirror {
251
252 /**
253 * An immutable map from from names to mirrors for all members in this
254 * container.
255 */
256 Map<String, MemberMirror> get members;
257 }
258
259 /**
260 * A library.
261 */
262 abstract class LibraryMirror implements ContainerMirror, DeclarationMirror {
263 /**
264 * An immutable map from from names to mirrors for all members in this
265 * library.
266 *
267 * The members of a library are its top-level classes, functions, variables,
268 * getters, and setters.
269 */
270 Map<String, MemberMirror> get members;
271
272 /**
273 * An immutable map from names to mirrors for all class
274 * declarations in this library.
275 */
276 Map<String, ClassMirror> get classes;
277
278 /**
279 * An immutable map from names to mirrors for all function, getter,
280 * and setter declarations in this library.
281 */
282 Map<String, MethodMirror> get functions;
283
284 /**
285 * An immutable map from names to mirrors for all getter
286 * declarations in this library.
287 */
288 Map<String, MethodMirror> get getters;
289
290 /**
291 * An immutable map from names to mirrors for all setter
292 * declarations in this library.
293 */
294 Map<String, MethodMirror> get setters;
295
296 /**
297 * An immutable map from names to mirrors for all variable
298 * declarations in this library.
299 */
300 Map<String, VariableMirror> get variables;
301
302 /**
303 * Returns the canonical URI for this library.
304 */
305 Uri get uri;
306
307 /**
308 * Returns a list of the imports and exports in this library;
309 */
310 List<LibraryDependencyMirror> get libraryDependencies;
311 }
312
313 /// A mirror on an import or export declaration.
314 abstract class LibraryDependencyMirror {
315 /// Is `true` if this dependency is an import.
316 bool get isImport;
317
318 /// Is `true` if this dependency is an export.
319 bool get isExport;
320
321 /// Returns the library mirror of the library that imports or exports the
322 /// [targetLibrary].
323 LibraryMirror get sourceLibrary;
324
325 /// Returns the library mirror of the library that is imported or exported.
326 LibraryMirror get targetLibrary;
327
328 /// Returns the prefix if this is a prefixed import and `null` otherwise.
329 String get prefix;
330
331 /// Returns the list of show/hide combinators on the import/export
332 /// declaration.
333 List<CombinatorMirror> get combinators;
334
335 /// Returns the source location for this import/export declaration.
336 SourceLocation get location;
337 }
338
339 /// A mirror on a show/hide combinator declared on a library dependency.
340 abstract class CombinatorMirror {
341 /// The list of identifiers on the combinator.
342 List<String> get identifiers;
343
344 /// Is `true` if this is a 'show' combinator.
345 bool get isShow;
346
347 /// Is `true` if this is a 'hide' combinator.
348 bool get isHide;
349 }
350
351 /**
352 * Common interface for classes, interfaces, typedefs and type variables.
353 */
354 abstract class TypeMirror implements DeclarationMirror {
355 /**
356 * Returns the library in which this member resides.
357 */
358 LibraryMirror get library;
359
360 /**
361 * Is [:true:] iff this type is the [:Object:] type.
362 */
363 bool get isObject;
364
365 /**
366 * Is [:true:] iff this type is the [:dynamic:] type.
367 */
368 bool get isDynamic;
369
370 /**
371 * Is [:true:] iff this type is the void type.
372 */
373 bool get isVoid;
374
375 /**
376 * Is [:true:] iff this type is a type variable.
377 */
378 bool get isTypeVariable;
379
380 /**
381 * Is [:true:] iff this type is a typedef.
382 */
383 bool get isTypedef;
384
385 /**
386 * Is [:true:] iff this type is a function type.
387 */
388 bool get isFunction;
389 }
390
391 /**
392 * A class or interface type.
393 */
394 abstract class ClassMirror implements TypeMirror, ContainerMirror {
395 /**
396 * A mirror on the original declaration of this type.
397 *
398 * For most classes, they are their own original declaration. For
399 * generic classes, however, there is a distinction between the
400 * original class declaration, which has unbound type variables, and
401 * the instantiations of generic classes, which have bound type
402 * variables.
403 */
404 ClassMirror get originalDeclaration;
405
406 /**
407 * Returns the super class of this type, or null if this type is [Object] or a
408 * typedef.
409 */
410 ClassMirror get superclass;
411
412 /**
413 * Returns a list of the interfaces directly implemented by this type.
414 */
415 List<ClassMirror> get superinterfaces;
416
417 /**
418 * The mixin of this class. If this class is the result of a mixin application
419 * of the form S with M, returns a class mirror on M. Otherwise return the
420 * class mirror itself.
421 */
422 ClassMirror get mixin;
423
424 /**
425 * Is [:true:] iff this type is a class.
426 */
427 bool get isClass;
428
429 /**
430 * Is this the original declaration of this type?
431 *
432 * For most classes, they are their own original declaration. For
433 * generic classes, however, there is a distinction between the
434 * original class declaration, which has unbound type variables, and
435 * the instantiations of generic classes, which have bound type
436 * variables.
437 */
438 bool get isOriginalDeclaration;
439
440 /**
441 * Is [:true:] if this class is declared abstract.
442 */
443 bool get isAbstract;
444
445 /**
446 * Returns a list of the type arguments for this type.
447 */
448 List<TypeMirror> get typeArguments;
449
450 /**
451 * Returns the list of type variables for this type.
452 */
453 List<TypeVariableMirror> get typeVariables;
454
455 /**
456 * An immutable map from from names to mirrors for all members of
457 * this type.
458 *
459 * The members of a type are its methods, fields, getters, and
460 * setters. Note that constructors and type variables are not
461 * considered to be members of a type.
462 *
463 * This does not include inherited members.
464 */
465 Map<String, MemberMirror> get members;
466
467 /**
468 * An immutable map from names to mirrors for all method,
469 * declarations for this type. This does not include getters and
470 * setters.
471 */
472 Map<String, MethodMirror> get methods;
473
474 /**
475 * An immutable map from names to mirrors for all getter
476 * declarations for this type.
477 */
478 Map<String, MethodMirror> get getters;
479
480 /**
481 * An immutable map from names to mirrors for all setter
482 * declarations for this type.
483 */
484 Map<String, MethodMirror> get setters;
485
486 /**
487 * An immutable map from names to mirrors for all variable
488 * declarations for this type.
489 */
490 Map<String, VariableMirror> get variables;
491
492 /**
493 * An immutable map from names to mirrors for all constructor
494 * declarations for this type.
495 */
496 Map<String, MethodMirror> get constructors;
497 }
498
499 /**
500 * A type parameter as declared on a generic type.
501 */
502 abstract class TypeVariableMirror implements TypeMirror {
503 /**
504 * Returns the bound of the type parameter.
505 */
506 TypeMirror get upperBound;
507 }
508
509 /**
510 * A function type.
511 */
512 abstract class FunctionTypeMirror implements ClassMirror {
513 /**
514 * Returns the return type of this function type.
515 */
516 TypeMirror get returnType;
517
518 /**
519 * Returns the parameters for this function type.
520 */
521 List<ParameterMirror> get parameters;
522
523 /**
524 * Returns the call method for this function type.
525 */
526 MethodMirror get callMethod;
527 }
528
529 /**
530 * A typedef.
531 */
532 abstract class TypedefMirror implements ClassMirror {
533 /**
534 * The defining type for this typedef.
535 *
536 * For instance [:void f(int):] for a [:typedef void f(int):].
537 */
538 TypeMirror get value;
539 }
540
541 /**
542 * A member of a type, i.e. a field, method or constructor.
543 */
544 abstract class MemberMirror implements DeclarationMirror {
545 /**
546 * Is this member a constructor?
547 */
548 bool get isConstructor;
549
550 /**
551 * Is this member a variable?
552 *
553 * This is [:false:] for locals.
554 */
555 bool get isVariable;
556
557 /**
558 * Is this member a method?.
559 *
560 * This is [:false:] for constructors.
561 */
562 bool get isMethod;
563
564 /**
565 * Is this member declared static?
566 */
567 bool get isStatic;
568
569 /**
570 * Is this member a parameter?
571 */
572 bool get isParameter;
573 }
574
575 /**
576 * A field.
577 */
578 abstract class VariableMirror implements MemberMirror {
579
580 /**
581 * Returns true if this field is final.
582 */
583 bool get isFinal;
584
585 /**
586 * Returns true if this field is const.
587 */
588 bool get isConst;
589
590 /**
591 * Returns the type of this field.
592 */
593 TypeMirror get type;
594 }
595
596 /**
597 * Common interface constructors and methods, including factories, getters and
598 * setters.
599 */
600 abstract class MethodMirror implements MemberMirror {
601 /**
602 * Returns the list of parameters for this method.
603 */
604 List<ParameterMirror> get parameters;
605
606 /**
607 * Returns the return type of this method.
608 */
609 TypeMirror get returnType;
610
611 /**
612 * Is the reflectee abstract?
613 */
614 bool get isAbstract;
615
616 /**
617 * Is the reflectee a regular function or method?
618 *
619 * A function or method is regular if it is not a getter, setter, or
620 * constructor. Note that operators, by this definition, are
621 * regular methods.
622 */
623 bool get isRegularMethod;
624
625 /**
626 * Is the reflectee a const constructor?
627 */
628 bool get isConstConstructor;
629
630 /**
631 * Is the reflectee a generative constructor?
632 */
633 bool get isGenerativeConstructor;
634
635 /**
636 * Is the reflectee a redirecting constructor?
637 */
638 bool get isRedirectingConstructor;
639
640 /**
641 * Is the reflectee a factory constructor?
642 */
643 bool get isFactoryConstructor;
644
645 /**
646 * Is [:true:] if this method is a getter method.
647 */
648 bool get isGetter;
649
650 /**
651 * Is [:true:] if this method is a setter method.
652 */
653 bool get isSetter;
654
655 /**
656 * Is [:true:] if this method is an operator method.
657 */
658 bool get isOperator;
659 }
660
661 /**
662 * A formal parameter.
663 */
664 abstract class ParameterMirror implements VariableMirror {
665 /**
666 * Returns the type of this parameter.
667 */
668 TypeMirror get type;
669
670 /**
671 * Returns the default value for this parameter.
672 */
673 String get defaultValue;
674
675 /**
676 * Does this parameter have a default value?
677 */
678 bool get hasDefaultValue;
679
680 /**
681 * Is this parameter optional?
682 */
683 bool get isOptional;
684
685 /**
686 * Is this parameter named?
687 */
688 bool get isNamed;
689
690 /**
691 * Returns [:true:] iff this parameter is an initializing formal of a
692 * constructor. That is, if it is of the form [:this.x:] where [:x:] is a
693 * field.
694 */
695 bool get isInitializingFormal;
696
697 /**
698 * Returns the initialized field, if this parameter is an initializing formal.
699 */
700 VariableMirror get initializedField;
701 }
702
703 /**
704 * A [SourceLocation] describes the span of an entity in Dart source code.
705 * A [SourceLocation] with a non-zero [length] should be the minimum span that
706 * encloses the declaration of the mirrored entity.
707 */
708 abstract class SourceLocation {
709 /**
710 * The 1-based line number for this source location.
711 *
712 * A value of 0 means that the line number is unknown.
713 */
714 int get line;
715
716 /**
717 * The 1-based column number for this source location.
718 *
719 * A value of 0 means that the column number is unknown.
720 */
721 int get column;
722
723 /**
724 * The 0-based character offset into the [sourceText] where this source
725 * location begins.
726 *
727 * A value of -1 means that the offset is unknown.
728 */
729 int get offset;
730
731 /**
732 * The number of characters in this source location.
733 *
734 * A value of 0 means that the [offset] is approximate.
735 */
736 int get length;
737
738 /**
739 * The text of the location span.
740 */
741 String get text;
742
743 /**
744 * Returns the URI where the source originated.
745 */
746 Uri get sourceUri;
747
748 /**
749 * Returns the text of this source.
750 */
751 String get sourceText;
752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698