| 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 library analyzer.context.declared_variables; | 5 library analyzer.context.declared_variables; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/constant/value.dart'; | 9 import 'package:analyzer/dart/constant/value.dart'; |
| 10 import 'package:analyzer/src/dart/constant/value.dart'; | 10 import 'package:analyzer/src/dart/constant/value.dart'; |
| 11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * An object used to provide access to the values of variables that have been | 14 * An object used to provide access to the values of variables that have been |
| 15 * defined on the command line using the `-D` option. | 15 * defined on the command line using the `-D` option. |
| 16 * | 16 * |
| 17 * Clients may not extend, implement or mix-in this class. | 17 * Clients may not extend, implement or mix-in this class. |
| 18 */ | 18 */ |
| 19 class DeclaredVariables { | 19 class DeclaredVariables { |
| 20 /** | 20 /** |
| 21 * A table mapping the names of declared variables to their values. | 21 * A table mapping the names of declared variables to their values. |
| 22 */ | 22 */ |
| 23 HashMap<String, String> _declaredVariables = new HashMap<String, String>(); | 23 HashMap<String, String> _declaredVariables = new HashMap<String, String>(); |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Return the names of the variables for which a value has been defined. |
| 27 */ |
| 28 Iterable<String> get variableNames => _declaredVariables.keys; |
| 29 |
| 30 /** |
| 26 * Define a variable with the given [name] to have the given [value]. | 31 * Define a variable with the given [name] to have the given [value]. |
| 27 */ | 32 */ |
| 28 void define(String name, String value) { | 33 void define(String name, String value) { |
| 29 _declaredVariables[name] = value; | 34 _declaredVariables[name] = value; |
| 30 } | 35 } |
| 31 | 36 |
| 32 /** | 37 /** |
| 33 * Return the value of the variable with the given [name] interpreted as a | 38 * Return the value of the variable with the given [name] interpreted as a |
| 34 * 'boolean' value. If the variable is not defined (or [name] is `null`), a | 39 * 'boolean' value. If the variable is not defined (or [name] is `null`), a |
| 35 * DartObject representing "unknown" is returned. If the value cannot be | 40 * DartObject representing "unknown" is returned. If the value cannot be |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 */ | 84 */ |
| 80 DartObject getString(TypeProvider typeProvider, String name) { | 85 DartObject getString(TypeProvider typeProvider, String name) { |
| 81 String value = _declaredVariables[name]; | 86 String value = _declaredVariables[name]; |
| 82 if (value == null) { | 87 if (value == null) { |
| 83 return new DartObjectImpl( | 88 return new DartObjectImpl( |
| 84 typeProvider.stringType, StringState.UNKNOWN_VALUE); | 89 typeProvider.stringType, StringState.UNKNOWN_VALUE); |
| 85 } | 90 } |
| 86 return new DartObjectImpl(typeProvider.stringType, new StringState(value)); | 91 return new DartObjectImpl(typeProvider.stringType, new StringState(value)); |
| 87 } | 92 } |
| 88 } | 93 } |
| OLD | NEW |