OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /** |
6 * The implementation of the class [DartObject]. | 6 * The implementation of the class [DartObject]. |
7 */ | 7 */ |
8 library analyzer.src.dart.constant.value; | 8 library analyzer.src.dart.constant.value; |
9 | 9 |
10 import 'dart:collection'; | 10 import 'dart:collection'; |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 @override | 369 @override |
370 DartObject getField(String name) { | 370 DartObject getField(String name) { |
371 InstanceState state = _state; | 371 InstanceState state = _state; |
372 if (state is GenericState) { | 372 if (state is GenericState) { |
373 return state.fields[name]; | 373 return state.fields[name]; |
374 } | 374 } |
375 return null; | 375 return null; |
376 } | 376 } |
377 | 377 |
| 378 /// Gets the constructor that was called to create this value, if this is a |
| 379 /// const constructor invocation. Otherwise returns null. |
| 380 ConstructorElement getConstructor() { |
| 381 InstanceState state = _state; |
| 382 if (state is GenericState) { |
| 383 return state.constructor; |
| 384 } |
| 385 return null; |
| 386 } |
| 387 |
| 388 /// Gets the arguments that were passed to create this value, if this is a |
| 389 /// const constructor invocation. Otherwise returns null. |
| 390 List<DartObject> getPositionalArguments() { |
| 391 InstanceState state = _state; |
| 392 if (state is GenericState) { |
| 393 return state.positionalArguments; |
| 394 } |
| 395 return null; |
| 396 } |
| 397 |
| 398 /// Gets the named arguments that were passed to create this value, if this is |
| 399 /// a const constructor invocation. Otherwise returns null. |
| 400 Map<String, DartObject> getNamedArguments() { |
| 401 InstanceState state = _state; |
| 402 if (state is GenericState) { |
| 403 return state.namedArguments; |
| 404 } |
| 405 return null; |
| 406 } |
| 407 |
378 /** | 408 /** |
379 * Return the result of invoking the '>' operator on this object with the | 409 * Return the result of invoking the '>' operator on this object with the |
380 * [rightOperand]. The [typeProvider] is the type provider used to find known | 410 * [rightOperand]. The [typeProvider] is the type provider used to find known |
381 * types. | 411 * types. |
382 * | 412 * |
383 * Throws an [EvaluationException] if the operator is not appropriate for an | 413 * Throws an [EvaluationException] if the operator is not appropriate for an |
384 * object of this kind. | 414 * object of this kind. |
385 */ | 415 */ |
386 DartObjectImpl greaterThan( | 416 DartObjectImpl greaterThan( |
387 TypeProvider typeProvider, DartObjectImpl rightOperand) => | 417 TypeProvider typeProvider, DartObjectImpl rightOperand) => |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 */ | 1345 */ |
1316 static GenericState UNKNOWN_VALUE = | 1346 static GenericState UNKNOWN_VALUE = |
1317 new GenericState(new HashMap<String, DartObjectImpl>()); | 1347 new GenericState(new HashMap<String, DartObjectImpl>()); |
1318 | 1348 |
1319 /** | 1349 /** |
1320 * The values of the fields of this instance. | 1350 * The values of the fields of this instance. |
1321 */ | 1351 */ |
1322 final HashMap<String, DartObjectImpl> _fieldMap; | 1352 final HashMap<String, DartObjectImpl> _fieldMap; |
1323 | 1353 |
1324 /** | 1354 /** |
| 1355 * The constructor that was invoked to generate this instance. |
| 1356 */ |
| 1357 final ConstructorElement constructor; |
| 1358 |
| 1359 /** |
| 1360 * The positional arguments passed to the constructor to create this instance. |
| 1361 */ |
| 1362 final List<DartObject> positionalArguments; |
| 1363 |
| 1364 /** |
| 1365 * The named arguments passed to the constructor to create this instance. |
| 1366 */ |
| 1367 final Map<String, DartObject> namedArguments; |
| 1368 |
| 1369 /** |
1325 * Initialize a newly created state to represent a newly created object. The | 1370 * Initialize a newly created state to represent a newly created object. The |
1326 * [fieldMap] contains the values of the fields of the instance. | 1371 * [fieldMap] contains the values of the fields of the instance. |
1327 */ | 1372 */ |
1328 GenericState(this._fieldMap); | 1373 GenericState(this._fieldMap, |
| 1374 {this.constructor, this.positionalArguments, this.namedArguments}); |
1329 | 1375 |
1330 @override | 1376 @override |
1331 HashMap<String, DartObjectImpl> get fields => _fieldMap; | 1377 HashMap<String, DartObjectImpl> get fields => _fieldMap; |
1332 | 1378 |
1333 @override | 1379 @override |
1334 int get hashCode { | 1380 int get hashCode { |
1335 int hashCode = 0; | 1381 int hashCode = 0; |
1336 for (DartObjectImpl value in _fieldMap.values) { | 1382 for (DartObjectImpl value in _fieldMap.values) { |
1337 hashCode += value.hashCode; | 1383 hashCode += value.hashCode; |
1338 } | 1384 } |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 return BoolState.from(_type == rightType); | 2854 return BoolState.from(_type == rightType); |
2809 } else if (rightOperand is DynamicState) { | 2855 } else if (rightOperand is DynamicState) { |
2810 return BoolState.UNKNOWN_VALUE; | 2856 return BoolState.UNKNOWN_VALUE; |
2811 } | 2857 } |
2812 return BoolState.FALSE_STATE; | 2858 return BoolState.FALSE_STATE; |
2813 } | 2859 } |
2814 | 2860 |
2815 @override | 2861 @override |
2816 String toString() => _type?.toString() ?? "-unknown-"; | 2862 String toString() => _type?.toString() ?? "-unknown-"; |
2817 } | 2863 } |
OLD | NEW |