| 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 bool get isDynamic => false; | 758 bool get isDynamic => false; |
| 759 | 759 |
| 760 bool get isVoid => false; | 760 bool get isVoid => false; |
| 761 | 761 |
| 762 bool get isTypeVariable => false; | 762 bool get isTypeVariable => false; |
| 763 | 763 |
| 764 bool get isTypedef => false; | 764 bool get isTypedef => false; |
| 765 | 765 |
| 766 bool get isFunction => false; | 766 bool get isFunction => false; |
| 767 | 767 |
| 768 ClassMirror get declaration => this; | 768 ClassMirror get originalDeclaration => this; |
| 769 | 769 |
| 770 ClassMirror get superclass { | 770 ClassMirror get superclass { |
| 771 if (_class.supertype != null) { | 771 if (_class.supertype != null) { |
| 772 return new Dart2JsInterfaceTypeMirror(system, _class.supertype); | 772 return new Dart2JsInterfaceTypeMirror(system, _class.supertype); |
| 773 } | 773 } |
| 774 return null; | 774 return null; |
| 775 } | 775 } |
| 776 | 776 |
| 777 List<ClassMirror> get interfaces { | 777 List<ClassMirror> get superinterfaces { |
| 778 var list = <ClassMirror>[]; | 778 var list = <ClassMirror>[]; |
| 779 Link<DartType> link = _class.interfaces; | 779 Link<DartType> link = _class.interfaces; |
| 780 while (!link.isEmpty) { | 780 while (!link.isEmpty) { |
| 781 var type = _convertTypeToTypeMirror(system, link.head, | 781 var type = _convertTypeToTypeMirror(system, link.head, |
| 782 system.compiler.types.dynamicType); | 782 system.compiler.types.dynamicType); |
| 783 list.add(type); | 783 list.add(type); |
| 784 link = link.tail; | 784 link = link.tail; |
| 785 } | 785 } |
| 786 return list; | 786 return list; |
| 787 } | 787 } |
| 788 | 788 |
| 789 bool get isClass => !_class.isInterface(); | 789 bool get isClass => !_class.isInterface(); |
| 790 | 790 |
| 791 bool get isInterface => _class.isInterface(); | 791 bool get isInterface => _class.isInterface(); |
| 792 | 792 |
| 793 bool get isAbstract => _class.modifiers.isAbstract(); | 793 bool get isAbstract => _class.modifiers.isAbstract(); |
| 794 | 794 |
| 795 bool get isDeclaration => true; | 795 bool get isOriginalDeclaration => true; |
| 796 | 796 |
| 797 List<TypeMirror> get typeArguments { | 797 List<TypeMirror> get typeArguments { |
| 798 throw new UnsupportedError( | 798 throw new UnsupportedError( |
| 799 'Declarations do not have type arguments'); | 799 'Declarations do not have type arguments'); |
| 800 } | 800 } |
| 801 | 801 |
| 802 List<TypeVariableMirror> get typeVariables { | 802 List<TypeVariableMirror> get typeVariables { |
| 803 if (_typeVariables == null) { | 803 if (_typeVariables == null) { |
| 804 _typeVariables = <TypeVariableMirror>[]; | 804 _typeVariables = <TypeVariableMirror>[]; |
| 805 _class.ensureResolved(system.compiler); | 805 _class.ensureResolved(system.compiler); |
| 806 for (TypeVariableType typeVariable in _class.typeVariables) { | 806 for (TypeVariableType typeVariable in _class.typeVariables) { |
| 807 _typeVariables.add( | 807 _typeVariables.add( |
| 808 new Dart2JsTypeVariableMirror(system, typeVariable)); | 808 new Dart2JsTypeVariableMirror(system, typeVariable)); |
| 809 } | 809 } |
| 810 } | 810 } |
| 811 return _typeVariables; | 811 return _typeVariables; |
| 812 } | 812 } |
| 813 | 813 |
| 814 Map<String, MethodMirror> get constructors { | 814 Map<String, MethodMirror> get constructors { |
| 815 _ensureMembers(); | 815 _ensureMembers(); |
| 816 return new AsFilteredImmutableMap<String, MemberMirror, MethodMirror>( | 816 return new AsFilteredImmutableMap<String, MemberMirror, MethodMirror>( |
| 817 _members, (m) => m.isConstructor ? m : null); | 817 _members, (m) => m.isConstructor ? m : null); |
| 818 } | 818 } |
| 819 | 819 |
| 820 /** | 820 /** |
| 821 * Returns the default type for this interface. | 821 * Returns the default type for this interface. |
| 822 */ | 822 */ |
| 823 ClassMirror get defaultType { | 823 ClassMirror get defaultFactory { |
| 824 if (_class.defaultClass != null) { | 824 if (_class.defaultClass != null) { |
| 825 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); | 825 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); |
| 826 } | 826 } |
| 827 return null; | 827 return null; |
| 828 } | 828 } |
| 829 | 829 |
| 830 bool operator ==(Object other) { | 830 bool operator ==(Object other) { |
| 831 if (this === other) { | 831 if (this === other) { |
| 832 return true; | 832 return true; |
| 833 } | 833 } |
| 834 if (other is! ClassMirror) { | 834 if (other is! ClassMirror) { |
| 835 return false; | 835 return false; |
| 836 } | 836 } |
| 837 if (library != other.library) { | 837 if (library != other.library) { |
| 838 return false; | 838 return false; |
| 839 } | 839 } |
| 840 if (isDeclaration !== other.isDeclaration) { | 840 if (isOriginalDeclaration !== other.isOriginalDeclaration) { |
| 841 return false; | 841 return false; |
| 842 } | 842 } |
| 843 return qualifiedName == other.qualifiedName; | 843 return qualifiedName == other.qualifiedName; |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 | 846 |
| 847 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror | 847 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror |
| 848 implements Dart2JsTypeMirror, TypedefMirror { | 848 implements Dart2JsTypeMirror, TypedefMirror { |
| 849 final Dart2JsLibraryMirror _library; | 849 final Dart2JsLibraryMirror _library; |
| 850 List<TypeVariableMirror> _typeVariables; | 850 List<TypeVariableMirror> _typeVariables; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 _typedef.element.alias, | 902 _typedef.element.alias, |
| 903 system.compiler.types.dynamicType, | 903 system.compiler.types.dynamicType, |
| 904 _typedef.element.functionSignature); | 904 _typedef.element.functionSignature); |
| 905 } | 905 } |
| 906 return _definition; | 906 return _definition; |
| 907 } | 907 } |
| 908 | 908 |
| 909 Map<String, MemberMirror> get declaredMembers => | 909 Map<String, MemberMirror> get declaredMembers => |
| 910 const <String, MemberMirror>{}; | 910 const <String, MemberMirror>{}; |
| 911 | 911 |
| 912 ClassMirror get declaration => this; | 912 ClassMirror get originalDeclaration => this; |
| 913 | 913 |
| 914 // TODO(johnniwinther): How should a typedef respond to these? | 914 // TODO(johnniwinther): How should a typedef respond to these? |
| 915 ClassMirror get superclass => null; | 915 ClassMirror get superclass => null; |
| 916 | 916 |
| 917 List<ClassMirror> get interfaces => const <ClassMirror>[]; | 917 List<ClassMirror> get superinterfaces => const <ClassMirror>[]; |
| 918 | 918 |
| 919 bool get isClass => false; | 919 bool get isClass => false; |
| 920 | 920 |
| 921 bool get isInterface => false; | 921 bool get isInterface => false; |
| 922 | 922 |
| 923 bool get isDeclaration => true; | 923 bool get isOriginalDeclaration => true; |
| 924 | 924 |
| 925 bool get isAbstract => false; | 925 bool get isAbstract => false; |
| 926 | 926 |
| 927 Map<String, MethodMirror> get constructors => | 927 Map<String, MethodMirror> get constructors => |
| 928 const <String, MethodMirror>{}; | 928 const <String, MethodMirror>{}; |
| 929 | 929 |
| 930 ClassMirror get defaultType => null; | 930 ClassMirror get defaultFactory => null; |
| 931 } | 931 } |
| 932 | 932 |
| 933 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror | 933 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror |
| 934 implements TypeVariableMirror { | 934 implements TypeVariableMirror { |
| 935 final TypeVariableType _typeVariableType; | 935 final TypeVariableType _typeVariableType; |
| 936 ClassMirror _declarer; | 936 ClassMirror _declarer; |
| 937 | 937 |
| 938 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, | 938 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, |
| 939 TypeVariableType typeVariableType) | 939 TypeVariableType typeVariableType) |
| 940 : this._typeVariableType = typeVariableType, | 940 : this._typeVariableType = typeVariableType, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror | 1026 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror |
| 1027 implements ClassMirror { | 1027 implements ClassMirror { |
| 1028 List<TypeMirror> _typeArguments; | 1028 List<TypeMirror> _typeArguments; |
| 1029 | 1029 |
| 1030 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, | 1030 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, |
| 1031 InterfaceType interfaceType) | 1031 InterfaceType interfaceType) |
| 1032 : super(system, interfaceType); | 1032 : super(system, interfaceType); |
| 1033 | 1033 |
| 1034 InterfaceType get _interfaceType => _type; | 1034 InterfaceType get _interfaceType => _type; |
| 1035 | 1035 |
| 1036 String get qualifiedName => declaration.qualifiedName; | 1036 String get qualifiedName => originalDeclaration.qualifiedName; |
| 1037 | 1037 |
| 1038 // TODO(johnniwinther): Substitute type arguments for type variables. | 1038 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1039 Map<String, MemberMirror> get declaredMembers => declaration.declaredMembers; | 1039 Map<String, MemberMirror> get declaredMembers => |
| 1040 originalDeclaration.declaredMembers; |
| 1040 | 1041 |
| 1041 bool get isObject => system.compiler.objectClass == _type.element; | 1042 bool get isObject => system.compiler.objectClass == _type.element; |
| 1042 | 1043 |
| 1043 bool get isDynamic => system.compiler.dynamicClass == _type.element; | 1044 bool get isDynamic => system.compiler.dynamicClass == _type.element; |
| 1044 | 1045 |
| 1045 ClassMirror get declaration | 1046 ClassMirror get originalDeclaration |
| 1046 => new Dart2JsClassMirror(system, _type.element); | 1047 => new Dart2JsClassMirror(system, _type.element); |
| 1047 | 1048 |
| 1048 // TODO(johnniwinther): Substitute type arguments for type variables. | 1049 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1049 ClassMirror get superclass => declaration.superclass; | 1050 ClassMirror get superclass => originalDeclaration.superclass; |
| 1050 | 1051 |
| 1051 // TODO(johnniwinther): Substitute type arguments for type variables. | 1052 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1052 List<ClassMirror> get interfaces => declaration.interfaces; | 1053 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; |
| 1053 | 1054 |
| 1054 bool get isClass => declaration.isClass; | 1055 bool get isClass => originalDeclaration.isClass; |
| 1055 | 1056 |
| 1056 bool get isInterface => declaration.isInterface; | 1057 bool get isInterface => originalDeclaration.isInterface; |
| 1057 | 1058 |
| 1058 bool get isAbstract => declaration.isAbstract; | 1059 bool get isAbstract => originalDeclaration.isAbstract; |
| 1059 | 1060 |
| 1060 bool get isPrivate => declaration.isPrivate; | 1061 bool get isPrivate => originalDeclaration.isPrivate; |
| 1061 | 1062 |
| 1062 bool get isDeclaration => false; | 1063 bool get isOriginalDeclaration => false; |
| 1063 | 1064 |
| 1064 List<TypeMirror> get typeArguments { | 1065 List<TypeMirror> get typeArguments { |
| 1065 if (_typeArguments == null) { | 1066 if (_typeArguments == null) { |
| 1066 _typeArguments = <TypeMirror>[]; | 1067 _typeArguments = <TypeMirror>[]; |
| 1067 Link<DartType> type = _interfaceType.arguments; | 1068 Link<DartType> type = _interfaceType.arguments; |
| 1068 while (type != null && type.head != null) { | 1069 while (type != null && type.head != null) { |
| 1069 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, | 1070 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, |
| 1070 system.compiler.types.dynamicType)); | 1071 system.compiler.types.dynamicType)); |
| 1071 type = type.tail; | 1072 type = type.tail; |
| 1072 } | 1073 } |
| 1073 } | 1074 } |
| 1074 return _typeArguments; | 1075 return _typeArguments; |
| 1075 } | 1076 } |
| 1076 | 1077 |
| 1077 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; | 1078 List<TypeVariableMirror> get typeVariables => |
| 1079 originalDeclaration.typeVariables; |
| 1078 | 1080 |
| 1079 // TODO(johnniwinther): Substitute type arguments for type variables. | 1081 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1080 Map<String, MethodMirror> get constructors => declaration.constructors; | 1082 Map<String, MethodMirror> get constructors => |
| 1083 originalDeclaration.constructors; |
| 1081 | 1084 |
| 1082 // TODO(johnniwinther): Substitute type arguments for type variables? | 1085 // TODO(johnniwinther): Substitute type arguments for type variables? |
| 1083 ClassMirror get defaultType => declaration.defaultType; | 1086 ClassMirror get defaultFactory => originalDeclaration.defaultFactory; |
| 1084 | 1087 |
| 1085 bool operator ==(Object other) { | 1088 bool operator ==(Object other) { |
| 1086 if (this === other) { | 1089 if (this === other) { |
| 1087 return true; | 1090 return true; |
| 1088 } | 1091 } |
| 1089 if (other is! ClassMirror) { | 1092 if (other is! ClassMirror) { |
| 1090 return false; | 1093 return false; |
| 1091 } | 1094 } |
| 1092 if (other.isDeclaration) { | 1095 if (other.isOriginalDeclaration) { |
| 1093 return false; | 1096 return false; |
| 1094 } | 1097 } |
| 1095 if (declaration != other.declaration) { | 1098 if (originalDeclaration != other.originalDeclaration) { |
| 1096 return false; | 1099 return false; |
| 1097 } | 1100 } |
| 1098 var thisTypeArguments = typeArguments.iterator(); | 1101 var thisTypeArguments = typeArguments.iterator(); |
| 1099 var otherTypeArguments = other.typeArguments.iterator(); | 1102 var otherTypeArguments = other.typeArguments.iterator(); |
| 1100 while (thisTypeArguments.hasNext && otherTypeArguments.hasNext) { | 1103 while (thisTypeArguments.hasNext && otherTypeArguments.hasNext) { |
| 1101 if (thisTypeArguments.next() != otherTypeArguments.next()) { | 1104 if (thisTypeArguments.next() != otherTypeArguments.next()) { |
| 1102 return false; | 1105 return false; |
| 1103 } | 1106 } |
| 1104 } | 1107 } |
| 1105 return !thisTypeArguments.hasNext && !otherTypeArguments.hasNext; | 1108 return !thisTypeArguments.hasNext && !otherTypeArguments.hasNext; |
| 1106 } | 1109 } |
| 1107 } | 1110 } |
| 1108 | 1111 |
| 1109 | 1112 |
| 1110 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror | 1113 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror |
| 1111 implements FunctionTypeMirror { | 1114 implements FunctionTypeMirror { |
| 1112 final FunctionSignature _functionSignature; | 1115 final FunctionSignature _functionSignature; |
| 1113 List<ParameterMirror> _parameters; | 1116 List<ParameterMirror> _parameters; |
| 1114 | 1117 |
| 1115 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, | 1118 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, |
| 1116 FunctionType functionType, this._functionSignature) | 1119 FunctionType functionType, this._functionSignature) |
| 1117 : super(system, functionType) { | 1120 : super(system, functionType) { |
| 1118 assert (_functionSignature !== null); | 1121 assert (_functionSignature !== null); |
| 1119 } | 1122 } |
| 1120 | 1123 |
| 1121 FunctionType get _functionType => _type; | 1124 FunctionType get _functionType => _type; |
| 1122 | 1125 |
| 1123 // TODO(johnniwinther): Is this the qualified name of a function type? | 1126 // TODO(johnniwinther): Is this the qualified name of a function type? |
| 1124 String get qualifiedName => declaration.qualifiedName; | 1127 String get qualifiedName => originalDeclaration.qualifiedName; |
| 1125 | 1128 |
| 1126 // TODO(johnniwinther): Substitute type arguments for type variables. | 1129 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1127 Map<String, MemberMirror> get declaredMembers { | 1130 Map<String, MemberMirror> get declaredMembers { |
| 1128 var method = callMethod; | 1131 var method = callMethod; |
| 1129 if (method !== null) { | 1132 if (method !== null) { |
| 1130 var map = new Map<String, MemberMirror>.from( | 1133 var map = new Map<String, MemberMirror>.from( |
| 1131 declaration.declaredMembers); | 1134 originalDeclaration.declaredMembers); |
| 1132 var name = method.qualifiedName; | 1135 var name = method.qualifiedName; |
| 1133 assert(!map.containsKey(name)); | 1136 assert(!map.containsKey(name)); |
| 1134 map[name] = method; | 1137 map[name] = method; |
| 1135 return new ImmutableMapWrapper<String, MemberMirror>(map); | 1138 return new ImmutableMapWrapper<String, MemberMirror>(map); |
| 1136 } | 1139 } |
| 1137 return declaration.declaredMembers; | 1140 return originalDeclaration.declaredMembers; |
| 1138 } | 1141 } |
| 1139 | 1142 |
| 1140 bool get isFunction => true; | 1143 bool get isFunction => true; |
| 1141 | 1144 |
| 1142 MethodMirror get callMethod => _convertElementMethodToMethodMirror( | 1145 MethodMirror get callMethod => _convertElementMethodToMethodMirror( |
| 1143 system.getLibrary(_functionType.element.getLibrary()), | 1146 system.getLibrary(_functionType.element.getLibrary()), |
| 1144 _functionType.element); | 1147 _functionType.element); |
| 1145 | 1148 |
| 1146 ClassMirror get declaration | 1149 ClassMirror get originalDeclaration |
| 1147 => new Dart2JsClassMirror(system, system.compiler.functionClass); | 1150 => new Dart2JsClassMirror(system, system.compiler.functionClass); |
| 1148 | 1151 |
| 1149 // TODO(johnniwinther): Substitute type arguments for type variables. | 1152 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1150 ClassMirror get superclass => declaration.superclass; | 1153 ClassMirror get superclass => originalDeclaration.superclass; |
| 1151 | 1154 |
| 1152 // TODO(johnniwinther): Substitute type arguments for type variables. | 1155 // TODO(johnniwinther): Substitute type arguments for type variables. |
| 1153 List<ClassMirror> get interfaces => declaration.interfaces; | 1156 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; |
| 1154 | 1157 |
| 1155 bool get isClass => declaration.isClass; | 1158 bool get isClass => originalDeclaration.isClass; |
| 1156 | 1159 |
| 1157 bool get isInterface => declaration.isInterface; | 1160 bool get isInterface => originalDeclaration.isInterface; |
| 1158 | 1161 |
| 1159 bool get isPrivate => declaration.isPrivate; | 1162 bool get isPrivate => originalDeclaration.isPrivate; |
| 1160 | 1163 |
| 1161 bool get isDeclaration => false; | 1164 bool get isOriginalDeclaration => false; |
| 1162 | 1165 |
| 1163 bool get isAbstract => false; | 1166 bool get isAbstract => false; |
| 1164 | 1167 |
| 1165 List<TypeMirror> get typeArguments => const <TypeMirror>[]; | 1168 List<TypeMirror> get typeArguments => const <TypeMirror>[]; |
| 1166 | 1169 |
| 1167 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; | 1170 List<TypeVariableMirror> get typeVariables => |
| 1171 originalDeclaration.typeVariables; |
| 1168 | 1172 |
| 1169 Map<String, MethodMirror> get constructors => <String, MethodMirror>{}; | 1173 Map<String, MethodMirror> get constructors => <String, MethodMirror>{}; |
| 1170 | 1174 |
| 1171 ClassMirror get defaultType => null; | 1175 ClassMirror get defaultFactory => null; |
| 1172 | 1176 |
| 1173 TypeMirror get returnType { | 1177 TypeMirror get returnType { |
| 1174 return _convertTypeToTypeMirror(system, _functionType.returnType, | 1178 return _convertTypeToTypeMirror(system, _functionType.returnType, |
| 1175 system.compiler.types.dynamicType); | 1179 system.compiler.types.dynamicType); |
| 1176 } | 1180 } |
| 1177 | 1181 |
| 1178 List<ParameterMirror> get parameters { | 1182 List<ParameterMirror> get parameters { |
| 1179 if (_parameters === null) { | 1183 if (_parameters === null) { |
| 1180 _parameters = _parametersFromFunctionSignature(system, callMethod, | 1184 _parameters = _parametersFromFunctionSignature(system, callMethod, |
| 1181 _functionSignature); | 1185 _functionSignature); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 if (node !== null) { | 1429 if (node !== null) { |
| 1426 var span = system.compiler.spanFromNode(node, script.uri); | 1430 var span = system.compiler.spanFromNode(node, script.uri); |
| 1427 return new Dart2JsLocation(script, span); | 1431 return new Dart2JsLocation(script, span); |
| 1428 } else { | 1432 } else { |
| 1429 var span = system.compiler.spanFromElement(_variable); | 1433 var span = system.compiler.spanFromElement(_variable); |
| 1430 return new Dart2JsLocation(script, span); | 1434 return new Dart2JsLocation(script, span); |
| 1431 } | 1435 } |
| 1432 } | 1436 } |
| 1433 } | 1437 } |
| 1434 | 1438 |
| OLD | NEW |