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('../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); | 7 #import('../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); |
8 #import('../../../lib/compiler/implementation/elements/elements.dart'); | 8 #import('../../../lib/compiler/implementation/elements/elements.dart'); |
9 #import('../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api'); | 9 #import('../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api'); |
10 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart'); | 10 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart'); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 Dart2JsObjectMirror library, Element element) { | 76 Dart2JsObjectMirror library, Element element) { |
77 if (element is SynthesizedConstructorElement) { | 77 if (element is SynthesizedConstructorElement) { |
78 return const <Dart2JsMemberMirror>[]; | 78 return const <Dart2JsMemberMirror>[]; |
79 } else if (element is VariableElement) { | 79 } else if (element is VariableElement) { |
80 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; | 80 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; |
81 } else if (element is FunctionElement) { | 81 } else if (element is FunctionElement) { |
82 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; | 82 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; |
83 } else if (element is AbstractFieldElement) { | 83 } else if (element is AbstractFieldElement) { |
84 var members = <Dart2JsMemberMirror>[]; | 84 var members = <Dart2JsMemberMirror>[]; |
85 if (element.getter !== null) { | 85 if (element.getter !== null) { |
86 members.add(new Dart2JsMethodMirror(library, element.getter, | 86 members.add(new Dart2JsMethodMirror(library, element.getter)); |
87 Dart2JsMethodKind.GETTER)); | |
88 } | 87 } |
89 if (element.setter !== null) { | 88 if (element.setter !== null) { |
90 members.add(new Dart2JsMethodMirror(library, element.setter, | 89 members.add(new Dart2JsMethodMirror(library, element.setter)); |
91 Dart2JsMethodKind.SETTER)); | |
92 } | 90 } |
93 return members; | 91 return members; |
94 } | 92 } |
95 throw new IllegalArgumentException( | 93 throw new IllegalArgumentException( |
96 "Unexpected member type $element ${element.kind}"); | 94 "Unexpected member type $element ${element.kind}"); |
97 } | 95 } |
98 | 96 |
99 MethodMirror _convertElementMethodToMethodMirror(Dart2JsObjectMirror library, | 97 MethodMirror _convertElementMethodToMethodMirror(Dart2JsObjectMirror library, |
100 Element element) { | 98 Element element) { |
101 if (element is FunctionElement) { | 99 if (element is FunctionElement) { |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 class Dart2JsMethodMirror extends Dart2JsElementMirror | 1189 class Dart2JsMethodMirror extends Dart2JsElementMirror |
1192 implements Dart2JsMemberMirror, MethodMirror { | 1190 implements Dart2JsMemberMirror, MethodMirror { |
1193 final Dart2JsObjectMirror _objectMirror; | 1191 final Dart2JsObjectMirror _objectMirror; |
1194 String _name; | 1192 String _name; |
1195 String _constructorName; | 1193 String _constructorName; |
1196 String _operatorName; | 1194 String _operatorName; |
1197 Dart2JsMethodKind _kind; | 1195 Dart2JsMethodKind _kind; |
1198 String _canonicalName; | 1196 String _canonicalName; |
1199 | 1197 |
1200 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror, | 1198 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror, |
1201 FunctionElement function, | 1199 FunctionElement function) |
1202 [Dart2JsMethodKind kind = null]) | |
1203 : this._objectMirror = objectMirror, | 1200 : this._objectMirror = objectMirror, |
1204 this._kind = kind, | |
1205 super(objectMirror.system, function) { | 1201 super(objectMirror.system, function) { |
1206 _name = _element.name.slowToString(); | 1202 _name = _element.name.slowToString(); |
1207 if (kind == null) { | 1203 if (_function.kind == ElementKind.GETTER) { |
1208 if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { | 1204 _kind = Dart2JsMethodKind.GETTER; |
1209 _constructorName = ''; | 1205 _canonicalName = _name; |
1210 int dollarPos = _name.indexOf('\$'); | 1206 } else if (_function.kind == ElementKind.SETTER) { |
1211 if (dollarPos != -1) { | 1207 _kind = Dart2JsMethodKind.SETTER; |
1212 _constructorName = _name.substring(dollarPos+1); | 1208 _canonicalName = '$_name='; |
1213 _name = _name.substring(0, dollarPos); | 1209 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { |
1214 // canonical name is TypeName.constructorName | 1210 _constructorName = ''; |
1215 _canonicalName = '$_name.$_constructorName'; | 1211 int dollarPos = _name.indexOf('\$'); |
1216 } else { | 1212 if (dollarPos != -1) { |
1217 // canonical name is TypeName | 1213 _constructorName = _name.substring(dollarPos+1); |
1218 _canonicalName = _name; | 1214 _name = _name.substring(0, dollarPos); |
1219 } | |
1220 if (_function.modifiers !== null && _function.modifiers.isConst()) { | |
1221 _kind = Dart2JsMethodKind.CONST; | |
1222 } else { | |
1223 _kind = Dart2JsMethodKind.CONSTRUCTOR; | |
1224 } | |
1225 } else if (_function.modifiers !== null | |
1226 && _function.modifiers.isFactory()) { | |
1227 _constructorName = ''; | |
1228 int dollarPos = _name.indexOf('\$'); | |
1229 if (dollarPos != -1) { | |
1230 _constructorName = _name.substring(dollarPos+1); | |
1231 _name = _name.substring(0, dollarPos); | |
1232 } | |
1233 _kind = Dart2JsMethodKind.FACTORY; | |
1234 // canonical name is TypeName.constructorName | 1215 // canonical name is TypeName.constructorName |
1235 _canonicalName = '$_name.$_constructorName'; | 1216 _canonicalName = '$_name.$_constructorName'; |
1236 } else if (_name.startsWith('operator\$')) { | |
1237 String str = _name.substring(9); | |
1238 _name = 'operator'; | |
1239 _kind = Dart2JsMethodKind.OPERATOR; | |
1240 _operatorName = _getOperatorFromOperatorName(str); | |
1241 // canonical name is 'operator operatorName' | |
1242 _canonicalName = 'operator $_operatorName'; | |
1243 } else { | 1217 } else { |
1244 _kind = Dart2JsMethodKind.NORMAL; | 1218 // canonical name is TypeName |
1245 _canonicalName = _name; | 1219 _canonicalName = _name; |
1246 } | 1220 } |
1247 } else if (kind == Dart2JsMethodKind.GETTER) { | 1221 if (_function.modifiers !== null && _function.modifiers.isConst()) { |
1222 _kind = Dart2JsMethodKind.CONST; | |
1223 } else { | |
1224 _kind = Dart2JsMethodKind.CONSTRUCTOR; | |
1225 } | |
1226 } else if (_function.modifiers !== null && | |
1227 _function.modifiers.isFactory()) { | |
1228 _kind = Dart2JsMethodKind.FACTORY; | |
1229 _constructorName = ''; | |
1230 int dollarPos = _name.indexOf('\$'); | |
1231 if (dollarPos != -1) { | |
1232 _constructorName = _name.substring(dollarPos+1); | |
Lasse Reichstein Nielsen
2012/08/20 13:07:58
Spaces around '+'.
Johnni Winther
2012/08/23 10:19:50
Done.
| |
1233 _name = _name.substring(0, dollarPos); | |
1234 } | |
1235 // canonical name is TypeName.constructorName | |
1236 _canonicalName = '$_name.$_constructorName'; | |
1237 } else if (_name.startsWith('operator\$')) { | |
1238 String str = _name.substring(9); | |
1239 _name = 'operator'; | |
1240 _kind = Dart2JsMethodKind.OPERATOR; | |
1241 _operatorName = _getOperatorFromOperatorName(str); | |
1242 // canonical name is 'operator operatorName' | |
1243 _canonicalName = 'operator $_operatorName'; | |
1244 } else { | |
1245 _kind = Dart2JsMethodKind.NORMAL; | |
1248 _canonicalName = _name; | 1246 _canonicalName = _name; |
1249 } else if (kind == Dart2JsMethodKind.SETTER) { | |
1250 _canonicalName = '$_name='; | |
1251 } else { | |
1252 assert(false); | |
1253 } | 1247 } |
1254 } | 1248 } |
1255 | 1249 |
1256 FunctionElement get _function() => _element; | 1250 FunctionElement get _function() => _element; |
1257 | 1251 |
1258 String get simpleName() => _name; | 1252 String get simpleName() => _name; |
1259 | 1253 |
1260 String get qualifiedName() | 1254 String get qualifiedName() |
1261 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; | 1255 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; |
1262 | 1256 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1355 if (node !== null) { | 1349 if (node !== null) { |
1356 var span = system.compiler.spanFromNode(node, script.uri); | 1350 var span = system.compiler.spanFromNode(node, script.uri); |
1357 return new Dart2JsLocation(script, span); | 1351 return new Dart2JsLocation(script, span); |
1358 } else { | 1352 } else { |
1359 var span = system.compiler.spanFromElement(_variable); | 1353 var span = system.compiler.spanFromElement(_variable); |
1360 return new Dart2JsLocation(script, span); | 1354 return new Dart2JsLocation(script, span); |
1361 } | 1355 } |
1362 } | 1356 } |
1363 } | 1357 } |
1364 | 1358 |
OLD | NEW |