| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 link = link.tail; | 52 link = link.tail; |
| 53 } | 53 } |
| 54 return parameters; | 54 return parameters; |
| 55 } | 55 } |
| 56 | 56 |
| 57 Dart2JsTypeMirror _convertTypeToTypeMirror( | 57 Dart2JsTypeMirror _convertTypeToTypeMirror( |
| 58 Dart2JsMirrorSystem system, | 58 Dart2JsMirrorSystem system, |
| 59 DartType type, | 59 DartType type, |
| 60 InterfaceType defaultType, | 60 InterfaceType defaultType, |
| 61 [FunctionSignature functionSignature]) { | 61 [FunctionSignature functionSignature]) { |
| 62 if (type === null) { | 62 if (type == null) { |
| 63 return new Dart2JsInterfaceTypeMirror(system, defaultType); | 63 return new Dart2JsInterfaceTypeMirror(system, defaultType); |
| 64 } else if (type is InterfaceType) { | 64 } else if (type is InterfaceType) { |
| 65 if (type === system.compiler.types.dynamicType) { | 65 if (type == system.compiler.types.dynamicType) { |
| 66 return new Dart2JsDynamicMirror(system, type); | 66 return new Dart2JsDynamicMirror(system, type); |
| 67 } else { | 67 } else { |
| 68 return new Dart2JsInterfaceTypeMirror(system, type); | 68 return new Dart2JsInterfaceTypeMirror(system, type); |
| 69 } | 69 } |
| 70 } else if (type is TypeVariableType) { | 70 } else if (type is TypeVariableType) { |
| 71 return new Dart2JsTypeVariableMirror(system, type); | 71 return new Dart2JsTypeVariableMirror(system, type); |
| 72 } else if (type is FunctionType) { | 72 } else if (type is FunctionType) { |
| 73 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); | 73 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); |
| 74 } else if (type is VoidType) { | 74 } else if (type is VoidType) { |
| 75 return new Dart2JsVoidMirror(system, type); | 75 return new Dart2JsVoidMirror(system, type); |
| 76 } else if (type is TypedefType) { | 76 } else if (type is TypedefType) { |
| 77 return new Dart2JsTypedefMirror(system, type); | 77 return new Dart2JsTypedefMirror(system, type); |
| 78 } | 78 } |
| 79 throw new ArgumentError("Unexpected interface type $type"); | 79 throw new ArgumentError("Unexpected interface type $type"); |
| 80 } | 80 } |
| 81 | 81 |
| 82 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( | 82 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( |
| 83 Dart2JsObjectMirror library, Element element) { | 83 Dart2JsObjectMirror library, Element element) { |
| 84 if (element is SynthesizedConstructorElement) { | 84 if (element is SynthesizedConstructorElement) { |
| 85 return const <Dart2JsMemberMirror>[]; | 85 return const <Dart2JsMemberMirror>[]; |
| 86 } else if (element is VariableElement) { | 86 } else if (element is VariableElement) { |
| 87 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; | 87 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; |
| 88 } else if (element is FunctionElement) { | 88 } else if (element is FunctionElement) { |
| 89 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; | 89 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; |
| 90 } else if (element is AbstractFieldElement) { | 90 } else if (element is AbstractFieldElement) { |
| 91 var members = <Dart2JsMemberMirror>[]; | 91 var members = <Dart2JsMemberMirror>[]; |
| 92 if (element.getter !== null) { | 92 if (element.getter != null) { |
| 93 members.add(new Dart2JsMethodMirror(library, element.getter)); | 93 members.add(new Dart2JsMethodMirror(library, element.getter)); |
| 94 } | 94 } |
| 95 if (element.setter !== null) { | 95 if (element.setter != null) { |
| 96 members.add(new Dart2JsMethodMirror(library, element.setter)); | 96 members.add(new Dart2JsMethodMirror(library, element.setter)); |
| 97 } | 97 } |
| 98 return members; | 98 return members; |
| 99 } | 99 } |
| 100 throw new ArgumentError( | 100 throw new ArgumentError( |
| 101 "Unexpected member type $element ${element.kind}"); | 101 "Unexpected member type $element ${element.kind}"); |
| 102 } | 102 } |
| 103 | 103 |
| 104 MethodMirror _convertElementMethodToMethodMirror(Dart2JsObjectMirror library, | 104 MethodMirror _convertElementMethodToMethodMirror(Dart2JsObjectMirror library, |
| 105 Element element) { | 105 Element element) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 'shr': '>>', | 144 'shr': '>>', |
| 145 'ge': '>=', | 145 'ge': '>=', |
| 146 'gt': '>', | 146 'gt': '>', |
| 147 'le': '<=', | 147 'le': '<=', |
| 148 'lt': '<', | 148 'lt': '<', |
| 149 'and': '&', | 149 'and': '&', |
| 150 'xor': '^', | 150 'xor': '^', |
| 151 'or': '|', | 151 'or': '|', |
| 152 }; | 152 }; |
| 153 String newName = mapping[name]; | 153 String newName = mapping[name]; |
| 154 if (newName === null) { | 154 if (newName == null) { |
| 155 throw new Exception('Unhandled operator name: $name'); | 155 throw new Exception('Unhandled operator name: $name'); |
| 156 } | 156 } |
| 157 return newName; | 157 return newName; |
| 158 } | 158 } |
| 159 | 159 |
| 160 DiagnosticListener get _diagnosticListener { | 160 DiagnosticListener get _diagnosticListener { |
| 161 return const Dart2JsDiagnosticListener(); | 161 return const Dart2JsDiagnosticListener(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 class Dart2JsDiagnosticListener implements DiagnosticListener { | 164 class Dart2JsDiagnosticListener implements DiagnosticListener { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 sourceFiles[uri.toString()] = | 311 sourceFiles[uri.toString()] = |
| 312 new SourceFile(relativize(cwd, uri, isWindows), source); | 312 new SourceFile(relativize(cwd, uri, isWindows), source); |
| 313 return new Future.immediate(source); | 313 return new Future.immediate(source); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void handler(Uri uri, int begin, int end, | 316 void handler(Uri uri, int begin, int end, |
| 317 String message, diagnostics.Diagnostic kind) { | 317 String message, diagnostics.Diagnostic kind) { |
| 318 if (isAborting) return; | 318 if (isAborting) return; |
| 319 bool fatal = | 319 bool fatal = |
| 320 kind === diagnostics.Diagnostic.CRASH || | 320 kind == diagnostics.Diagnostic.CRASH || |
| 321 kind === diagnostics.Diagnostic.ERROR; | 321 kind == diagnostics.Diagnostic.ERROR; |
| 322 if (uri === null) { | 322 if (uri == null) { |
| 323 if (!fatal) { | 323 if (!fatal) { |
| 324 return; | 324 return; |
| 325 } | 325 } |
| 326 print(message); | 326 print(message); |
| 327 throw message; | 327 throw message; |
| 328 } else if (fatal) { | 328 } else if (fatal) { |
| 329 SourceFile file = sourceFiles[uri.toString()]; | 329 SourceFile file = sourceFiles[uri.toString()]; |
| 330 print(file.getLocationMessage(message, begin, end, true, (s) => s)); | 330 print(file.getLocationMessage(message, begin, end, true, (s) => s)); |
| 331 throw message; | 331 throw message; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 Dart2JsCompilation(Path script, Path libraryRoot, | 335 Dart2JsCompilation(Path script, Path libraryRoot, |
| 336 [Path packageRoot, List<String> opts = const <String>[]]) | 336 [Path packageRoot, List<String> opts = const <String>[]]) |
| 337 : cwd = getCurrentDirectory(), sourceFiles = <String, SourceFile>{} { | 337 : cwd = getCurrentDirectory(), sourceFiles = <String, SourceFile>{} { |
| 338 var libraryUri = cwd.resolve(libraryRoot.toString()); | 338 var libraryUri = cwd.resolve(libraryRoot.toString()); |
| 339 var packageUri; | 339 var packageUri; |
| 340 if (packageRoot !== null) { | 340 if (packageRoot != null) { |
| 341 packageUri = cwd.resolve(packageRoot.toString()); | 341 packageUri = cwd.resolve(packageRoot.toString()); |
| 342 } else { | 342 } else { |
| 343 packageUri = libraryUri; | 343 packageUri = libraryUri; |
| 344 } | 344 } |
| 345 _compiler = new api.Compiler(provider, handler, | 345 _compiler = new api.Compiler(provider, handler, |
| 346 libraryUri, packageUri, <String>[]); | 346 libraryUri, packageUri, <String>[]); |
| 347 var scriptUri = cwd.resolve(script.toString()); | 347 var scriptUri = cwd.resolve(script.toString()); |
| 348 // TODO(johnniwinther): Detect file not found | 348 // TODO(johnniwinther): Detect file not found |
| 349 _compiler.run(scriptUri); | 349 _compiler.run(scriptUri); |
| 350 } | 350 } |
| 351 | 351 |
| 352 Dart2JsCompilation.library(List<Path> libraries, Path libraryRoot, | 352 Dart2JsCompilation.library(List<Path> libraries, Path libraryRoot, |
| 353 [Path packageRoot, List<String> opts = const <String>[]]) | 353 [Path packageRoot, List<String> opts = const <String>[]]) |
| 354 : cwd = getCurrentDirectory(), sourceFiles = <String, SourceFile>{} { | 354 : cwd = getCurrentDirectory(), sourceFiles = <String, SourceFile>{} { |
| 355 var libraryUri = cwd.resolve(libraryRoot.toString()); | 355 var libraryUri = cwd.resolve(libraryRoot.toString()); |
| 356 var packageUri; | 356 var packageUri; |
| 357 if (packageRoot !== null) { | 357 if (packageRoot != null) { |
| 358 packageUri = cwd.resolve(packageRoot.toString()); | 358 packageUri = cwd.resolve(packageRoot.toString()); |
| 359 } else { | 359 } else { |
| 360 packageUri = libraryUri; | 360 packageUri = libraryUri; |
| 361 } | 361 } |
| 362 _compiler = new LibraryCompiler(provider, handler, | 362 _compiler = new LibraryCompiler(provider, handler, |
| 363 libraryUri, packageUri, <String>[]); | 363 libraryUri, packageUri, <String>[]); |
| 364 var librariesUri = <Uri>[]; | 364 var librariesUri = <Uri>[]; |
| 365 for (Path library in libraries) { | 365 for (Path library in libraries) { |
| 366 librariesUri.add(cwd.resolve(library.toString())); | 366 librariesUri.add(cwd.resolve(library.toString())); |
| 367 // TODO(johnniwinther): Detect file not found | 367 // TODO(johnniwinther): Detect file not found |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 abstract class Dart2JsTypeMirror extends Dart2JsDeclarationMirror | 400 abstract class Dart2JsTypeMirror extends Dart2JsDeclarationMirror |
| 401 implements TypeMirror { | 401 implements TypeMirror { |
| 402 | 402 |
| 403 } | 403 } |
| 404 | 404 |
| 405 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { | 405 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
| 406 final Dart2JsMirrorSystem system; | 406 final Dart2JsMirrorSystem system; |
| 407 final Element _element; | 407 final Element _element; |
| 408 | 408 |
| 409 Dart2JsElementMirror(this.system, this._element) { | 409 Dart2JsElementMirror(this.system, this._element) { |
| 410 assert (system !== null); | 410 assert (system != null); |
| 411 assert (_element !== null); | 411 assert (_element != null); |
| 412 } | 412 } |
| 413 | 413 |
| 414 String get simpleName => _element.name.slowToString(); | 414 String get simpleName => _element.name.slowToString(); |
| 415 | 415 |
| 416 String get displayName => simpleName; | 416 String get displayName => simpleName; |
| 417 | 417 |
| 418 SourceLocation get location => new Dart2JsLocation( | 418 SourceLocation get location => new Dart2JsLocation( |
| 419 _element.getCompilationUnit().script, | 419 _element.getCompilationUnit().script, |
| 420 system.compiler.spanFromElement(_element)); | 420 system.compiler.spanFromElement(_element)); |
| 421 | 421 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 bool get isPrivate => false; | 499 bool get isPrivate => false; |
| 500 | 500 |
| 501 LibraryMirror library() => this; | 501 LibraryMirror library() => this; |
| 502 | 502 |
| 503 /** | 503 /** |
| 504 * 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 |
| 505 * 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 |
| 506 * 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. |
| 507 */ | 507 */ |
| 508 String get simpleName { | 508 String get simpleName { |
| 509 if (_library.libraryTag !== null) { | 509 if (_library.libraryTag != null) { |
| 510 // TODO(ahe): Remove StringNode check when old syntax is removed. | 510 // TODO(ahe): Remove StringNode check when old syntax is removed. |
| 511 StringNode name = _library.libraryTag.name.asStringNode(); | 511 StringNode name = _library.libraryTag.name.asStringNode(); |
| 512 if (name !== null) { | 512 if (name != null) { |
| 513 return name.dartString.slowToString(); | 513 return name.dartString.slowToString(); |
| 514 } else { | 514 } else { |
| 515 return _library.libraryTag.name.toString(); | 515 return _library.libraryTag.name.toString(); |
| 516 } | 516 } |
| 517 } else { | 517 } else { |
| 518 // Use the file name as script name. | 518 // Use the file name as script name. |
| 519 String path = _library.uri.path; | 519 String path = _library.uri.path; |
| 520 return path.substring(path.lastIndexOf('/') + 1); | 520 return path.substring(path.lastIndexOf('/') + 1); |
| 521 } | 521 } |
| 522 } | 522 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 _variableElement.variables.functionSignature); | 658 _variableElement.variables.functionSignature); |
| 659 | 659 |
| 660 String get defaultValue { | 660 String get defaultValue { |
| 661 if (hasDefaultValue) { | 661 if (hasDefaultValue) { |
| 662 SendSet expression = _variableElement.cachedNode.asSendSet(); | 662 SendSet expression = _variableElement.cachedNode.asSendSet(); |
| 663 return unparse(expression.arguments.head); | 663 return unparse(expression.arguments.head); |
| 664 } | 664 } |
| 665 return null; | 665 return null; |
| 666 } | 666 } |
| 667 bool get hasDefaultValue { | 667 bool get hasDefaultValue { |
| 668 return _variableElement.cachedNode !== null && | 668 return _variableElement.cachedNode != null && |
| 669 _variableElement.cachedNode is SendSet; | 669 _variableElement.cachedNode is SendSet; |
| 670 } | 670 } |
| 671 | 671 |
| 672 bool get isInitializingFormal => false; | 672 bool get isInitializingFormal => false; |
| 673 | 673 |
| 674 FieldMirror get initializedField => null; | 674 FieldMirror get initializedField => null; |
| 675 } | 675 } |
| 676 | 676 |
| 677 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { | 677 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { |
| 678 | 678 |
| 679 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, | 679 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, |
| 680 MethodMirror method, | 680 MethodMirror method, |
| 681 FieldParameterElement element, | 681 FieldParameterElement element, |
| 682 bool isOptional) | 682 bool isOptional) |
| 683 : super._normal(system, method, element, isOptional); | 683 : super._normal(system, method, element, isOptional); |
| 684 | 684 |
| 685 FieldParameterElement get _fieldParameterElement => _element; | 685 FieldParameterElement get _fieldParameterElement => _element; |
| 686 | 686 |
| 687 TypeMirror get type { | 687 TypeMirror get type { |
| 688 if (_fieldParameterElement.variables.cachedNode.type !== null) { | 688 if (_fieldParameterElement.variables.cachedNode.type != null) { |
| 689 return super.type; | 689 return super.type; |
| 690 } | 690 } |
| 691 return _convertTypeToTypeMirror(system, | 691 return _convertTypeToTypeMirror(system, |
| 692 _fieldParameterElement.fieldElement.computeType(system.compiler), | 692 _fieldParameterElement.fieldElement.computeType(system.compiler), |
| 693 system.compiler.types.dynamicType, | 693 system.compiler.types.dynamicType, |
| 694 _variableElement.variables.functionSignature); | 694 _variableElement.variables.functionSignature); |
| 695 } | 695 } |
| 696 | 696 |
| 697 bool get isInitializingFormal => true; | 697 bool get isInitializingFormal => true; |
| 698 | 698 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 720 : this.library = library, | 720 : this.library = library, |
| 721 super(library.system, _class); | 721 super(library.system, _class); |
| 722 | 722 |
| 723 DeclarationMirror get owner => library; | 723 DeclarationMirror get owner => library; |
| 724 | 724 |
| 725 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; | 725 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
| 726 | 726 |
| 727 SourceLocation get location { | 727 SourceLocation get location { |
| 728 if (_class is PartialClassElement) { | 728 if (_class is PartialClassElement) { |
| 729 var node = _class.parseNode(system.compiler); | 729 var node = _class.parseNode(system.compiler); |
| 730 if (node !== null) { | 730 if (node != null) { |
| 731 var script = _class.getCompilationUnit().script; | 731 var script = _class.getCompilationUnit().script; |
| 732 var span = system.compiler.spanFromNode(node, script.uri); | 732 var span = system.compiler.spanFromNode(node, script.uri); |
| 733 return new Dart2JsLocation(script, span); | 733 return new Dart2JsLocation(script, span); |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 return super.location; | 736 return super.location; |
| 737 } | 737 } |
| 738 | 738 |
| 739 void _ensureMembers() { | 739 void _ensureMembers() { |
| 740 if (_members == null) { | 740 if (_members == null) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 * Returns the default type for this interface. | 841 * Returns the default type for this interface. |
| 842 */ | 842 */ |
| 843 ClassMirror get defaultFactory { | 843 ClassMirror get defaultFactory { |
| 844 if (_class.defaultClass != null) { | 844 if (_class.defaultClass != null) { |
| 845 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); | 845 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); |
| 846 } | 846 } |
| 847 return null; | 847 return null; |
| 848 } | 848 } |
| 849 | 849 |
| 850 bool operator ==(Object other) { | 850 bool operator ==(Object other) { |
| 851 if (this === other) { | 851 if (identical(this, other)) { |
| 852 return true; | 852 return true; |
| 853 } | 853 } |
| 854 if (other is! ClassMirror) { | 854 if (other is! ClassMirror) { |
| 855 return false; | 855 return false; |
| 856 } | 856 } |
| 857 if (library != other.library) { | 857 if (library != other.library) { |
| 858 return false; | 858 return false; |
| 859 } | 859 } |
| 860 if (isOriginalDeclaration !== other.isOriginalDeclaration) { | 860 if (!identical(isOriginalDeclaration, other.isOriginalDeclaration)) { |
| 861 return false; | 861 return false; |
| 862 } | 862 } |
| 863 return qualifiedName == other.qualifiedName; | 863 return qualifiedName == other.qualifiedName; |
| 864 } | 864 } |
| 865 } | 865 } |
| 866 | 866 |
| 867 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror | 867 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror |
| 868 implements Dart2JsTypeMirror, TypedefMirror { | 868 implements Dart2JsTypeMirror, TypedefMirror { |
| 869 final Dart2JsLibraryMirror _library; | 869 final Dart2JsLibraryMirror _library; |
| 870 List<TypeVariableMirror> _typeVariables; | 870 List<TypeVariableMirror> _typeVariables; |
| 871 TypeMirror _definition; | 871 TypeMirror _definition; |
| 872 | 872 |
| 873 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) | 873 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) |
| 874 : this._library = system.getLibrary(_typedef.element.getLibrary()), | 874 : this._library = system.getLibrary(_typedef.element.getLibrary()), |
| 875 super(system, _typedef); | 875 super(system, _typedef); |
| 876 | 876 |
| 877 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, | 877 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, |
| 878 TypedefType _typedef) | 878 TypedefType _typedef) |
| 879 : this._library = library, | 879 : this._library = library, |
| 880 super(library.system, _typedef); | 880 super(library.system, _typedef); |
| 881 | 881 |
| 882 TypedefType get _typedef => _type; | 882 TypedefType get _typedef => _type; |
| 883 | 883 |
| 884 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; | 884 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
| 885 | 885 |
| 886 SourceLocation get location { | 886 SourceLocation get location { |
| 887 var node = _typedef.element.parseNode(_diagnosticListener); | 887 var node = _typedef.element.parseNode(_diagnosticListener); |
| 888 if (node !== null) { | 888 if (node != null) { |
| 889 var script = _typedef.element.getCompilationUnit().script; | 889 var script = _typedef.element.getCompilationUnit().script; |
| 890 var span = system.compiler.spanFromNode(node, script.uri); | 890 var span = system.compiler.spanFromNode(node, script.uri); |
| 891 return new Dart2JsLocation(script, span); | 891 return new Dart2JsLocation(script, span); |
| 892 } | 892 } |
| 893 return super.location; | 893 return super.location; |
| 894 } | 894 } |
| 895 | 895 |
| 896 LibraryMirror get library => _library; | 896 LibraryMirror get library => _library; |
| 897 | 897 |
| 898 bool get isTypedef => true; | 898 bool get isTypedef => true; |
| 899 | 899 |
| 900 List<TypeMirror> get typeArguments { | 900 List<TypeMirror> get typeArguments { |
| 901 throw new UnsupportedError( | 901 throw new UnsupportedError( |
| 902 'Declarations do not have type arguments'); | 902 'Declarations do not have type arguments'); |
| 903 } | 903 } |
| 904 | 904 |
| 905 List<TypeVariableMirror> get typeVariables { | 905 List<TypeVariableMirror> get typeVariables { |
| 906 if (_typeVariables == null) { | 906 if (_typeVariables == null) { |
| 907 _typeVariables = <TypeVariableMirror>[]; | 907 _typeVariables = <TypeVariableMirror>[]; |
| 908 for (TypeVariableType typeVariable in _typedef.typeArguments) { | 908 for (TypeVariableType typeVariable in _typedef.typeArguments) { |
| 909 _typeVariables.add( | 909 _typeVariables.add( |
| 910 new Dart2JsTypeVariableMirror(system, typeVariable)); | 910 new Dart2JsTypeVariableMirror(system, typeVariable)); |
| 911 } | 911 } |
| 912 } | 912 } |
| 913 return _typeVariables; | 913 return _typeVariables; |
| 914 } | 914 } |
| 915 | 915 |
| 916 TypeMirror get definition { | 916 TypeMirror get definition { |
| 917 if (_definition === null) { | 917 if (_definition == null) { |
| 918 // TODO(johnniwinther): Should be [ensureResolved]. | 918 // TODO(johnniwinther): Should be [ensureResolved]. |
| 919 system.compiler.resolveTypedef(_typedef.element); | 919 system.compiler.resolveTypedef(_typedef.element); |
| 920 _definition = _convertTypeToTypeMirror( | 920 _definition = _convertTypeToTypeMirror( |
| 921 system, | 921 system, |
| 922 _typedef.element.alias, | 922 _typedef.element.alias, |
| 923 system.compiler.types.dynamicType, | 923 system.compiler.types.dynamicType, |
| 924 _typedef.element.functionSignature); | 924 _typedef.element.functionSignature); |
| 925 } | 925 } |
| 926 return _definition; | 926 return _definition; |
| 927 } | 927 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 944 | 944 |
| 945 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror | 945 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror |
| 946 implements TypeVariableMirror { | 946 implements TypeVariableMirror { |
| 947 final TypeVariableType _typeVariableType; | 947 final TypeVariableType _typeVariableType; |
| 948 ClassMirror _declarer; | 948 ClassMirror _declarer; |
| 949 | 949 |
| 950 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, | 950 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, |
| 951 TypeVariableType typeVariableType) | 951 TypeVariableType typeVariableType) |
| 952 : this._typeVariableType = typeVariableType, | 952 : this._typeVariableType = typeVariableType, |
| 953 super(system, typeVariableType) { | 953 super(system, typeVariableType) { |
| 954 assert(_typeVariableType !== null); | 954 assert(_typeVariableType != null); |
| 955 } | 955 } |
| 956 | 956 |
| 957 | 957 |
| 958 String get qualifiedName => '${declarer.qualifiedName}.${simpleName}'; | 958 String get qualifiedName => '${declarer.qualifiedName}.${simpleName}'; |
| 959 | 959 |
| 960 ClassMirror get declarer { | 960 ClassMirror get declarer { |
| 961 if (_declarer === null) { | 961 if (_declarer == null) { |
| 962 if (_typeVariableType.element.enclosingElement.isClass()) { | 962 if (_typeVariableType.element.enclosingElement.isClass()) { |
| 963 _declarer = new Dart2JsClassMirror(system, | 963 _declarer = new Dart2JsClassMirror(system, |
| 964 _typeVariableType.element.enclosingElement); | 964 _typeVariableType.element.enclosingElement); |
| 965 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { | 965 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { |
| 966 _declarer = new Dart2JsTypedefMirror(system, | 966 _declarer = new Dart2JsTypedefMirror(system, |
| 967 _typeVariableType.element.enclosingElement.computeType( | 967 _typeVariableType.element.enclosingElement.computeType( |
| 968 system.compiler)); | 968 system.compiler)); |
| 969 } | 969 } |
| 970 } | 970 } |
| 971 return _declarer; | 971 return _declarer; |
| 972 } | 972 } |
| 973 | 973 |
| 974 LibraryMirror get library => declarer.library; | 974 LibraryMirror get library => declarer.library; |
| 975 | 975 |
| 976 bool get isTypeVariable => true; | 976 bool get isTypeVariable => true; |
| 977 | 977 |
| 978 TypeMirror get bound => _convertTypeToTypeMirror( | 978 TypeMirror get bound => _convertTypeToTypeMirror( |
| 979 system, | 979 system, |
| 980 _typeVariableType.element.bound, | 980 _typeVariableType.element.bound, |
| 981 system.compiler.objectClass.computeType(system.compiler)); | 981 system.compiler.objectClass.computeType(system.compiler)); |
| 982 | 982 |
| 983 bool operator ==(Object other) { | 983 bool operator ==(Object other) { |
| 984 if (this === other) { | 984 if (identical(this, other)) { |
| 985 return true; | 985 return true; |
| 986 } | 986 } |
| 987 if (other is! TypeVariableMirror) { | 987 if (other is! TypeVariableMirror) { |
| 988 return false; | 988 return false; |
| 989 } | 989 } |
| 990 if (declarer != other.declarer) { | 990 if (declarer != other.declarer) { |
| 991 return false; | 991 return false; |
| 992 } | 992 } |
| 993 return qualifiedName == other.qualifiedName; | 993 return qualifiedName == other.qualifiedName; |
| 994 } | 994 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // TODO(johnniwinther): Substitute type arguments for type variables. | 1118 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1119 Map<String, MethodMirror> get setters => originalDeclaration.setters; | 1119 Map<String, MethodMirror> get setters => originalDeclaration.setters; |
| 1120 | 1120 |
| 1121 // TODO(johnniwinther): Substitute type arguments for type variables. | 1121 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1122 Map<String, MethodMirror> get getters => originalDeclaration.getters; | 1122 Map<String, MethodMirror> get getters => originalDeclaration.getters; |
| 1123 | 1123 |
| 1124 // TODO(johnniwinther): Substitute type arguments for type variables? | 1124 // TODO(johnniwinther): Substitute type arguments for type variables? |
| 1125 ClassMirror get defaultFactory => originalDeclaration.defaultFactory; | 1125 ClassMirror get defaultFactory => originalDeclaration.defaultFactory; |
| 1126 | 1126 |
| 1127 bool operator ==(Object other) { | 1127 bool operator ==(Object other) { |
| 1128 if (this === other) { | 1128 if (identical(this, other)) { |
| 1129 return true; | 1129 return true; |
| 1130 } | 1130 } |
| 1131 if (other is! ClassMirror) { | 1131 if (other is! ClassMirror) { |
| 1132 return false; | 1132 return false; |
| 1133 } | 1133 } |
| 1134 if (other.isOriginalDeclaration) { | 1134 if (other.isOriginalDeclaration) { |
| 1135 return false; | 1135 return false; |
| 1136 } | 1136 } |
| 1137 if (originalDeclaration != other.originalDeclaration) { | 1137 if (originalDeclaration != other.originalDeclaration) { |
| 1138 return false; | 1138 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1150 | 1150 |
| 1151 | 1151 |
| 1152 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror | 1152 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror |
| 1153 implements FunctionTypeMirror { | 1153 implements FunctionTypeMirror { |
| 1154 final FunctionSignature _functionSignature; | 1154 final FunctionSignature _functionSignature; |
| 1155 List<ParameterMirror> _parameters; | 1155 List<ParameterMirror> _parameters; |
| 1156 | 1156 |
| 1157 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, | 1157 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, |
| 1158 FunctionType functionType, this._functionSignature) | 1158 FunctionType functionType, this._functionSignature) |
| 1159 : super(system, functionType) { | 1159 : super(system, functionType) { |
| 1160 assert (_functionSignature !== null); | 1160 assert (_functionSignature != null); |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 FunctionType get _functionType => _type; | 1163 FunctionType get _functionType => _type; |
| 1164 | 1164 |
| 1165 // TODO(johnniwinther): Is this the qualified name of a function type? | 1165 // TODO(johnniwinther): Is this the qualified name of a function type? |
| 1166 String get qualifiedName => originalDeclaration.qualifiedName; | 1166 String get qualifiedName => originalDeclaration.qualifiedName; |
| 1167 | 1167 |
| 1168 // TODO(johnniwinther): Substitute type arguments for type variables. | 1168 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1169 Map<String, MemberMirror> get declaredMembers { | 1169 Map<String, MemberMirror> get declaredMembers { |
| 1170 var method = callMethod; | 1170 var method = callMethod; |
| 1171 if (method !== null) { | 1171 if (method != null) { |
| 1172 var map = new Map<String, MemberMirror>.from( | 1172 var map = new Map<String, MemberMirror>.from( |
| 1173 originalDeclaration.declaredMembers); | 1173 originalDeclaration.declaredMembers); |
| 1174 var name = method.qualifiedName; | 1174 var name = method.qualifiedName; |
| 1175 assert(!map.containsKey(name)); | 1175 assert(!map.containsKey(name)); |
| 1176 map[name] = method; | 1176 map[name] = method; |
| 1177 return new ImmutableMapWrapper<String, MemberMirror>(map); | 1177 return new ImmutableMapWrapper<String, MemberMirror>(map); |
| 1178 } | 1178 } |
| 1179 return originalDeclaration.declaredMembers; | 1179 return originalDeclaration.declaredMembers; |
| 1180 } | 1180 } |
| 1181 | 1181 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1208 | 1208 |
| 1209 List<TypeVariableMirror> get typeVariables => | 1209 List<TypeVariableMirror> get typeVariables => |
| 1210 originalDeclaration.typeVariables; | 1210 originalDeclaration.typeVariables; |
| 1211 | 1211 |
| 1212 TypeMirror get returnType { | 1212 TypeMirror get returnType { |
| 1213 return _convertTypeToTypeMirror(system, _functionType.returnType, | 1213 return _convertTypeToTypeMirror(system, _functionType.returnType, |
| 1214 system.compiler.types.dynamicType); | 1214 system.compiler.types.dynamicType); |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 List<ParameterMirror> get parameters { | 1217 List<ParameterMirror> get parameters { |
| 1218 if (_parameters === null) { | 1218 if (_parameters == null) { |
| 1219 _parameters = _parametersFromFunctionSignature(system, callMethod, | 1219 _parameters = _parametersFromFunctionSignature(system, callMethod, |
| 1220 _functionSignature); | 1220 _functionSignature); |
| 1221 } | 1221 } |
| 1222 return _parameters; | 1222 return _parameters; |
| 1223 } | 1223 } |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 class Dart2JsVoidMirror extends Dart2JsTypeElementMirror { | 1226 class Dart2JsVoidMirror extends Dart2JsTypeElementMirror { |
| 1227 | 1227 |
| 1228 Dart2JsVoidMirror(Dart2JsMirrorSystem system, VoidType voidType) | 1228 Dart2JsVoidMirror(Dart2JsMirrorSystem system, VoidType voidType) |
| 1229 : super(system, voidType); | 1229 : super(system, voidType); |
| 1230 | 1230 |
| 1231 VoidType get _voidType => _type; | 1231 VoidType get _voidType => _type; |
| 1232 | 1232 |
| 1233 String get qualifiedName => simpleName; | 1233 String get qualifiedName => simpleName; |
| 1234 | 1234 |
| 1235 /** | 1235 /** |
| 1236 * The void type has no location. | 1236 * The void type has no location. |
| 1237 */ | 1237 */ |
| 1238 SourceLocation get location => null; | 1238 SourceLocation get location => null; |
| 1239 | 1239 |
| 1240 /** | 1240 /** |
| 1241 * The void type has no library. | 1241 * The void type has no library. |
| 1242 */ | 1242 */ |
| 1243 LibraryMirror get library => null; | 1243 LibraryMirror get library => null; |
| 1244 | 1244 |
| 1245 bool get isVoid => true; | 1245 bool get isVoid => true; |
| 1246 | 1246 |
| 1247 bool operator ==(Object other) { | 1247 bool operator ==(Object other) { |
| 1248 if (this === other) { | 1248 if (identical(this, other)) { |
| 1249 return true; | 1249 return true; |
| 1250 } | 1250 } |
| 1251 if (other is! TypeMirror) { | 1251 if (other is! TypeMirror) { |
| 1252 return false; | 1252 return false; |
| 1253 } | 1253 } |
| 1254 return other.isVoid; | 1254 return other.isVoid; |
| 1255 } | 1255 } |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 | 1258 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1270 SourceLocation get location => null; | 1270 SourceLocation get location => null; |
| 1271 | 1271 |
| 1272 /** | 1272 /** |
| 1273 * The dynamic type has no library. | 1273 * The dynamic type has no library. |
| 1274 */ | 1274 */ |
| 1275 LibraryMirror get library => null; | 1275 LibraryMirror get library => null; |
| 1276 | 1276 |
| 1277 bool get isDynamic => true; | 1277 bool get isDynamic => true; |
| 1278 | 1278 |
| 1279 bool operator ==(Object other) { | 1279 bool operator ==(Object other) { |
| 1280 if (this === other) { | 1280 if (identical(this, other)) { |
| 1281 return true; | 1281 return true; |
| 1282 } | 1282 } |
| 1283 if (other is! TypeMirror) { | 1283 if (other is! TypeMirror) { |
| 1284 return false; | 1284 return false; |
| 1285 } | 1285 } |
| 1286 return other.isDynamic; | 1286 return other.isDynamic; |
| 1287 } | 1287 } |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 //------------------------------------------------------------------------------ | 1290 //------------------------------------------------------------------------------ |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; | 1407 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; |
| 1408 | 1408 |
| 1409 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; | 1409 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; |
| 1410 | 1410 |
| 1411 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; | 1411 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; |
| 1412 | 1412 |
| 1413 String get operatorName => _operatorName; | 1413 String get operatorName => _operatorName; |
| 1414 | 1414 |
| 1415 SourceLocation get location { | 1415 SourceLocation get location { |
| 1416 var node = _function.parseNode(_diagnosticListener); | 1416 var node = _function.parseNode(_diagnosticListener); |
| 1417 if (node !== null) { | 1417 if (node != null) { |
| 1418 var script = _function.getCompilationUnit().script; | 1418 var script = _function.getCompilationUnit().script; |
| 1419 var span = system.compiler.spanFromNode(node, script.uri); | 1419 var span = system.compiler.spanFromNode(node, script.uri); |
| 1420 return new Dart2JsLocation(script, span); | 1420 return new Dart2JsLocation(script, span); |
| 1421 } | 1421 } |
| 1422 return super.location; | 1422 return super.location; |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 class Dart2JsFieldMirror extends Dart2JsElementMirror | 1427 class Dart2JsFieldMirror extends Dart2JsElementMirror |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1454 | 1454 |
| 1455 bool get isConst => _variable.modifiers.isConst(); | 1455 bool get isConst => _variable.modifiers.isConst(); |
| 1456 | 1456 |
| 1457 TypeMirror get type => _convertTypeToTypeMirror(system, | 1457 TypeMirror get type => _convertTypeToTypeMirror(system, |
| 1458 _variable.computeType(system.compiler), | 1458 _variable.computeType(system.compiler), |
| 1459 system.compiler.types.dynamicType); | 1459 system.compiler.types.dynamicType); |
| 1460 | 1460 |
| 1461 SourceLocation get location { | 1461 SourceLocation get location { |
| 1462 var script = _variable.getCompilationUnit().script; | 1462 var script = _variable.getCompilationUnit().script; |
| 1463 var node = _variable.variables.parseNode(_diagnosticListener); | 1463 var node = _variable.variables.parseNode(_diagnosticListener); |
| 1464 if (node !== null) { | 1464 if (node != null) { |
| 1465 var span = system.compiler.spanFromNode(node, script.uri); | 1465 var span = system.compiler.spanFromNode(node, script.uri); |
| 1466 return new Dart2JsLocation(script, span); | 1466 return new Dart2JsLocation(script, span); |
| 1467 } else { | 1467 } else { |
| 1468 var span = system.compiler.spanFromElement(_variable); | 1468 var span = system.compiler.spanFromElement(_variable); |
| 1469 return new Dart2JsLocation(script, span); | 1469 return new Dart2JsLocation(script, span); |
| 1470 } | 1470 } |
| 1471 } | 1471 } |
| 1472 } | 1472 } |
| 1473 | 1473 |
| OLD | NEW |