Skip to content

Commit cdd2700

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate many ID tests.
Change-Id: Ib29a26f5cce9c7c358aa4fab02373cf9128f6774 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396700 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent c42b74d commit cdd2700

15 files changed

+90
-88
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,7 @@ test/generated/simple_resolver_test.dart
178178
test/generated/static_type_analyzer_test.dart
179179
test/generated/type_system_test.dart
180180
test/id_tests/assigned_variables_test.dart
181-
test/id_tests/constant_test.dart
182-
test/id_tests/definite_assignment_test.dart
183-
test/id_tests/definite_unassignment_test.dart
184-
test/id_tests/exhaustiveness_test.dart
185-
test/id_tests/inferred_type_arguments_test.dart
186-
test/id_tests/inferred_variable_types_test.dart
187-
test/id_tests/metadata_evaluate_test.dart
188-
test/id_tests/metadata_test.dart
189-
test/id_tests/nullability_test.dart
190-
test/id_tests/reachability_test.dart
191181
test/id_tests/type_constraint_generation_test.dart
192-
test/id_tests/type_promotion_test.dart
193-
test/id_tests/why_not_promoted_test.dart
194182
test/src/dart/analysis/driver_caching_test.dart
195183
test/src/dart/analysis/driver_test.dart
196184
test/src/dart/analysis/index_test.dart

pkg/analyzer/lib/dart/constant/value.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
library;
1414

1515
import 'package:analyzer/dart/element/element.dart';
16+
import 'package:analyzer/dart/element/element2.dart';
1617
import 'package:analyzer/dart/element/type.dart';
18+
import 'package:meta/meta.dart';
1719

1820
/// A representation of the value of a compile-time constant expression.
1921
///
@@ -102,6 +104,15 @@ abstract class DartObject {
102104
/// * the value of the object being represented is `null`.
103105
ExecutableElement? toFunctionValue();
104106

107+
/// Return an element corresponding to the value of the object being
108+
/// represented, or `null`
109+
/// if
110+
/// * this object is not of a function type,
111+
/// * the value of the object being represented is not known, or
112+
/// * the value of the object being represented is `null`.
113+
@experimental
114+
ExecutableElement2? toFunctionValue2();
115+
105116
/// Return an integer corresponding to the value of the object being
106117
/// represented, or `null` if
107118
/// * this object is not of type 'int',

pkg/analyzer/lib/src/dart/constant/value.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/dart/ast/ast.dart';
1414
import 'package:analyzer/dart/ast/syntactic_entity.dart';
1515
import 'package:analyzer/dart/constant/value.dart';
1616
import 'package:analyzer/dart/element/element.dart';
17+
import 'package:analyzer/dart/element/element2.dart';
1718
import 'package:analyzer/dart/element/type.dart';
1819
import 'package:analyzer/diagnostic/diagnostic.dart';
1920
import 'package:analyzer/error/error.dart';
@@ -23,6 +24,7 @@ import 'package:analyzer/src/dart/element/element.dart';
2324
import 'package:analyzer/src/dart/element/extensions.dart';
2425
import 'package:analyzer/src/dart/element/type_system.dart';
2526
import 'package:analyzer/src/error/codes.dart';
27+
import 'package:analyzer/src/utilities/extensions/element.dart';
2628
import 'package:meta/meta.dart';
2729

2830
/// The state of an object representing a boolean value.
@@ -897,6 +899,11 @@ class DartObjectImpl implements DartObject, Constant {
897899
return state is FunctionState ? state.element : null;
898900
}
899901

902+
@override
903+
ExecutableElement2? toFunctionValue2() {
904+
return toFunctionValue().asElement2;
905+
}
906+
900907
@override
901908
int? toIntValue() {
902909
var state = this.state;

pkg/analyzer/test/id_tests/constant_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
99
import 'package:analyzer/dart/analysis/features.dart';
1010
import 'package:analyzer/dart/ast/ast.dart';
1111
import 'package:analyzer/dart/constant/value.dart';
12-
import 'package:analyzer/dart/element/element.dart';
12+
import 'package:analyzer/dart/element/element2.dart';
1313
import 'package:analyzer/dart/element/type.dart';
1414
import 'package:analyzer/error/error.dart';
1515
import 'package:analyzer/src/dart/analysis/experiments.dart';
@@ -58,8 +58,8 @@ class ConstantsDataComputer extends DataComputer<String> {
5858
@override
5959
void computeUnitData(TestingData testingData, CompilationUnit unit,
6060
Map<Id, ActualData<String>> actualMap) {
61-
ConstantsDataExtractor(unit.declaredElement!.source.uri, actualMap)
62-
.run(unit);
61+
var unitUri = unit.declaredFragment!.source.uri;
62+
ConstantsDataExtractor(unitUri, actualMap).run(unit);
6363
}
6464
}
6565

@@ -69,9 +69,9 @@ class ConstantsDataExtractor extends AstDataExtractor<String> {
6969
@override
7070
String? computeNodeValue(Id id, AstNode node) {
7171
if (node is Identifier) {
72-
var element = node.staticElement;
73-
if (element is PropertyAccessorElement && element.isSynthetic) {
74-
var variable = element.variable2!;
72+
var element = node.element;
73+
if (element is PropertyAccessorElement2 && element.isSynthetic) {
74+
var variable = element.variable3!;
7575
if (!variable.isSynthetic && variable.isConst) {
7676
var value = variable.computeConstantValue();
7777
if (value != null) return _stringify(value);
@@ -116,8 +116,8 @@ class ConstantsDataExtractor extends AstDataExtractor<String> {
116116
}
117117
// TODO(paulberry): Support object constants.
118118
} else if (type is FunctionType) {
119-
var element = value.toFunctionValue()!;
120-
return 'Function(${element.name},type=${_stringifyType(value.type!)})';
119+
var element = value.toFunctionValue2()!;
120+
return 'Function(${element.name3},type=${_stringifyType(value.type!)})';
121121
}
122122
throw UnimplementedError('_stringify for type $type');
123123
}

pkg/analyzer/test/id_tests/definite_assignment_test.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'dart:io';
77
import 'package:_fe_analyzer_shared/src/testing/id.dart' show ActualData, Id;
88
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
99
import 'package:analyzer/dart/ast/ast.dart';
10-
import 'package:analyzer/dart/element/element.dart';
10+
import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/error/error.dart';
1212
import 'package:analyzer/src/dart/analysis/testing_data.dart';
1313
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
@@ -50,11 +50,9 @@ class _DefiniteAssignmentDataComputer extends DataComputer<String> {
5050
@override
5151
void computeUnitData(TestingData testingData, CompilationUnit unit,
5252
Map<Id, ActualData<String>> actualMap) {
53-
var unitElement = unit.declaredElement!;
54-
var flowResult = testingData.uriToFlowAnalysisData[unitElement.source.uri]!;
55-
_DefiniteAssignmentDataExtractor(
56-
unitElement.source.uri, actualMap, flowResult)
57-
.run(unit);
53+
var unitUri = unit.declaredFragment!.source.uri;
54+
var flowResult = testingData.uriToFlowAnalysisData[unitUri]!;
55+
_DefiniteAssignmentDataExtractor(unitUri, actualMap, flowResult).run(unit);
5856
}
5957
}
6058

@@ -67,8 +65,9 @@ class _DefiniteAssignmentDataExtractor extends AstDataExtractor<String> {
6765
@override
6866
String? computeNodeValue(Id id, AstNode node) {
6967
if (node is SimpleIdentifier && node.inGetterContext()) {
70-
var element = node.staticElement;
71-
if (element is LocalVariableElement || element is ParameterElement) {
68+
var element = node.element;
69+
if (element is LocalVariableElement2 ||
70+
element is FormalParameterElement) {
7271
if (_flowResult.notDefinitelyAssigned.contains(node)) {
7372
return 'unassigned';
7473
}

pkg/analyzer/test/id_tests/definite_unassignment_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'dart:io';
77
import 'package:_fe_analyzer_shared/src/testing/id.dart' show ActualData, Id;
88
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
99
import 'package:analyzer/dart/ast/ast.dart';
10-
import 'package:analyzer/dart/element/element.dart';
10+
import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/error/error.dart';
1212
import 'package:analyzer/src/dart/analysis/testing_data.dart';
1313
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
@@ -50,10 +50,9 @@ class _DefiniteAssignmentDataComputer extends DataComputer<String> {
5050
@override
5151
void computeUnitData(TestingData testingData, CompilationUnit unit,
5252
Map<Id, ActualData<String>> actualMap) {
53-
var unitElement = unit.declaredElement!;
54-
var flowResult = testingData.uriToFlowAnalysisData[unitElement.source.uri]!;
55-
_DefiniteUnassignmentDataExtractor(
56-
unitElement.source.uri, actualMap, flowResult)
53+
var unitUri = unit.declaredFragment!.source.uri;
54+
var flowResult = testingData.uriToFlowAnalysisData[unitUri]!;
55+
_DefiniteUnassignmentDataExtractor(unitUri, actualMap, flowResult)
5756
.run(unit);
5857
}
5958
}
@@ -67,8 +66,9 @@ class _DefiniteUnassignmentDataExtractor extends AstDataExtractor<String> {
6766
@override
6867
String? computeNodeValue(Id id, AstNode node) {
6968
if (node is SimpleIdentifier && node.inGetterContext()) {
70-
var element = node.staticElement;
71-
if (element is LocalVariableElement || element is ParameterElement) {
69+
var element = node.element;
70+
if (element is LocalVariableElement2 ||
71+
element is FormalParameterElement) {
7272
if (_flowResult.definitelyUnassigned.contains(node)) {
7373
return 'unassigned';
7474
}

pkg/analyzer/test/id_tests/exhaustiveness_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ class _ExhaustivenessDataComputer extends DataComputer<Features> {
4949
@override
5050
void computeUnitData(TestingData testingData, CompilationUnit unit,
5151
Map<Id, ActualData<Features>> actualMap) {
52-
var unitElement = unit.declaredElement!;
53-
var exhaustivenessData =
54-
testingData.uriToExhaustivenessData[unitElement.source.uri]!;
55-
_ExhaustivenessDataExtractor(
56-
unitElement.source.uri, actualMap, exhaustivenessData)
52+
var unitUri = unit.declaredFragment!.source.uri;
53+
var exhaustivenessData = testingData.uriToExhaustivenessData[unitUri]!;
54+
_ExhaustivenessDataExtractor(unitUri, actualMap, exhaustivenessData)
5755
.run(unit);
5856
}
5957
}

pkg/analyzer/test/id_tests/inferred_type_arguments_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ class _InferredTypeArgumentsDataComputer extends DataComputer<List<DartType>> {
3838
@override
3939
void computeUnitData(TestingData testingData, CompilationUnit unit,
4040
Map<Id, ActualData<List<DartType>>> actualMap) {
41-
_InferredTypeArgumentsDataExtractor(
42-
unit.declaredElement!.source.uri, actualMap)
43-
.run(unit);
41+
var unitUri = unit.declaredFragment!.source.uri;
42+
_InferredTypeArgumentsDataExtractor(unitUri, actualMap).run(unit);
4443
}
4544
}
4645

pkg/analyzer/test/id_tests/inferred_variable_types_test.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ class _InferredVariableTypesDataComputer extends DataComputer<DartType> {
3838
@override
3939
void computeUnitData(TestingData testingData, CompilationUnit unit,
4040
Map<Id, ActualData<DartType>> actualMap) {
41-
_InferredVariableTypesDataExtractor(
42-
unit.declaredElement!.source.uri, actualMap)
43-
.run(unit);
41+
var unitUri = unit.declaredFragment!.source.uri;
42+
_InferredVariableTypesDataExtractor(unitUri, actualMap).run(unit);
4443
}
4544
}
4645

@@ -50,23 +49,23 @@ class _InferredVariableTypesDataExtractor extends AstDataExtractor<DartType> {
5049
@override
5150
DartType? computeNodeValue(Id id, AstNode node) {
5251
if (node is VariableDeclaration) {
53-
var element = node.declaredElement!;
52+
var element = node.declaredFragment!.element;
5453
if (element.hasImplicitType) {
5554
return element.type;
5655
}
5756
} else if (node is FormalParameter) {
58-
var element = node.declaredElement!;
57+
var element = node.declaredFragment!.element;
5958
if (element.hasImplicitType) {
6059
return element.type;
6160
}
6261
} else if (node is FunctionDeclarationStatement) {
63-
var element = node.functionDeclaration.declaredElement!;
62+
var element = node.functionDeclaration.declaredFragment!.element;
6463
if (element.hasImplicitReturnType) {
6564
return element.returnType;
6665
}
6766
} else if (node is FunctionExpression &&
6867
node.parent is! FunctionDeclaration) {
69-
var element = node.declaredElement!;
68+
var element = node.declaredFragment!.element;
7069
if (element.hasImplicitReturnType) {
7170
return element.returnType;
7271
}

pkg/analyzer/test/id_tests/metadata_evaluate_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:_fe_analyzer_shared/src/testing/id.dart';
88
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
99
import 'package:_fe_analyzer_shared/src/testing/metadata_helper.dart';
1010
import 'package:analyzer/dart/ast/ast.dart';
11-
import 'package:analyzer/dart/element/element.dart';
11+
import 'package:analyzer/dart/element/element2.dart';
1212
import 'package:analyzer/src/dart/analysis/testing_data.dart';
1313
import 'package:analyzer/src/dart/element/element.dart';
1414
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
@@ -42,8 +42,8 @@ class _MetadataDataComputer extends DataComputer<String> {
4242
@override
4343
void computeUnitData(TestingData testingData, CompilationUnit unit,
4444
Map<Id, ActualData<String>> actualMap) {
45-
_MetadataDataExtractor(unit.declaredElement!.source.uri, actualMap)
46-
.run(unit);
45+
var unitUri = unit.declaredFragment!.source.uri;
46+
_MetadataDataExtractor(unitUri, actualMap).run(unit);
4747
}
4848
}
4949

@@ -55,10 +55,10 @@ class _MetadataDataExtractor extends AstDataExtractor<String> {
5555
@override
5656
String? computeNodeValue(Id id, AstNode node) {
5757
if (node is Declaration) {
58-
Element? element = node.declaredElement;
59-
if (element != null) {
58+
var element = node.declaredFragment?.element;
59+
if (element case Annotatable annotatable) {
6060
List<String> list = [];
61-
for (ElementAnnotation annotation in element.metadata) {
61+
for (var annotation in annotatable.metadata2.annotations) {
6262
if (annotation is ElementAnnotationImpl) {
6363
var resolved = parseAnnotation(annotation);
6464
list.addAll(evaluationToText(resolved,

0 commit comments

Comments
 (0)