mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:54:55 +00:00
Deprecate ElementAnnotation.constantValue
R=brianwilkerson@google.com, pquitslund@google.com Change-Id: Ifae6a614c20b703d9614d7ccc2f8b254bafcb070 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160942 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
04879fa4cd
commit
8ae9842e12
|
@ -2,6 +2,8 @@
|
|||
* Added `LocalVariableElement.hasInitializer`,
|
||||
`PropertyInducingElement.hasInitializer`, `ParameterElement.hasDefaultValue`.
|
||||
* `ElementImpl.toString()` uses `getDisplayString(withNullability: true)`.
|
||||
* Deprecated `ElementAnnotation.constantValue`, it does not guarantee that
|
||||
the value has been computed. Use `computeConstantValue()` instead.
|
||||
|
||||
## 0.40.0
|
||||
* Added `LibraryElement.featureSet`.
|
||||
|
|
|
@ -691,6 +691,7 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
|
|||
/// Return a representation of the value of this annotation, or `null` if the
|
||||
/// value of this annotation has not been computed or if the value could not
|
||||
/// be computed because of errors.
|
||||
@Deprecated('Use computeConstantValue() instead')
|
||||
DartObject get constantValue;
|
||||
|
||||
/// Return the element representing the field, variable, or const constructor
|
||||
|
|
|
@ -2409,6 +2409,7 @@ class ElementAnnotationImpl implements ElementAnnotation {
|
|||
List<AnalysisError> get constantEvaluationErrors =>
|
||||
evaluationResult?.errors ?? const <AnalysisError>[];
|
||||
|
||||
@Deprecated('Use computeConstantValue() instead')
|
||||
@override
|
||||
DartObject get constantValue => evaluationResult?.value;
|
||||
|
||||
|
@ -2565,7 +2566,7 @@ class ElementAnnotationImpl implements ElementAnnotation {
|
|||
computeConstants(library.typeProvider, library.typeSystem,
|
||||
context.declaredVariables, [this], analysisOptions.experimentStatus);
|
||||
}
|
||||
return constantValue;
|
||||
return evaluationResult?.value;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -7596,6 +7597,7 @@ abstract class VariableElementImpl extends ElementImpl
|
|||
/// initializers.
|
||||
Expression get constantInitializer => null;
|
||||
|
||||
@Deprecated('Use computeConstantValue() instead')
|
||||
@override
|
||||
DartObject get constantValue => evaluationResult?.value;
|
||||
|
||||
|
|
|
@ -1480,7 +1480,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
for (var annotation in classElement.metadata) {
|
||||
if (annotation.isTarget) {
|
||||
var value = annotation.constantValue;
|
||||
var value = annotation.computeConstantValue();
|
||||
var kinds = <TargetKind>{};
|
||||
for (var kindObject in value.getField('kinds').toSetValue()) {
|
||||
var index = kindObject.getField('index').toIntValue();
|
||||
|
|
|
@ -860,7 +860,7 @@ const x = 1;
|
|||
''');
|
||||
var result = await driver.getResult(testFile);
|
||||
Annotation at_x = AstFinder.getClass(result.unit, 'C').metadata[0];
|
||||
expect(at_x.elementAnnotation.constantValue.toIntValue(), 1);
|
||||
expect(at_x.elementAnnotation.computeConstantValue().toIntValue(), 1);
|
||||
}
|
||||
|
||||
test_const_circular_reference() async {
|
||||
|
|
|
@ -858,12 +858,10 @@ main() {
|
|||
ParameterElement parameter = argument.staticParameterElement;
|
||||
|
||||
ElementAnnotation annotation = parameter.metadata[0];
|
||||
expect(annotation.constantValue, isNull);
|
||||
|
||||
DartObject value = annotation.computeConstantValue();
|
||||
expect(value, isNotNull);
|
||||
expect(value.getField('f').toStringValue(), 'x');
|
||||
expect(annotation.constantValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ const a = const A();
|
|||
// To evaluate `const A()` we have to evaluate `{int p}`.
|
||||
// Even if its value is `null`.
|
||||
expect(p.isConstantEvaluated, isTrue);
|
||||
expect(p.constantValue.isNull, isTrue);
|
||||
expect(p.computeConstantValue().isNull, isTrue);
|
||||
}
|
||||
|
||||
test_constFactoryRedirection_super() async {
|
||||
|
@ -64,7 +64,7 @@ main() {}
|
|||
''');
|
||||
|
||||
var node = findNode.annotation('@I');
|
||||
var value = node.elementAnnotation.constantValue;
|
||||
var value = node.elementAnnotation.computeConstantValue();
|
||||
expect(value.getField('(super)').getField('f').toIntValue(), 42);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue