| OLD | NEW |
| 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_dart2js; | 5 library mirrors_dart2js; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:uri'; | 8 import 'dart:uri'; |
| 9 | 9 |
| 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; | 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Dart2Js specific extensions of mirror interfaces | 380 // Dart2Js specific extensions of mirror interfaces |
| 381 //------------------------------------------------------------------------------ | 381 //------------------------------------------------------------------------------ |
| 382 | 382 |
| 383 abstract class Dart2JsMirror implements Mirror { | 383 abstract class Dart2JsMirror implements Mirror { |
| 384 Dart2JsMirrorSystem get system; | 384 Dart2JsMirrorSystem get system; |
| 385 } | 385 } |
| 386 | 386 |
| 387 abstract class Dart2JsDeclarationMirror | 387 abstract class Dart2JsDeclarationMirror |
| 388 implements Dart2JsMirror, DeclarationMirror { | 388 implements Dart2JsMirror, DeclarationMirror { |
| 389 | 389 |
| 390 bool get isTopLevel => owner != null && owner is LibraryMirror; |
| 391 |
| 392 bool get isPrivate => _isPrivate(simpleName); |
| 390 } | 393 } |
| 391 | 394 |
| 392 abstract class Dart2JsMemberMirror | 395 abstract class Dart2JsMemberMirror extends Dart2JsDeclarationMirror |
| 393 implements Dart2JsDeclarationMirror, MemberMirror { | 396 implements MemberMirror { |
| 394 | 397 |
| 395 } | 398 } |
| 396 | 399 |
| 397 abstract class Dart2JsTypeMirror | 400 abstract class Dart2JsTypeMirror extends Dart2JsDeclarationMirror |
| 398 implements Dart2JsDeclarationMirror, TypeMirror { | 401 implements TypeMirror { |
| 399 | 402 |
| 400 } | 403 } |
| 401 | 404 |
| 402 abstract class Dart2JsElementMirror implements Dart2JsDeclarationMirror { | 405 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
| 403 final Dart2JsMirrorSystem system; | 406 final Dart2JsMirrorSystem system; |
| 404 final Element _element; | 407 final Element _element; |
| 405 | 408 |
| 406 Dart2JsElementMirror(this.system, this._element) { | 409 Dart2JsElementMirror(this.system, this._element) { |
| 407 assert (system !== null); | 410 assert (system !== null); |
| 408 assert (_element !== null); | 411 assert (_element !== null); |
| 409 } | 412 } |
| 410 | 413 |
| 411 String get simpleName => _element.name.slowToString(); | 414 String get simpleName => _element.name.slowToString(); |
| 412 | 415 |
| 413 String get displayName => simpleName; | 416 String get displayName => simpleName; |
| 414 | 417 |
| 415 SourceLocation get location => new Dart2JsLocation( | 418 SourceLocation get location => new Dart2JsLocation( |
| 416 _element.getCompilationUnit().script, | 419 _element.getCompilationUnit().script, |
| 417 system.compiler.spanFromElement(_element)); | 420 system.compiler.spanFromElement(_element)); |
| 418 | 421 |
| 419 String toString() => _element.toString(); | 422 String toString() => _element.toString(); |
| 420 | 423 |
| 421 int get hashCode => qualifiedName.hashCode; | 424 int get hashCode => qualifiedName.hashCode; |
| 422 } | 425 } |
| 423 | 426 |
| 424 abstract class Dart2JsProxyMirror implements Dart2JsDeclarationMirror { | 427 abstract class Dart2JsProxyMirror extends Dart2JsDeclarationMirror { |
| 425 final Dart2JsMirrorSystem system; | 428 final Dart2JsMirrorSystem system; |
| 426 | 429 |
| 427 Dart2JsProxyMirror(this.system); | 430 Dart2JsProxyMirror(this.system); |
| 428 | 431 |
| 429 String get displayName => simpleName; | 432 String get displayName => simpleName; |
| 430 | 433 |
| 431 int get hashCode => qualifiedName.hashCode; | 434 int get hashCode => qualifiedName.hashCode; |
| 432 } | 435 } |
| 433 | 436 |
| 434 //------------------------------------------------------------------------------ | 437 //------------------------------------------------------------------------------ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 489 |
| 487 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) | 490 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) |
| 488 : super(system, library); | 491 : super(system, library); |
| 489 | 492 |
| 490 LibraryElement get _library => _element; | 493 LibraryElement get _library => _element; |
| 491 | 494 |
| 492 Uri get uri => _library.uri; | 495 Uri get uri => _library.uri; |
| 493 | 496 |
| 494 DeclarationMirror get owner => null; | 497 DeclarationMirror get owner => null; |
| 495 | 498 |
| 499 bool get isPrivate => false; |
| 500 |
| 496 LibraryMirror library() => this; | 501 LibraryMirror library() => this; |
| 497 | 502 |
| 498 /** | 503 /** |
| 499 * Returns the library name (for libraries with a #library tag) or the script | 504 * Returns the library name (for libraries with a #library tag) or the script |
| 500 * file name (for scripts without a #library tag). The latter case is used to | 505 * file name (for scripts without a #library tag). The latter case is used to |
| 501 * provide a 'library name' for scripts, to use for instance in dartdoc. | 506 * provide a 'library name' for scripts, to use for instance in dartdoc. |
| 502 */ | 507 */ |
| 503 String get simpleName { | 508 String get simpleName { |
| 504 if (_library.libraryTag !== null) { | 509 if (_library.libraryTag !== null) { |
| 505 // TODO(ahe): Remove StringNode check when old syntax is removed. | 510 // TODO(ahe): Remove StringNode check when old syntax is removed. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } | 765 } |
| 761 return list; | 766 return list; |
| 762 } | 767 } |
| 763 | 768 |
| 764 bool get isClass => !_class.isInterface(); | 769 bool get isClass => !_class.isInterface(); |
| 765 | 770 |
| 766 bool get isInterface => _class.isInterface(); | 771 bool get isInterface => _class.isInterface(); |
| 767 | 772 |
| 768 bool get isAbstract => _class.modifiers.isAbstract(); | 773 bool get isAbstract => _class.modifiers.isAbstract(); |
| 769 | 774 |
| 770 bool get isPrivate => _isPrivate(simpleName); | |
| 771 | |
| 772 bool get isDeclaration => true; | 775 bool get isDeclaration => true; |
| 773 | 776 |
| 774 List<TypeMirror> get typeArguments { | 777 List<TypeMirror> get typeArguments { |
| 775 throw new UnsupportedError( | 778 throw new UnsupportedError( |
| 776 'Declarations do not have type arguments'); | 779 'Declarations do not have type arguments'); |
| 777 } | 780 } |
| 778 | 781 |
| 779 List<TypeVariableMirror> get typeVariables { | 782 List<TypeVariableMirror> get typeVariables { |
| 780 if (_typeVariables == null) { | 783 if (_typeVariables == null) { |
| 781 _typeVariables = <TypeVariableMirror>[]; | 784 _typeVariables = <TypeVariableMirror>[]; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 | 893 |
| 891 // TODO(johnniwinther): How should a typedef respond to these? | 894 // TODO(johnniwinther): How should a typedef respond to these? |
| 892 ClassMirror get superclass => null; | 895 ClassMirror get superclass => null; |
| 893 | 896 |
| 894 List<ClassMirror> get interfaces => const <ClassMirror>[]; | 897 List<ClassMirror> get interfaces => const <ClassMirror>[]; |
| 895 | 898 |
| 896 bool get isClass => false; | 899 bool get isClass => false; |
| 897 | 900 |
| 898 bool get isInterface => false; | 901 bool get isInterface => false; |
| 899 | 902 |
| 900 bool get isPrivate => _isPrivate(simpleName); | |
| 901 | |
| 902 bool get isDeclaration => true; | 903 bool get isDeclaration => true; |
| 903 | 904 |
| 904 bool get isAbstract => false; | 905 bool get isAbstract => false; |
| 905 | 906 |
| 906 Map<String, MethodMirror> get constructors => | 907 Map<String, MethodMirror> get constructors => |
| 907 const <String, MethodMirror>{}; | 908 const <String, MethodMirror>{}; |
| 908 | 909 |
| 909 ClassMirror get defaultType => null; | 910 ClassMirror get defaultType => null; |
| 910 } | 911 } |
| 911 | 912 |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 DeclarationMirror get owner => _objectMirror; | 1382 DeclarationMirror get owner => _objectMirror; |
| 1382 | 1383 |
| 1383 bool get isTopLevel => _objectMirror is LibraryMirror; | 1384 bool get isTopLevel => _objectMirror is LibraryMirror; |
| 1384 | 1385 |
| 1385 bool get isConstructor => false; | 1386 bool get isConstructor => false; |
| 1386 | 1387 |
| 1387 bool get isField => true; | 1388 bool get isField => true; |
| 1388 | 1389 |
| 1389 bool get isMethod => false; | 1390 bool get isMethod => false; |
| 1390 | 1391 |
| 1391 bool get isPrivate => _isPrivate(simpleName); | |
| 1392 | |
| 1393 bool get isStatic => _variable.modifiers.isStatic(); | 1392 bool get isStatic => _variable.modifiers.isStatic(); |
| 1394 | 1393 |
| 1395 bool get isFinal => _variable.modifiers.isFinal(); | 1394 bool get isFinal => _variable.modifiers.isFinal(); |
| 1396 | 1395 |
| 1397 bool get isConst => _variable.modifiers.isConst(); | 1396 bool get isConst => _variable.modifiers.isConst(); |
| 1398 | 1397 |
| 1399 TypeMirror get type => _convertTypeToTypeMirror(system, | 1398 TypeMirror get type => _convertTypeToTypeMirror(system, |
| 1400 _variable.computeType(system.compiler), | 1399 _variable.computeType(system.compiler), |
| 1401 system.compiler.types.dynamicType); | 1400 system.compiler.types.dynamicType); |
| 1402 | 1401 |
| 1403 SourceLocation get location { | 1402 SourceLocation get location { |
| 1404 var script = _variable.getCompilationUnit().script; | 1403 var script = _variable.getCompilationUnit().script; |
| 1405 var node = _variable.variables.parseNode(_diagnosticListener); | 1404 var node = _variable.variables.parseNode(_diagnosticListener); |
| 1406 if (node !== null) { | 1405 if (node !== null) { |
| 1407 var span = system.compiler.spanFromNode(node, script.uri); | 1406 var span = system.compiler.spanFromNode(node, script.uri); |
| 1408 return new Dart2JsLocation(script, span); | 1407 return new Dart2JsLocation(script, span); |
| 1409 } else { | 1408 } else { |
| 1410 var span = system.compiler.spanFromElement(_variable); | 1409 var span = system.compiler.spanFromElement(_variable); |
| 1411 return new Dart2JsLocation(script, span); | 1410 return new Dart2JsLocation(script, span); |
| 1412 } | 1411 } |
| 1413 } | 1412 } |
| 1414 } | 1413 } |
| 1415 | 1414 |
| OLD | NEW |