Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 11348036: Alignments for the ClassMirror interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/dartdoc/lib/mirrors_util.dart ('k') | tests/compiler/dart2js/mirrors_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 => originalDeclaration.declaredM embers;
ahe 2012/10/30 14:35:46 Long line.
1040 1040
1041 bool get isObject => system.compiler.objectClass == _type.element; 1041 bool get isObject => system.compiler.objectClass == _type.element;
1042 1042
1043 bool get isDynamic => system.compiler.dynamicClass == _type.element; 1043 bool get isDynamic => system.compiler.dynamicClass == _type.element;
1044 1044
1045 ClassMirror get declaration 1045 ClassMirror get originalDeclaration
1046 => new Dart2JsClassMirror(system, _type.element); 1046 => new Dart2JsClassMirror(system, _type.element);
1047 1047
1048 // TODO(johnniwinther): Substitute type arguments for type variables. 1048 // TODO(johnniwinther): Substitute type arguments for type variables.
1049 ClassMirror get superclass => declaration.superclass; 1049 ClassMirror get superclass => originalDeclaration.superclass;
1050 1050
1051 // TODO(johnniwinther): Substitute type arguments for type variables. 1051 // TODO(johnniwinther): Substitute type arguments for type variables.
1052 List<ClassMirror> get interfaces => declaration.interfaces; 1052 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1053 1053
1054 bool get isClass => declaration.isClass; 1054 bool get isClass => originalDeclaration.isClass;
1055 1055
1056 bool get isInterface => declaration.isInterface; 1056 bool get isInterface => originalDeclaration.isInterface;
1057 1057
1058 bool get isAbstract => declaration.isAbstract; 1058 bool get isAbstract => originalDeclaration.isAbstract;
1059 1059
1060 bool get isPrivate => declaration.isPrivate; 1060 bool get isPrivate => originalDeclaration.isPrivate;
1061 1061
1062 bool get isDeclaration => false; 1062 bool get isOriginalDeclaration => false;
1063 1063
1064 List<TypeMirror> get typeArguments { 1064 List<TypeMirror> get typeArguments {
1065 if (_typeArguments == null) { 1065 if (_typeArguments == null) {
1066 _typeArguments = <TypeMirror>[]; 1066 _typeArguments = <TypeMirror>[];
1067 Link<DartType> type = _interfaceType.arguments; 1067 Link<DartType> type = _interfaceType.arguments;
1068 while (type != null && type.head != null) { 1068 while (type != null && type.head != null) {
1069 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, 1069 _typeArguments.add(_convertTypeToTypeMirror(system, type.head,
1070 system.compiler.types.dynamicType)); 1070 system.compiler.types.dynamicType));
1071 type = type.tail; 1071 type = type.tail;
1072 } 1072 }
1073 } 1073 }
1074 return _typeArguments; 1074 return _typeArguments;
1075 } 1075 }
1076 1076
1077 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; 1077 List<TypeVariableMirror> get typeVariables => originalDeclaration.typeVariable s;
kasperl 2012/10/30 14:05:12 Long line.
Johnni Winther 2012/10/30 14:25:39 Done.
1078 1078
1079 // TODO(johnniwinther): Substitute type arguments for type variables. 1079 // TODO(johnniwinther): Substitute type arguments for type variables.
1080 Map<String, MethodMirror> get constructors => declaration.constructors; 1080 Map<String, MethodMirror> get constructors => originalDeclaration.constructors ;
kasperl 2012/10/30 14:05:12 Long line.
Johnni Winther 2012/10/30 14:25:39 Done.
1081 1081
1082 // TODO(johnniwinther): Substitute type arguments for type variables? 1082 // TODO(johnniwinther): Substitute type arguments for type variables?
1083 ClassMirror get defaultType => declaration.defaultType; 1083 ClassMirror get defaultFactory => originalDeclaration.defaultFactory;
1084 1084
1085 bool operator ==(Object other) { 1085 bool operator ==(Object other) {
1086 if (this === other) { 1086 if (this === other) {
1087 return true; 1087 return true;
1088 } 1088 }
1089 if (other is! ClassMirror) { 1089 if (other is! ClassMirror) {
1090 return false; 1090 return false;
1091 } 1091 }
1092 if (other.isDeclaration) { 1092 if (other.isOriginalDeclaration) {
1093 return false; 1093 return false;
1094 } 1094 }
1095 if (declaration != other.declaration) { 1095 if (originalDeclaration != other.originalDeclaration) {
1096 return false; 1096 return false;
1097 } 1097 }
1098 var thisTypeArguments = typeArguments.iterator(); 1098 var thisTypeArguments = typeArguments.iterator();
1099 var otherTypeArguments = other.typeArguments.iterator(); 1099 var otherTypeArguments = other.typeArguments.iterator();
1100 while (thisTypeArguments.hasNext && otherTypeArguments.hasNext) { 1100 while (thisTypeArguments.hasNext && otherTypeArguments.hasNext) {
1101 if (thisTypeArguments.next() != otherTypeArguments.next()) { 1101 if (thisTypeArguments.next() != otherTypeArguments.next()) {
1102 return false; 1102 return false;
1103 } 1103 }
1104 } 1104 }
1105 return !thisTypeArguments.hasNext && !otherTypeArguments.hasNext; 1105 return !thisTypeArguments.hasNext && !otherTypeArguments.hasNext;
1106 } 1106 }
1107 } 1107 }
1108 1108
1109 1109
1110 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror 1110 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror
1111 implements FunctionTypeMirror { 1111 implements FunctionTypeMirror {
1112 final FunctionSignature _functionSignature; 1112 final FunctionSignature _functionSignature;
1113 List<ParameterMirror> _parameters; 1113 List<ParameterMirror> _parameters;
1114 1114
1115 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, 1115 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system,
1116 FunctionType functionType, this._functionSignature) 1116 FunctionType functionType, this._functionSignature)
1117 : super(system, functionType) { 1117 : super(system, functionType) {
1118 assert (_functionSignature !== null); 1118 assert (_functionSignature !== null);
1119 } 1119 }
1120 1120
1121 FunctionType get _functionType => _type; 1121 FunctionType get _functionType => _type;
1122 1122
1123 // TODO(johnniwinther): Is this the qualified name of a function type? 1123 // TODO(johnniwinther): Is this the qualified name of a function type?
1124 String get qualifiedName => declaration.qualifiedName; 1124 String get qualifiedName => originalDeclaration.qualifiedName;
1125 1125
1126 // TODO(johnniwinther): Substitute type arguments for type variables. 1126 // TODO(johnniwinther): Substitute type arguments for type variables.
1127 Map<String, MemberMirror> get declaredMembers { 1127 Map<String, MemberMirror> get declaredMembers {
1128 var method = callMethod; 1128 var method = callMethod;
1129 if (method !== null) { 1129 if (method !== null) {
1130 var map = new Map<String, MemberMirror>.from( 1130 var map = new Map<String, MemberMirror>.from(
1131 declaration.declaredMembers); 1131 originalDeclaration.declaredMembers);
1132 var name = method.qualifiedName; 1132 var name = method.qualifiedName;
1133 assert(!map.containsKey(name)); 1133 assert(!map.containsKey(name));
1134 map[name] = method; 1134 map[name] = method;
1135 return new ImmutableMapWrapper<String, MemberMirror>(map); 1135 return new ImmutableMapWrapper<String, MemberMirror>(map);
1136 } 1136 }
1137 return declaration.declaredMembers; 1137 return originalDeclaration.declaredMembers;
1138 } 1138 }
1139 1139
1140 bool get isFunction => true; 1140 bool get isFunction => true;
1141 1141
1142 MethodMirror get callMethod => _convertElementMethodToMethodMirror( 1142 MethodMirror get callMethod => _convertElementMethodToMethodMirror(
1143 system.getLibrary(_functionType.element.getLibrary()), 1143 system.getLibrary(_functionType.element.getLibrary()),
1144 _functionType.element); 1144 _functionType.element);
1145 1145
1146 ClassMirror get declaration 1146 ClassMirror get originalDeclaration
1147 => new Dart2JsClassMirror(system, system.compiler.functionClass); 1147 => new Dart2JsClassMirror(system, system.compiler.functionClass);
1148 1148
1149 // TODO(johnniwinther): Substitute type arguments for type variables. 1149 // TODO(johnniwinther): Substitute type arguments for type variables.
1150 ClassMirror get superclass => declaration.superclass; 1150 ClassMirror get superclass => originalDeclaration.superclass;
1151 1151
1152 // TODO(johnniwinther): Substitute type arguments for type variables. 1152 // TODO(johnniwinther): Substitute type arguments for type variables.
1153 List<ClassMirror> get interfaces => declaration.interfaces; 1153 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1154 1154
1155 bool get isClass => declaration.isClass; 1155 bool get isClass => originalDeclaration.isClass;
1156 1156
1157 bool get isInterface => declaration.isInterface; 1157 bool get isInterface => originalDeclaration.isInterface;
1158 1158
1159 bool get isPrivate => declaration.isPrivate; 1159 bool get isPrivate => originalDeclaration.isPrivate;
1160 1160
1161 bool get isDeclaration => false; 1161 bool get isOriginalDeclaration => false;
1162 1162
1163 bool get isAbstract => false; 1163 bool get isAbstract => false;
1164 1164
1165 List<TypeMirror> get typeArguments => const <TypeMirror>[]; 1165 List<TypeMirror> get typeArguments => const <TypeMirror>[];
1166 1166
1167 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; 1167 List<TypeVariableMirror> get typeVariables => originalDeclaration.typeVariable s;
ahe 2012/10/30 14:35:46 Long line.
1168 1168
1169 Map<String, MethodMirror> get constructors => <String, MethodMirror>{}; 1169 Map<String, MethodMirror> get constructors => <String, MethodMirror>{};
1170 1170
1171 ClassMirror get defaultType => null; 1171 ClassMirror get defaultFactory => null;
1172 1172
1173 TypeMirror get returnType { 1173 TypeMirror get returnType {
1174 return _convertTypeToTypeMirror(system, _functionType.returnType, 1174 return _convertTypeToTypeMirror(system, _functionType.returnType,
1175 system.compiler.types.dynamicType); 1175 system.compiler.types.dynamicType);
1176 } 1176 }
1177 1177
1178 List<ParameterMirror> get parameters { 1178 List<ParameterMirror> get parameters {
1179 if (_parameters === null) { 1179 if (_parameters === null) {
1180 _parameters = _parametersFromFunctionSignature(system, callMethod, 1180 _parameters = _parametersFromFunctionSignature(system, callMethod,
1181 _functionSignature); 1181 _functionSignature);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 if (node !== null) { 1425 if (node !== null) {
1426 var span = system.compiler.spanFromNode(node, script.uri); 1426 var span = system.compiler.spanFromNode(node, script.uri);
1427 return new Dart2JsLocation(script, span); 1427 return new Dart2JsLocation(script, span);
1428 } else { 1428 } else {
1429 var span = system.compiler.spanFromElement(_variable); 1429 var span = system.compiler.spanFromElement(_variable);
1430 return new Dart2JsLocation(script, span); 1430 return new Dart2JsLocation(script, span);
1431 } 1431 }
1432 } 1432 }
1433 } 1433 }
1434 1434
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/mirrors_util.dart ('k') | tests/compiler/dart2js/mirrors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698