OLD | NEW |
| (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 #import('dart:io'); | |
8 #import('dart:uri'); | |
9 #import('dart2js_mirror.dart'); | |
10 | |
11 /** | |
12 * [Compilation] encapsulates the compilation of a program. | |
13 */ | |
14 class Compilation { | |
15 /** | |
16 * Creates a new compilation which has [script] as its entry point. | |
17 */ | |
18 factory Compilation(Path script, | |
19 Path libraryRoot, | |
20 [Path packageRoot, | |
21 List<String> opts = const <String>[]]) { | |
22 return new Dart2JsCompilation(script, libraryRoot, packageRoot, opts); | |
23 } | |
24 | |
25 /** | |
26 * Creates a new compilation which consists of a set of libraries, but which | |
27 * has no entry point. This compilation cannot generate output but can only | |
28 * be used for static inspection of the source code. | |
29 */ | |
30 factory Compilation.library(List<Path> libraries, | |
31 Path libraryRoot, | |
32 [Path packageRoot, | |
33 List<String> opts = const []]) { | |
34 return new Dart2JsCompilation.library(libraries, libraryRoot, | |
35 packageRoot, opts); | |
36 } | |
37 | |
38 /** | |
39 * Returns the mirror system for this compilation. | |
40 */ | |
41 final MirrorSystem mirrors; | |
42 | |
43 /** | |
44 * Returns a future for the compiled JavaScript code. | |
45 */ | |
46 abstract Future<String> compileToJavaScript(); | |
47 } | |
48 | |
49 /** | |
50 * The main interface for the whole mirror system. | |
51 */ | |
52 abstract class MirrorSystem { | |
53 /** | |
54 * Returns an unmodifiable map of all libraries in this mirror system. | |
55 */ | |
56 Map<Object, LibraryMirror> get libraries; | |
57 } | |
58 | |
59 | |
60 /** | |
61 * An entity in the mirror system. | |
62 */ | |
63 abstract class Mirror implements Hashable { | |
64 /** | |
65 * The simple name of the entity. The simple name is in most cases the | |
66 * the declared single identifier name of the entity, such as 'method' for | |
67 * a method [:void method() {...}:]. | |
68 */ | |
69 String get simpleName; | |
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 * Returns the mirror system which contains this mirror. | |
80 */ | |
81 MirrorSystem get system; | |
82 } | |
83 | |
84 /** | |
85 * Common interface for interface types and libraries. | |
86 */ | |
87 abstract class ObjectMirror implements Mirror { | |
88 | |
89 /** | |
90 * Returns an unmodifiable map of the members of declared in this type or | |
91 * library. | |
92 */ | |
93 Map<Object, MemberMirror> get declaredMembers; | |
94 } | |
95 | |
96 /** | |
97 * A library. | |
98 */ | |
99 abstract class LibraryMirror extends ObjectMirror { | |
100 /** | |
101 * The name of the library, as given in #library(). | |
102 */ | |
103 String get simpleName; | |
104 | |
105 /** | |
106 * Returns an iterable over all types in the library. | |
107 */ | |
108 Map<Object, InterfaceMirror> get types; | |
109 | |
110 /** | |
111 * Returns the source location for this library. | |
112 */ | |
113 Location get location; | |
114 } | |
115 | |
116 /** | |
117 * Common interface for classes, interfaces, typedefs and type variables. | |
118 */ | |
119 abstract class TypeMirror implements Mirror { | |
120 /** | |
121 * Returns the source location for this type. | |
122 */ | |
123 Location get location; | |
124 | |
125 /** | |
126 * Returns the library in which this member resides. | |
127 */ | |
128 LibraryMirror get library; | |
129 | |
130 /** | |
131 * Is [:true:] iff this type is the [:Object:] type. | |
132 */ | |
133 bool get isObject; | |
134 | |
135 /** | |
136 * Is [:true:] iff this type is the [:Dynamic:] type. | |
137 */ | |
138 bool get isDynamic; | |
139 | |
140 /** | |
141 * Is [:true:] iff this type is the void type. | |
142 */ | |
143 bool get isVoid; | |
144 | |
145 /** | |
146 * Is [:true:] iff this type is a type variable. | |
147 */ | |
148 bool get isTypeVariable; | |
149 | |
150 /** | |
151 * Is [:true:] iff this type is a typedef. | |
152 */ | |
153 bool get isTypedef; | |
154 | |
155 /** | |
156 * Is [:true:] iff this type is a function type. | |
157 */ | |
158 bool get isFunction; | |
159 } | |
160 | |
161 /** | |
162 * A class or interface type. | |
163 */ | |
164 abstract class InterfaceMirror implements TypeMirror, ObjectMirror { | |
165 /** | |
166 * Returns the defining type, i.e. declaration of a type. | |
167 */ | |
168 InterfaceMirror get declaration; | |
169 | |
170 /** | |
171 * Returns the super class of this type, or null if this type is [Object] or a | |
172 * typedef. | |
173 */ | |
174 InterfaceMirror get superclass; | |
175 | |
176 /** | |
177 * Returns an iterable over the interfaces directly implemented by this type. | |
178 */ | |
179 Map<Object, InterfaceMirror> get interfaces; | |
180 | |
181 /** | |
182 * Is [:true:] iff this type is a class. | |
183 */ | |
184 bool get isClass; | |
185 | |
186 /** | |
187 * Is [:true:] iff this type is an interface. | |
188 */ | |
189 bool get isInterface; | |
190 | |
191 /** | |
192 * Is [:true:] if this type is private. | |
193 */ | |
194 bool get isPrivate; | |
195 | |
196 /** | |
197 * Is [:true:] if this type is the declaration of a type. | |
198 */ | |
199 bool get isDeclaration; | |
200 | |
201 /** | |
202 * Returns a list of the type arguments for this type. | |
203 */ | |
204 List<TypeMirror> get typeArguments; | |
205 | |
206 /** | |
207 * Returns the list of type variables for this type. | |
208 */ | |
209 List<TypeVariableMirror> get typeVariables; | |
210 | |
211 /** | |
212 * Returns an immutable map of the constructors in this interface. | |
213 */ | |
214 Map<Object, MethodMirror> get constructors; | |
215 | |
216 /** | |
217 * Returns the default type for this interface. | |
218 */ | |
219 InterfaceMirror get defaultType; | |
220 } | |
221 | |
222 /** | |
223 * A type parameter as declared on a generic type. | |
224 */ | |
225 abstract class TypeVariableMirror implements TypeMirror { | |
226 /** | |
227 * Return a mirror on the class, interface, or typedef that declared the | |
228 * type variable. | |
229 */ | |
230 // Should not be called [declaration] as we then would have two [TypeMirror] | |
231 // subtypes ([InterfaceMirror] and [TypeVariableMirror]) which have | |
232 // [declaration()] methods but with different semantics. | |
233 InterfaceMirror get declarer; | |
234 | |
235 /** | |
236 * Returns the bound of the type parameter. | |
237 */ | |
238 TypeMirror get bound; | |
239 } | |
240 | |
241 /** | |
242 * A function type. | |
243 */ | |
244 abstract class FunctionTypeMirror implements InterfaceMirror { | |
245 /** | |
246 * Returns the return type of this function type. | |
247 */ | |
248 TypeMirror get returnType; | |
249 | |
250 /** | |
251 * Returns the parameters for this function type. | |
252 */ | |
253 List<ParameterMirror> get parameters; | |
254 | |
255 /** | |
256 * Returns the call method for this function type. | |
257 */ | |
258 MethodMirror get callMethod; | |
259 } | |
260 | |
261 /** | |
262 * A typedef. | |
263 */ | |
264 abstract class TypedefMirror implements InterfaceMirror { | |
265 /** | |
266 * Returns the defining type for this typedef. For instance [:void f(int):] | |
267 * for a [:typedef void f(int):]. | |
268 */ | |
269 TypeMirror get definition; | |
270 } | |
271 | |
272 /** | |
273 * A member of a type, i.e. a field, method or constructor. | |
274 */ | |
275 abstract class MemberMirror implements Mirror { | |
276 /** | |
277 * Returns the source location for this member. | |
278 */ | |
279 Location get location; | |
280 | |
281 /** | |
282 * Returns a mirror on the declaration immediately surrounding the reflectee. | |
283 * This could be a class, interface, library or another method or function. | |
284 */ | |
285 ObjectMirror get surroundingDeclaration; | |
286 | |
287 /** | |
288 * Returns true if this is a top level member, i.e. a member not within a | |
289 * type. | |
290 */ | |
291 bool get isTopLevel; | |
292 | |
293 /** | |
294 * Returns true if this member is a constructor. | |
295 */ | |
296 bool get isConstructor; | |
297 | |
298 /** | |
299 * Returns true if this member is a field. | |
300 */ | |
301 bool get isField; | |
302 | |
303 /** | |
304 * Returns true if this member is a method. | |
305 */ | |
306 bool get isMethod; | |
307 | |
308 /** | |
309 * Returns true if this member is private. | |
310 */ | |
311 bool get isPrivate; | |
312 | |
313 /** | |
314 * Returns true if this member is static. | |
315 */ | |
316 bool get isStatic; | |
317 } | |
318 | |
319 /** | |
320 * A field. | |
321 */ | |
322 abstract class FieldMirror implements MemberMirror { | |
323 | |
324 /** | |
325 * Returns true if this field is final. | |
326 */ | |
327 bool get isFinal; | |
328 | |
329 /** | |
330 * Returns the type of this field. | |
331 */ | |
332 TypeMirror get type; | |
333 } | |
334 | |
335 /** | |
336 * Common interface constructors and methods, including factories, getters and | |
337 * setters. | |
338 */ | |
339 abstract class MethodMirror implements MemberMirror { | |
340 /** | |
341 * Returns the list of parameters for this method. | |
342 */ | |
343 List<ParameterMirror> get parameters; | |
344 | |
345 /** | |
346 * Returns the return type of this method. | |
347 */ | |
348 TypeMirror get returnType; | |
349 | |
350 /** | |
351 * Is [:true:] if this method is a constant constructor. | |
352 */ | |
353 bool get isConst; | |
354 | |
355 /** | |
356 * Is [:true:] if this method is a factory method. | |
357 */ | |
358 bool get isFactory; | |
359 | |
360 /** | |
361 * Returns the constructor name for named constructors and factory methods, | |
362 * e.g. [:'bar':] for constructor [:Foo.bar:] of type [:Foo:]. | |
363 */ | |
364 String get constructorName; | |
365 | |
366 /** | |
367 * Is [:true:] if this method is a getter method. | |
368 */ | |
369 bool get isGetter; | |
370 | |
371 /** | |
372 * Is [:true:] if this method is a setter method. | |
373 */ | |
374 bool get isSetter; | |
375 | |
376 /** | |
377 * Is [:true:] if this method is an operator method. | |
378 */ | |
379 bool get isOperator; | |
380 | |
381 /** | |
382 * Returns the operator name for operator methods, e.g. [:'<':] for | |
383 * [:operator <:] | |
384 */ | |
385 String get operatorName; | |
386 } | |
387 | |
388 /** | |
389 * A formal parameter. | |
390 */ | |
391 abstract class ParameterMirror implements Mirror { | |
392 /** | |
393 * Returns the type of this parameter. | |
394 */ | |
395 TypeMirror get type; | |
396 | |
397 /** | |
398 * Returns the default value for this parameter. | |
399 */ | |
400 String get defaultValue; | |
401 | |
402 /** | |
403 * Returns true if this parameter has a default value. | |
404 */ | |
405 bool get hasDefaultValue; | |
406 | |
407 /** | |
408 * Returns true if this parameter is optional. | |
409 */ | |
410 bool get isOptional; | |
411 | |
412 /** | |
413 * Returns [:true:] iff this parameter is an initializing formal of a | |
414 * constructor. That is, if it is of the form [:this.x:] where [:x:] is a | |
415 * field. | |
416 */ | |
417 bool get isInitializingFormal; | |
418 | |
419 /** | |
420 * Returns the initialized field, if this parameter is an initializing formal. | |
421 */ | |
422 FieldMirror get initializedField; | |
423 } | |
424 | |
425 /** | |
426 * A [Location] describes the span of an entity in Dart source code. | |
427 * A [Location] should be the minimum span that encloses the declaration of the | |
428 * mirrored entity. | |
429 */ | |
430 abstract class Location { | |
431 /** | |
432 * The character position where the location begins. | |
433 */ | |
434 int get start; | |
435 | |
436 /** | |
437 * The character position where the location ends. | |
438 */ | |
439 int get end; | |
440 | |
441 /** | |
442 * Returns the [Source] in which this [Location] indexes. | |
443 * If [:loc:] is a location, [:loc.source().text()[loc.start()] is where it | |
444 * starts, and [:loc.source().text()[loc.end()] is where it ends. | |
445 */ | |
446 Source get source; | |
447 | |
448 /** | |
449 * The text of the location span. | |
450 */ | |
451 String get text; | |
452 } | |
453 | |
454 /** | |
455 * A [Source] describes the source code of a compilation unit in Dart source | |
456 * code. | |
457 */ | |
458 abstract class Source { | |
459 /** | |
460 * Returns the URI where the source originated. | |
461 */ | |
462 Uri get uri; | |
463 | |
464 /** | |
465 * Returns the text of this source. | |
466 */ | |
467 String get text; | |
468 } | |
OLD | NEW |