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

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

Issue 119913002: Align source mirrors with runtime mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library mirrors; 5 library mirrors;
6 6
7 /** 7 import 'dart:mirrors';
8 * The main interface for the whole mirror system. 8 import 'dart:mirrors' as api show SourceLocation;
9 */ 9 export 'dart:mirrors';
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 10
16 /** 11 abstract class DeclarationSourceMirror implements DeclarationMirror {
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 12 /// Returns `true` if the name of this declaration is generated by the
68 /// provider of the mirror system. 13 /// provider of the mirror system.
69 bool get isNameSynthetic; 14 bool get isNameSynthetic;
70 15
71 /** 16 /**
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. 17 * Looks up [name] in the scope of this declaration.
113 * 18 *
114 * [name] may be either a single identifier, like 'foo', or of the 19 * [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. 20 * a prefixed identifier, like 'foo.bar', where 'foo' must be a prefix.
116 * For methods and constructors, the scope includes the parameters. For 21 * For methods and constructors, the scope includes the parameters. For
117 * classes and typedefs, the scope includes the type variables. 22 * classes and typedefs, the scope includes the type variables.
118 * For classes and class members, the scope includes inherited members. 23 * For classes and class members, the scope includes inherited members.
119 * 24 *
120 * See also: 25 * See also:
121 * 26 *
122 * * [Lexical Scope](https://www.dartlang.org/docs/dart-up-and-running/content s/ch02.html#ch02-lexical-scope) 27 * * [Lexical Scope](https://www.dartlang.org/docs/dart-up-and-running/content s/ch02.html#ch02-lexical-scope)
123 * in Dart Up and Running. 28 * in Dart Up and Running.
124 * * [Lexical Scoping](http://www.dartlang.org/docs/spec/latest/dart-language- specification.html#h.jb82efuudrc5) 29 * * [Lexical Scoping](http://www.dartlang.org/docs/spec/latest/dart-language- specification.html#h.jb82efuudrc5)
125 * in the Dart Specification. 30 * in the Dart Specification.
126 */ 31 */
127 DeclarationMirror lookupInScope(String name); 32 DeclarationMirror lookupInScope(String name);
128 } 33 }
129 34
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 /** 35 /**
174 * Specialized [InstanceMirror] used for reflection on constant lists. 36 * Specialized [InstanceMirror] used for reflection on constant lists.
175 */ 37 */
176 abstract class ListInstanceMirror implements InstanceMirror { 38 abstract class ListInstanceMirror implements InstanceMirror {
177 /** 39 /**
178 * Returns an instance mirror of the value at [index] or throws a [RangeError] 40 * Returns an instance mirror of the value at [index] or throws a [RangeError]
179 * if the [index] is out of bounds. 41 * if the [index] is out of bounds.
180 */ 42 */
181 InstanceMirror operator[](int index); 43 InstanceMirror getElement(int index);
182 44
183 /** 45 /**
184 * The number of elements in the list. 46 * The number of elements in the list.
185 */ 47 */
186 int get length; 48 int get length;
187 } 49 }
188 50
189 /** 51 /**
190 * Specialized [InstanceMirror] used for reflection on constant maps. 52 * Specialized [InstanceMirror] used for reflection on constant maps.
191 */ 53 */
192 abstract class MapInstanceMirror implements InstanceMirror { 54 abstract class MapInstanceMirror implements InstanceMirror {
193 /** 55 /**
194 * Returns a collection containing all the keys in the map. 56 * Returns a collection containing all the keys in the map.
195 */ 57 */
196 Iterable<String> get keys; 58 Iterable<String> get keys;
197 59
198 /** 60 /**
199 * Returns an instance mirror of the value for the given key or 61 * Returns an instance mirror of the value for the given key or
200 * null if key is not in the map. 62 * null if key is not in the map.
201 */ 63 */
202 InstanceMirror operator[](String key); 64 InstanceMirror getValue(String key);
203 65
204 /** 66 /**
205 * The number of {key, value} pairs in the map. 67 * The number of {key, value} pairs in the map.
206 */ 68 */
207 int get length; 69 int get length;
208 } 70 }
209 71
210 /** 72 /**
211 * Specialized [InstanceMirror] used for reflection on type constants. 73 * Specialized [InstanceMirror] used for reflection on type constants.
212 */ 74 */
(...skipping 25 matching lines...) Expand all
238 /** 100 /**
239 * Is [:true:] if this comment is a documentation comment. 101 * Is [:true:] if this comment is a documentation comment.
240 * 102 *
241 * That is, that the comment is either enclosed in [: /** ... */ :] or starts 103 * That is, that the comment is either enclosed in [: /** ... */ :] or starts
242 * with [: /// :]. 104 * with [: /// :].
243 */ 105 */
244 bool get isDocComment; 106 bool get isDocComment;
245 } 107 }
246 108
247 /** 109 /**
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. 110 * A library.
261 */ 111 */
262 abstract class LibraryMirror implements ContainerMirror, DeclarationMirror { 112 abstract class LibrarySourceMirror
263 /** 113 implements DeclarationSourceMirror, LibraryMirror {
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 /** 114 /**
308 * Returns a list of the imports and exports in this library; 115 * Returns a list of the imports and exports in this library;
309 */ 116 */
310 List<LibraryDependencyMirror> get libraryDependencies; 117 List<LibraryDependencyMirror> get libraryDependencies;
311 } 118 }
312 119
313 /// A mirror on an import or export declaration. 120 /// A mirror on an import or export declaration.
314 abstract class LibraryDependencyMirror { 121 abstract class LibraryDependencyMirror {
315 /// Is `true` if this dependency is an import. 122 /// Is `true` if this dependency is an import.
316 bool get isImport; 123 bool get isImport;
(...skipping 27 matching lines...) Expand all
344 /// Is `true` if this is a 'show' combinator. 151 /// Is `true` if this is a 'show' combinator.
345 bool get isShow; 152 bool get isShow;
346 153
347 /// Is `true` if this is a 'hide' combinator. 154 /// Is `true` if this is a 'hide' combinator.
348 bool get isHide; 155 bool get isHide;
349 } 156 }
350 157
351 /** 158 /**
352 * Common interface for classes, interfaces, typedefs and type variables. 159 * Common interface for classes, interfaces, typedefs and type variables.
353 */ 160 */
354 abstract class TypeMirror implements DeclarationMirror { 161 abstract class TypeSourceMirror implements DeclarationSourceMirror, TypeMirror {
355 /** 162 /// Returns `true` is this is a mirror on the void type.
356 * Returns the library in which this member resides. 163 bool get isVoid;
357 */
358 LibraryMirror get library;
359 164
360 /** 165 /// Returns `true` is this is a mirror on the dynamic type.
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; 166 bool get isDynamic;
369 167
370 /** 168 /// Create a type mirror on the instantiation of the declaration of this type
371 * Is [:true:] iff this type is the void type. 169 /// with [typeArguments] as type arguments.
372 */ 170 TypeMirror createInstantiation(List<TypeMirror> typeArguments);
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 } 171 }
390 172
391 /** 173 /**
392 * A class or interface type. 174 * A class or interface type.
393 */ 175 */
394 abstract class ClassMirror implements TypeMirror, ContainerMirror { 176 abstract class ClassSourceMirror implements TypeSourceMirror, ClassMirror {
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 /** 177 /**
441 * Is [:true:] if this class is declared abstract. 178 * Is [:true:] if this class is declared abstract.
442 */ 179 */
443 bool get isAbstract; 180 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 } 181 }
660 182
661 /** 183 /**
662 * A formal parameter. 184 * A formal parameter.
663 */ 185 */
664 abstract class ParameterMirror implements VariableMirror { 186 abstract class ParameterSourceMirror implements ParameterMirror {
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 /** 187 /**
691 * Returns [:true:] iff this parameter is an initializing formal of a 188 * 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 189 * constructor. That is, if it is of the form [:this.x:] where [:x:] is a
693 * field. 190 * field.
694 */ 191 */
695 bool get isInitializingFormal; 192 bool get isInitializingFormal;
696 193
697 /** 194 /**
698 * Returns the initialized field, if this parameter is an initializing formal. 195 * Returns the initialized field, if this parameter is an initializing formal.
699 */ 196 */
700 VariableMirror get initializedField; 197 VariableMirror get initializedField;
701 } 198 }
702 199
703 /** 200 /**
704 * A [SourceLocation] describes the span of an entity in Dart source code. 201 * 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 202 * A [SourceLocation] with a non-zero [length] should be the minimum span that
706 * encloses the declaration of the mirrored entity. 203 * encloses the declaration of the mirrored entity.
707 */ 204 */
708 abstract class SourceLocation { 205 abstract class SourceLocation implements api.SourceLocation {
709 /** 206 /**
710 * The 1-based line number for this source location. 207 * The 1-based line number for this source location.
711 * 208 *
712 * A value of 0 means that the line number is unknown. 209 * A value of 0 means that the line number is unknown.
713 */ 210 */
714 int get line; 211 int get line;
715 212
716 /** 213 /**
717 * The 1-based column number for this source location. 214 * The 1-based column number for this source location.
718 * 215 *
(...skipping 24 matching lines...) Expand all
743 /** 240 /**
744 * Returns the URI where the source originated. 241 * Returns the URI where the source originated.
745 */ 242 */
746 Uri get sourceUri; 243 Uri get sourceUri;
747 244
748 /** 245 /**
749 * Returns the text of this source. 246 * Returns the text of this source.
750 */ 247 */
751 String get sourceText; 248 String get sourceText;
752 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698