OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 trydart.poi; | 5 library trydart.poi; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Completer, | 8 Completer, |
9 Future, | 9 Future, |
10 Stream; | 10 Stream; |
(...skipping 26 matching lines...) Expand all Loading... |
37 QueueFilter, | 37 QueueFilter, |
38 WorkItem; | 38 WorkItem; |
39 | 39 |
40 import 'package:compiler/implementation/elements/visitor.dart' show | 40 import 'package:compiler/implementation/elements/visitor.dart' show |
41 ElementVisitor; | 41 ElementVisitor; |
42 | 42 |
43 import 'package:compiler/implementation/elements/elements.dart' show | 43 import 'package:compiler/implementation/elements/elements.dart' show |
44 ClassElement, | 44 ClassElement, |
45 CompilationUnitElement, | 45 CompilationUnitElement, |
46 Element, | 46 Element, |
| 47 ElementCategory, |
47 LibraryElement, | 48 LibraryElement, |
48 ScopeContainerElement; | 49 ScopeContainerElement; |
49 | 50 |
| 51 import 'package:compiler/implementation/dart_types.dart' show |
| 52 DartType; |
| 53 |
50 import 'package:compiler/implementation/scanner/scannerlib.dart' show | 54 import 'package:compiler/implementation/scanner/scannerlib.dart' show |
51 EOF_TOKEN, | 55 EOF_TOKEN, |
52 IDENTIFIER_TOKEN, | 56 IDENTIFIER_TOKEN, |
53 KEYWORD_TOKEN, | 57 KEYWORD_TOKEN, |
54 PartialClassElement, | 58 PartialClassElement, |
55 PartialElement, | 59 PartialElement, |
56 Token; | 60 Token; |
57 | 61 |
58 /// Controls if this program should be querying Dart Mind. Used by tests. | 62 /// Controls if this program should be querying Dart Mind. Used by tests. |
59 bool enableDartMind = true; | 63 bool enableDartMind = true; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 364 |
361 void visitCompilationUnitElement(CompilationUnitElement e) { | 365 void visitCompilationUnitElement(CompilationUnitElement e) { |
362 e.enclosingElement.accept(this); | 366 e.enclosingElement.accept(this); |
363 } | 367 } |
364 | 368 |
365 void serialize( | 369 void serialize( |
366 Element element, | 370 Element element, |
367 {bool omitEnclosing: true, | 371 {bool omitEnclosing: true, |
368 void serializeMembers(), | 372 void serializeMembers(), |
369 String name}) { | 373 String name}) { |
| 374 DartType type; |
| 375 int category = element.kind.category; |
| 376 if (category == ElementCategory.FUNCTION || |
| 377 category == ElementCategory.VARIABLE || |
| 378 element.isConstructor) { |
| 379 type = element.computeType(cachedCompiler); |
| 380 } |
370 if (name == null) { | 381 if (name == null) { |
371 name = element.name; | 382 name = element.name; |
372 } | 383 } |
373 buffer.write('{\n'); | 384 buffer.write('{\n'); |
374 indentationLevel++; | 385 indentationLevel++; |
375 indented | 386 indented |
376 ..write('"name": "') | 387 ..write('"name": "') |
377 ..write(name) | 388 ..write(name) |
378 ..write('",\n'); | 389 ..write('",\n'); |
379 indented | 390 indented |
380 ..write('"kind": "') | 391 ..write('"kind": "') |
381 ..write(element.kind) | 392 ..write(element.kind) |
382 ..write('"'); | 393 ..write('"'); |
383 // TODO(ahe): Add a type/signature field. | 394 if (type != null) { |
| 395 buffer.write(',\n'); |
| 396 indented |
| 397 ..write('"type": "') |
| 398 ..write(type) |
| 399 ..write('"'); |
| 400 } |
384 if (serializeMembers != null) { | 401 if (serializeMembers != null) { |
385 buffer.write(',\n'); | 402 buffer.write(',\n'); |
386 indented.write('"members": ['); | 403 indented.write('"members": ['); |
387 indentationLevel++; | 404 indentationLevel++; |
388 serializeMembers(); | 405 serializeMembers(); |
389 indentationLevel--; | 406 indentationLevel--; |
390 buffer.write('\n'); | 407 buffer.write('\n'); |
391 indented.write(']'); | 408 indented.write(']'); |
392 } | 409 } |
393 if (!omitEnclosing) { | 410 if (!omitEnclosing) { |
394 buffer.write(',\n'); | 411 buffer.write(',\n'); |
395 indented.write('"enclosing": '); | 412 indented.write('"enclosing": '); |
396 element.enclosingElement.accept(this); | 413 element.enclosingElement.accept(this); |
397 } | 414 } |
398 indentationLevel--; | 415 indentationLevel--; |
399 buffer.write('\n'); | 416 buffer.write('\n'); |
400 indented.write('}'); | 417 indented.write('}'); |
401 } | 418 } |
402 } | 419 } |
OLD | NEW |