| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * The interface used to access the result of constant evaluation. |
| 7 * |
| 8 * Because the analyzer does not have any of the code under analysis loaded, it |
| 9 * does not do real evaluation. Instead it performs a symbolic computation and |
| 10 * presents those results through this interface. |
| 11 * |
| 12 * Instances of these constant values are accessed through the |
| 13 * [element model](../element/element.dart). |
| 14 */ |
| 15 library analyzer.dart.constant.value; |
| 16 |
| 17 import 'package:analyzer/dart/element/type.dart'; |
| 18 |
| 19 /** |
| 20 * A representation of the value of a compile-time constant expression. |
| 21 * |
| 22 * Note that, unlike the mirrors system, the object being represented does *not* |
| 23 * exist. This interface allows static analysis tools to determine something |
| 24 * about the state of the object that would exist if the code that creates the |
| 25 * object were executed, but none of the code being analyzed is actually |
| 26 * executed. |
| 27 * |
| 28 * Clients may not extend, implement or mix-in this class. |
| 29 */ |
| 30 abstract class DartObject { |
| 31 /** |
| 32 * Return `true` if the value of the object being represented is known. |
| 33 * |
| 34 * This method will return `false` if |
| 35 * * the value being represented is the value of a declared variable (a |
| 36 * variable whose value is provided at run-time using a `-D` command-line |
| 37 * option), or |
| 38 * * the value is a function. |
| 39 * |
| 40 * The result of this method does not imply anything about the state of |
| 41 * object representations returned by the method [getField], those that are |
| 42 * elements of the list returned by [toListValue], or the keys or values in |
| 43 * the map returned by [toMapValue]. For example, a representation of a list |
| 44 * can return `true` even if one or more of the elements of that list would |
| 45 * return `false`. |
| 46 */ |
| 47 bool get hasKnownValue; |
| 48 |
| 49 /** |
| 50 * Return `true` if the object being represented represents the value 'null'. |
| 51 */ |
| 52 bool get isNull; |
| 53 |
| 54 /** |
| 55 * Return a representation of the type of the object being represented. |
| 56 * |
| 57 * For values resulting from the invocation of a 'const' constructor, this |
| 58 * will be a representation of the run-time type of the object. |
| 59 * |
| 60 * For values resulting from a literal expression, this will be a |
| 61 * representation of the static type of the value -- `int` for integer |
| 62 * literals, `List` for list literals, etc. -- even when the static type is an |
| 63 * abstract type (such as `List`) and hence will never be the run-time type of |
| 64 * the represented object. |
| 65 * |
| 66 * For values resulting from any other kind of expression, this will be a |
| 67 * representation of the result of evaluating the expression. |
| 68 * |
| 69 * Return `null` if the expression cannot be evaluated, either because it is |
| 70 * not a valid constant expression or because one or more of the values used |
| 71 * in the expression does not have a known value. |
| 72 * |
| 73 * This method can return a representation of the type, even if this object |
| 74 * would return `false` from [hasKnownValue]. |
| 75 */ |
| 76 ParameterizedType get type; |
| 77 |
| 78 /** |
| 79 * Return a representation of the value of the field with the given [name]. |
| 80 * |
| 81 * Return `null` if either the object being represented does not have a field |
| 82 * with the given name or if the implementation of the class of the object is |
| 83 * invalid, making it impossible to determine that value of the field. |
| 84 * |
| 85 * Note that, unlike the mirrors API, this method does *not* invoke a getter; |
| 86 * it simply returns a representation of the known state of a field. |
| 87 */ |
| 88 DartObject getField(String name); |
| 89 |
| 90 /** |
| 91 * Return a boolean corresponding to the value of the object being |
| 92 * represented, or `null` if |
| 93 * * this object is not of type 'bool', |
| 94 * * the value of the object being represented is not known, or |
| 95 * * the value of the object being represented is `null`. |
| 96 */ |
| 97 bool toBoolValue(); |
| 98 |
| 99 /** |
| 100 * Return a double corresponding to the value of the object being represented, |
| 101 * or `null` |
| 102 * if |
| 103 * * this object is not of type 'double', |
| 104 * * the value of the object being represented is not known, or |
| 105 * * the value of the object being represented is `null`. |
| 106 */ |
| 107 double toDoubleValue(); |
| 108 |
| 109 /** |
| 110 * Return an integer corresponding to the value of the object being |
| 111 * represented, or `null` if |
| 112 * * this object is not of type 'int', |
| 113 * * the value of the object being represented is not known, or |
| 114 * * the value of the object being represented is `null`. |
| 115 */ |
| 116 int toIntValue(); |
| 117 |
| 118 /** |
| 119 * Return a list corresponding to the value of the object being represented, |
| 120 * or `null` if |
| 121 * * this object is not of type 'List', or |
| 122 * * the value of the object being represented is `null`. |
| 123 */ |
| 124 List<DartObject> toListValue(); |
| 125 |
| 126 /** |
| 127 * Return a map corresponding to the value of the object being represented, or |
| 128 * `null` if |
| 129 * * this object is not of type 'Map', or |
| 130 * * the value of the object being represented is `null`. |
| 131 */ |
| 132 Map<DartObject, DartObject> toMapValue(); |
| 133 |
| 134 /** |
| 135 * Return a string corresponding to the value of the object being represented, |
| 136 * or `null` if |
| 137 * * this object is not of type 'String', |
| 138 * * the value of the object being represented is not known, or |
| 139 * * the value of the object being represented is `null`. |
| 140 */ |
| 141 String toStringValue(); |
| 142 |
| 143 /** |
| 144 * Return a string corresponding to the value of the object being represented, |
| 145 * or `null` if |
| 146 * * this object is not of type 'Symbol', or |
| 147 * * the value of the object being represented is `null`. |
| 148 * (We return the string |
| 149 */ |
| 150 String toSymbolValue(); |
| 151 |
| 152 /** |
| 153 * Return the representation of the type corresponding to the value of the |
| 154 * object being represented, or `null` if |
| 155 * * this object is not of type 'Type', or |
| 156 * * the value of the object being represented is `null`. |
| 157 */ |
| 158 DartType toTypeValue(); |
| 159 } |
| OLD | NEW |