| 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('../../compiler/compiler.dart', prefix: 'diagnostics'); | 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics'); |
| 8 #import('../../compiler/implementation/elements/elements.dart'); | 8 #import('../../compiler/implementation/elements/elements.dart'); |
| 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); | 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); |
| 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); | 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 Type type, | 54 Type type, |
| 55 InterfaceType defaultType, | 55 InterfaceType defaultType, |
| 56 [FunctionSignature functionSignature]) { | 56 [FunctionSignature functionSignature]) { |
| 57 if (type === null) { | 57 if (type === null) { |
| 58 return new Dart2JsInterfaceTypeMirror(system, defaultType); | 58 return new Dart2JsInterfaceTypeMirror(system, defaultType); |
| 59 } else if (type is InterfaceType) { | 59 } else if (type is InterfaceType) { |
| 60 return new Dart2JsInterfaceTypeMirror(system, type); | 60 return new Dart2JsInterfaceTypeMirror(system, type); |
| 61 } else if (type is TypeVariableType) { | 61 } else if (type is TypeVariableType) { |
| 62 return new Dart2JsTypeVariableMirror(system, type); | 62 return new Dart2JsTypeVariableMirror(system, type); |
| 63 } else if (type is FunctionType) { | 63 } else if (type is FunctionType) { |
| 64 if (type.element is TypedefElement) { | 64 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); |
| 65 return new Dart2JsTypedefMirror(system, type.element); | |
| 66 } else { | |
| 67 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); | |
| 68 } | |
| 69 } else if (type is VoidType) { | 65 } else if (type is VoidType) { |
| 70 return new Dart2JsVoidMirror(system, type); | 66 return new Dart2JsVoidMirror(system, type); |
| 67 } else if (type is TypedefType) { |
| 68 return new Dart2JsTypedefMirror(system, type); |
| 71 } | 69 } |
| 72 throw new IllegalArgumentException("Unexpected interface type $type"); | 70 throw new IllegalArgumentException("Unexpected interface type $type"); |
| 73 } | 71 } |
| 74 | 72 |
| 75 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( | 73 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( |
| 76 Dart2JsObjectMirror library, Element element) { | 74 Dart2JsObjectMirror library, Element element) { |
| 77 if (element is SynthesizedConstructorElement) { | 75 if (element is SynthesizedConstructorElement) { |
| 78 return const <Dart2JsMemberMirror>[]; | 76 return const <Dart2JsMemberMirror>[]; |
| 79 } else if (element is VariableElement) { | 77 } else if (element is VariableElement) { |
| 80 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; | 78 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 493 |
| 496 void _ensureTypes() { | 494 void _ensureTypes() { |
| 497 if (_types == null) { | 495 if (_types == null) { |
| 498 _types = <InterfaceMirror>{}; | 496 _types = <InterfaceMirror>{}; |
| 499 _library.forEachExport((Element e) { | 497 _library.forEachExport((Element e) { |
| 500 if (e.getLibrary() == _library) { | 498 if (e.getLibrary() == _library) { |
| 501 if (e.isClass()) { | 499 if (e.isClass()) { |
| 502 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); | 500 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); |
| 503 _types[type.canonicalName] = type; | 501 _types[type.canonicalName] = type; |
| 504 } else if (e.isTypedef()) { | 502 } else if (e.isTypedef()) { |
| 505 var type = new Dart2JsTypedefMirror.fromLibrary(this, e); | 503 var type = new Dart2JsTypedefMirror.fromLibrary(this, |
| 504 e.computeType(system.compiler)); |
| 506 _types[type.canonicalName] = type; | 505 _types[type.canonicalName] = type; |
| 507 } | 506 } |
| 508 } | 507 } |
| 509 }); | 508 }); |
| 510 } | 509 } |
| 511 } | 510 } |
| 512 | 511 |
| 513 void _ensureMembers() { | 512 void _ensureMembers() { |
| 514 if (_members == null) { | 513 if (_members == null) { |
| 515 _members = <MemberMirror>{}; | 514 _members = <MemberMirror>{}; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 bool get isDeclaration() => true; | 745 bool get isDeclaration() => true; |
| 747 | 746 |
| 748 List<TypeMirror> typeArguments() { | 747 List<TypeMirror> typeArguments() { |
| 749 throw new UnsupportedOperationException( | 748 throw new UnsupportedOperationException( |
| 750 'Declarations do not have type arguments'); | 749 'Declarations do not have type arguments'); |
| 751 } | 750 } |
| 752 | 751 |
| 753 List<TypeVariableMirror> typeVariables() { | 752 List<TypeVariableMirror> typeVariables() { |
| 754 if (_typeVariables == null) { | 753 if (_typeVariables == null) { |
| 755 _typeVariables = <TypeVariableMirror>[]; | 754 _typeVariables = <TypeVariableMirror>[]; |
| 756 _class.typeParameters.forEach((_,parameter) { | 755 for (TypeVariableType typeVariable in _class.typeVariables) { |
| 757 _typeVariables.add( | 756 _typeVariables.add( |
| 758 new Dart2JsTypeVariableMirror(system, | 757 new Dart2JsTypeVariableMirror(system, typeVariable)); |
| 759 parameter.computeType(system.compiler))); | 758 } |
| 760 }); | |
| 761 } | 759 } |
| 762 return _typeVariables; | 760 return _typeVariables; |
| 763 } | 761 } |
| 764 | 762 |
| 765 Map<Object, MethodMirror> constructors() { | 763 Map<Object, MethodMirror> constructors() { |
| 766 _ensureMembers(); | 764 _ensureMembers(); |
| 767 return new AsFilteredImmutableMap<Object, MemberMirror, MethodMirror>( | 765 return new AsFilteredImmutableMap<Object, MemberMirror, MethodMirror>( |
| 768 _members, (m) => m.isConstructor ? m : null); | 766 _members, (m) => m.isConstructor ? m : null); |
| 769 } | 767 } |
| 770 | 768 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 788 if (library() != other.library()) { | 786 if (library() != other.library()) { |
| 789 return false; | 787 return false; |
| 790 } | 788 } |
| 791 if (isDeclaration !== other.isDeclaration) { | 789 if (isDeclaration !== other.isDeclaration) { |
| 792 return false; | 790 return false; |
| 793 } | 791 } |
| 794 return qualifiedName() == other.qualifiedName(); | 792 return qualifiedName() == other.qualifiedName(); |
| 795 } | 793 } |
| 796 } | 794 } |
| 797 | 795 |
| 798 class Dart2JsTypedefMirror extends Dart2JsElementMirror | 796 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror |
| 799 implements Dart2JsTypeMirror, TypedefMirror { | 797 implements Dart2JsTypeMirror, TypedefMirror { |
| 800 final Dart2JsLibraryMirror _library; | 798 final Dart2JsLibraryMirror _library; |
| 801 List<TypeVariableMirror> _typeVariables; | 799 List<TypeVariableMirror> _typeVariables; |
| 802 TypeMirror _definition; | 800 TypeMirror _definition; |
| 803 | 801 |
| 804 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefElement _typedef) | 802 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) |
| 805 : this._library = system.getLibrary(_typedef.getLibrary()), | 803 : this._library = system.getLibrary(_typedef.element.getLibrary()), |
| 806 super(system, _typedef); | 804 super(system, _typedef); |
| 807 | 805 |
| 808 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, | 806 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, |
| 809 TypedefElement _typedef) | 807 TypedefType _typedef) |
| 810 : this._library = library, | 808 : this._library = library, |
| 811 super(library.system, _typedef); | 809 super(library.system, _typedef); |
| 812 | 810 |
| 813 TypedefElement get _typedef() => _element; | 811 TypedefType get _typedef() => _type; |
| 814 | 812 |
| 815 String get canonicalName() => simpleName(); | 813 String get canonicalName() => simpleName(); |
| 816 | 814 |
| 817 String qualifiedName() => '${library().qualifiedName()}.${simpleName()}'; | 815 String qualifiedName() => '${library().qualifiedName()}.${simpleName()}'; |
| 818 | 816 |
| 819 Location location() { | 817 Location location() { |
| 820 var node = _typedef.parseNode(_diagnosticListener); | 818 var node = _typedef.element.parseNode(_diagnosticListener); |
| 821 if (node !== null) { | 819 if (node !== null) { |
| 822 var script = _typedef.getCompilationUnit().script; | 820 var script = _typedef.element.getCompilationUnit().script; |
| 823 var span = system.compiler.spanFromNode(node, script.uri); | 821 var span = system.compiler.spanFromNode(node, script.uri); |
| 824 return new Dart2JsLocation(script, span); | 822 return new Dart2JsLocation(script, span); |
| 825 } | 823 } |
| 826 return super.location(); | 824 return super.location(); |
| 827 } | 825 } |
| 828 | 826 |
| 829 LibraryMirror library() => _library; | 827 LibraryMirror library() => _library; |
| 830 | 828 |
| 831 bool get isObject() => false; | 829 bool get isObject() => false; |
| 832 | 830 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 897 |
| 900 String qualifiedName() => '${declarer().qualifiedName()}.${simpleName()}'; | 898 String qualifiedName() => '${declarer().qualifiedName()}.${simpleName()}'; |
| 901 | 899 |
| 902 InterfaceMirror declarer() { | 900 InterfaceMirror declarer() { |
| 903 if (_declarer === null) { | 901 if (_declarer === null) { |
| 904 if (_typeVariableType.element.enclosingElement.isClass()) { | 902 if (_typeVariableType.element.enclosingElement.isClass()) { |
| 905 _declarer = new Dart2JsInterfaceMirror(system, | 903 _declarer = new Dart2JsInterfaceMirror(system, |
| 906 _typeVariableType.element.enclosingElement); | 904 _typeVariableType.element.enclosingElement); |
| 907 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { | 905 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { |
| 908 _declarer = new Dart2JsTypedefMirror(system, | 906 _declarer = new Dart2JsTypedefMirror(system, |
| 909 _typeVariableType.element.enclosingElement); | 907 _typeVariableType.element.enclosingElement.computeType( |
| 908 system.compiler)); |
| 910 } | 909 } |
| 911 } | 910 } |
| 912 return _declarer; | 911 return _declarer; |
| 913 } | 912 } |
| 914 | 913 |
| 915 LibraryMirror library() => declarer().library(); | 914 LibraryMirror library() => declarer().library(); |
| 916 | 915 |
| 917 bool get isObject() => false; | 916 bool get isObject() => false; |
| 918 | 917 |
| 919 bool get isDynamic() => false; | 918 bool get isDynamic() => false; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 | 1013 |
| 1015 bool get isInterface() => declaration.isInterface; | 1014 bool get isInterface() => declaration.isInterface; |
| 1016 | 1015 |
| 1017 bool get isPrivate() => declaration.isPrivate; | 1016 bool get isPrivate() => declaration.isPrivate; |
| 1018 | 1017 |
| 1019 bool get isDeclaration() => false; | 1018 bool get isDeclaration() => false; |
| 1020 | 1019 |
| 1021 List<TypeMirror> typeArguments() { | 1020 List<TypeMirror> typeArguments() { |
| 1022 if (_typeArguments == null) { | 1021 if (_typeArguments == null) { |
| 1023 _typeArguments = <TypeMirror>[]; | 1022 _typeArguments = <TypeMirror>[]; |
| 1024 Link<Type> type = _interfaceType.arguments; | 1023 Link<Type> type = _interfaceType.typeArguments; |
| 1025 while (type != null && type.head != null) { | 1024 while (type != null && type.head != null) { |
| 1026 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, | 1025 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, |
| 1027 system.compiler.dynamicClass.computeType(system.compiler))); | 1026 system.compiler.dynamicClass.computeType(system.compiler))); |
| 1028 type = type.tail; | 1027 type = type.tail; |
| 1029 } | 1028 } |
| 1030 } | 1029 } |
| 1031 return _typeArguments; | 1030 return _typeArguments; |
| 1032 } | 1031 } |
| 1033 | 1032 |
| 1034 List<TypeVariableMirror> typeVariables() => declaration.typeVariables(); | 1033 List<TypeVariableMirror> typeVariables() => declaration.typeVariables(); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 if (node !== null) { | 1361 if (node !== null) { |
| 1363 var span = system.compiler.spanFromNode(node, script.uri); | 1362 var span = system.compiler.spanFromNode(node, script.uri); |
| 1364 return new Dart2JsLocation(script, span); | 1363 return new Dart2JsLocation(script, span); |
| 1365 } else { | 1364 } else { |
| 1366 var span = system.compiler.spanFromElement(_variable); | 1365 var span = system.compiler.spanFromElement(_variable); |
| 1367 return new Dart2JsLocation(script, span); | 1366 return new Dart2JsLocation(script, span); |
| 1368 } | 1367 } |
| 1369 } | 1368 } |
| 1370 } | 1369 } |
| 1371 | 1370 |
| OLD | NEW |