| 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 23 matching lines...) Expand all Loading... |
| 34 import 'package:compiler/implementation/dart2jslib.dart' show | 34 import 'package:compiler/implementation/dart2jslib.dart' show |
| 35 Compiler, | 35 Compiler, |
| 36 Enqueuer, | 36 Enqueuer, |
| 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 AbstractFieldElement, |
| 44 ClassElement, | 45 ClassElement, |
| 45 CompilationUnitElement, | 46 CompilationUnitElement, |
| 46 Element, | 47 Element, |
| 47 ElementCategory, | 48 ElementCategory, |
| 49 FunctionElement, |
| 48 LibraryElement, | 50 LibraryElement, |
| 49 ScopeContainerElement; | 51 ScopeContainerElement; |
| 50 | 52 |
| 53 import 'package:compiler/implementation/elements/modelx.dart' as modelx; |
| 54 |
| 51 import 'package:compiler/implementation/dart_types.dart' show | 55 import 'package:compiler/implementation/dart_types.dart' show |
| 52 DartType; | 56 DartType; |
| 53 | 57 |
| 54 import 'package:compiler/implementation/scanner/scannerlib.dart' show | 58 import 'package:compiler/implementation/scanner/scannerlib.dart' show |
| 55 EOF_TOKEN, | 59 EOF_TOKEN, |
| 56 IDENTIFIER_TOKEN, | 60 IDENTIFIER_TOKEN, |
| 57 KEYWORD_TOKEN, | 61 KEYWORD_TOKEN, |
| 58 PartialClassElement, | 62 PartialClassElement, |
| 59 PartialElement, | 63 PartialElement, |
| 60 Token; | 64 Token; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 name: e.getLibraryName(), | 362 name: e.getLibraryName(), |
| 359 serializeEnclosing: () { | 363 serializeEnclosing: () { |
| 360 // The enclosing scope of a library is a scope which contains all the | 364 // The enclosing scope of a library is a scope which contains all the |
| 361 // imported names. | 365 // imported names. |
| 362 isFirst = true; | 366 isFirst = true; |
| 363 buffer.write('{\n'); | 367 buffer.write('{\n'); |
| 364 indentationLevel++; | 368 indentationLevel++; |
| 365 indented.write('"kind": "imports",\n'); | 369 indented.write('"kind": "imports",\n'); |
| 366 indented.write('"members": ['); | 370 indented.write('"members": ['); |
| 367 indentationLevel++; | 371 indentationLevel++; |
| 368 e.importScope.importScope.values.forEach(forEach); | 372 importScope(e).importScope.values.forEach(forEach); |
| 369 indentationLevel--; | 373 indentationLevel--; |
| 370 buffer.write('\n'); | 374 buffer.write('\n'); |
| 371 indented.write('],\n'); | 375 indented.write('],\n'); |
| 372 // The enclosing scope of the imported names scope is the superclass | 376 // The enclosing scope of the imported names scope is the superclass |
| 373 // scope of the current class. | 377 // scope of the current class. |
| 374 indented.write('"enclosing": '); | 378 indented.write('"enclosing": '); |
| 375 serializeClassSide( | 379 serializeClassSide( |
| 376 currentClass.superclass, isStatic: false, includeSuper: true); | 380 currentClass.superclass, isStatic: false, includeSuper: true); |
| 377 buffer.write('\n'); | 381 buffer.write('\n'); |
| 378 indentationLevel--; | 382 indentationLevel--; |
| 379 indented.write('}'); | 383 indented.write('}'); |
| 380 }, | 384 }, |
| 381 serializeMembers: () { | 385 serializeMembers: () { |
| 382 isFirst = true; | 386 isFirst = true; |
| 383 e.localScope.values.forEach(forEach); | 387 localScope(e).values.forEach(forEach); |
| 384 }); | 388 }); |
| 385 } | 389 } |
| 386 | 390 |
| 387 void visitClassElement(ClassElement e) { | 391 void visitClassElement(ClassElement e) { |
| 388 currentClass = e; | 392 currentClass = e; |
| 389 serializeClassSide(e, isStatic: true); | 393 serializeClassSide(e, isStatic: true); |
| 390 } | 394 } |
| 391 | 395 |
| 392 /// Serializes one of the "sides" a class. The sides of a class are "instance | 396 /// Serializes one of the "sides" a class. The sides of a class are "instance |
| 393 /// side" and "class side". These terms are from Smalltalk. The instance side | 397 /// side" and "class side". These terms are from Smalltalk. The instance side |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 serialize(member); | 464 serialize(member); |
| 461 isFirst = false; | 465 isFirst = false; |
| 462 }); | 466 }); |
| 463 }); | 467 }); |
| 464 } | 468 } |
| 465 | 469 |
| 466 void visitCompilationUnitElement(CompilationUnitElement e) { | 470 void visitCompilationUnitElement(CompilationUnitElement e) { |
| 467 e.enclosingElement.accept(this); | 471 e.enclosingElement.accept(this); |
| 468 } | 472 } |
| 469 | 473 |
| 474 void visitAbstractFieldElement(AbstractFieldElement e) { |
| 475 throw new UnsupportedError('AbstractFieldElement cannot be serialized.'); |
| 476 } |
| 477 |
| 470 void serialize( | 478 void serialize( |
| 471 Element element, | 479 Element element, |
| 472 {bool omitEnclosing: true, | 480 {bool omitEnclosing: true, |
| 473 void serializeMembers(), | 481 void serializeMembers(), |
| 474 void serializeEnclosing(), | 482 void serializeEnclosing(), |
| 475 String kind, | 483 String kind, |
| 476 String name}) { | 484 String name}) { |
| 485 if (element.isAbstractField) { |
| 486 AbstractFieldElement field = element; |
| 487 FunctionElement getter = field.getter; |
| 488 FunctionElement setter = field.setter; |
| 489 if (getter != null) { |
| 490 serialize( |
| 491 getter, |
| 492 omitEnclosing: omitEnclosing, |
| 493 serializeMembers: serializeMembers, |
| 494 serializeEnclosing: serializeEnclosing, |
| 495 kind: kind, |
| 496 name: name); |
| 497 } |
| 498 if (setter != null) { |
| 499 if (getter != null) { |
| 500 buffer.write(',\n'); |
| 501 indented; |
| 502 } |
| 503 serialize( |
| 504 getter, |
| 505 omitEnclosing: omitEnclosing, |
| 506 serializeMembers: serializeMembers, |
| 507 serializeEnclosing: serializeEnclosing, |
| 508 kind: kind, |
| 509 name: name); |
| 510 } |
| 511 return; |
| 512 } |
| 477 DartType type; | 513 DartType type; |
| 478 int category = element.kind.category; | 514 int category = element.kind.category; |
| 479 if (category == ElementCategory.FUNCTION || | 515 if (category == ElementCategory.FUNCTION || |
| 480 category == ElementCategory.VARIABLE || | 516 category == ElementCategory.VARIABLE || |
| 481 element.isConstructor) { | 517 element.isConstructor) { |
| 482 type = element.computeType(cachedCompiler); | 518 type = element.computeType(cachedCompiler); |
| 483 } | 519 } |
| 484 if (name == null) { | 520 if (name == null) { |
| 485 name = element.name; | 521 name = element.name; |
| 486 } | 522 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 serializeEnclosing(); | 558 serializeEnclosing(); |
| 523 } else { | 559 } else { |
| 524 element.enclosingElement.accept(this); | 560 element.enclosingElement.accept(this); |
| 525 } | 561 } |
| 526 } | 562 } |
| 527 indentationLevel--; | 563 indentationLevel--; |
| 528 buffer.write('\n'); | 564 buffer.write('\n'); |
| 529 indented.write('}'); | 565 indented.write('}'); |
| 530 } | 566 } |
| 531 } | 567 } |
| 568 |
| 569 modelx.ScopeX localScope(modelx.LibraryElementX element) => element.localScope; |
| 570 |
| 571 modelx.ImportScope importScope(modelx.LibraryElementX element) { |
| 572 return element.importScope; |
| 573 } |
| OLD | NEW |