Skip to content

Commit 76e3198

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate NullSafeApiVerifier.
Change-Id: I012630edfef67c69cd8d6c77fbb79f20ba7ba521 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395041 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 6888624 commit 76e3198

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ lib/src/error/imports_verifier.dart
114114
lib/src/error/inheritance_override.dart
115115
lib/src/error/literal_element_verifier.dart
116116
lib/src/error/must_call_super_verifier.dart
117-
lib/src/error/null_safe_api_verifier.dart
118117
lib/src/error/nullable_dereference_verifier.dart
119118
lib/src/error/override_verifier.dart
120119
lib/src/error/redeclare_verifier.dart

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ abstract class ConstructorElement2 implements ExecutableElement2 {
292292
/// resolved.
293293
ConstructorElement2? get redirectedConstructor2;
294294

295+
@override
296+
InterfaceType get returnType;
297+
295298
/// The constructor of the superclass that this constructor invokes, or
296299
/// `null` if this constructor redirects to another constructor, or if the
297300
/// library containing this constructor has not yet been resolved.
@@ -1814,7 +1817,6 @@ abstract class Metadata {
18141817
///
18151818
/// Clients may not extend, implement or mix-in this class.
18161819
abstract class MethodElement2 implements ExecutableElement2 {
1817-
18181820
/// The name of the method that can be implemented by a class to allow its
18191821
/// instances to be invoked as if they were a function.
18201822
static final String CALL_METHOD_NAME = "call";

pkg/analyzer/lib/src/dart/analysis/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
11291129
var seenConstructors = <ConstructorElement?>{};
11301130
while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
11311131
var enclosing = constructor.enclosingElement3;
1132-
if (enclosing is ClassElement && enclosing.isMixinApplication) {
1132+
if (enclosing is ClassElementImpl && enclosing.isMixinApplication) {
11331133
var superInvocation = constructor.constantInitializers
11341134
.whereType<SuperConstructorInvocation>()
11351135
.singleOrNull;

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ class ConstructorElementImpl extends ExecutableElementImpl
14221422
}
14231423

14241424
@override
1425-
InterfaceElement get enclosingElement3 =>
1425+
InterfaceElementImpl get enclosingElement3 =>
14261426
super.enclosingElement3 as InterfaceElementImpl;
14271427

14281428
@override
@@ -1433,7 +1433,7 @@ class ConstructorElementImpl extends ExecutableElementImpl
14331433
bool get hasLiteral {
14341434
if (super.hasLiteral) return true;
14351435
var enclosingElement = enclosingElement3;
1436-
if (enclosingElement is! ExtensionTypeElement) return false;
1436+
if (enclosingElement is! ExtensionTypeElementImpl) return false;
14371437
return this == enclosingElement.primaryConstructor &&
14381438
enclosingElement.hasLiteral;
14391439
}
@@ -1584,8 +1584,8 @@ class ConstructorElementImpl2 extends ExecutableElementImpl2
15841584
ConstructorElement2 get baseElement => this;
15851585

15861586
@override
1587-
InterfaceElement2 get enclosingElement2 =>
1588-
(firstFragment._enclosingElement3 as InterfaceFragment).element;
1587+
InterfaceElementImpl2 get enclosingElement2 =>
1588+
firstFragment.enclosingElement3.element;
15891589

15901590
@override
15911591
bool get isConst => firstFragment.isConst;
@@ -1608,6 +1608,11 @@ class ConstructorElementImpl2 extends ExecutableElementImpl2
16081608
as ConstructorElementImpl?)
16091609
?.element;
16101610

1611+
@override
1612+
InterfaceType get returnType {
1613+
return firstFragment.returnType;
1614+
}
1615+
16111616
@override
16121617
ConstructorElement2? get superConstructor2 =>
16131618
(firstFragment.superConstructor?.declaration as ConstructorElementImpl?)
@@ -3396,7 +3401,7 @@ class ElementLocationImpl implements ElementLocation {
33963401
}
33973402
ancestor = ancestor.enclosingElement2;
33983403
} else {
3399-
components.insert(0, ancestor.identifier);
3404+
components.insert(0, ancestor.identifier);
34003405
if (ancestor is LocalFunctionElementImpl) {
34013406
ancestor = (ancestor.wrappedElement._enclosingElement3
34023407
as ExecutableElementImpl)
@@ -5745,6 +5750,9 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
57455750
@override
57465751
String get displayName => name;
57475752

5753+
@override
5754+
InterfaceElementImpl2 get element;
5755+
57485756
@override
57495757
List<InterfaceType> get interfaces {
57505758
linkedData?.read(this);

pkg/analyzer/lib/src/dart/micro/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ConstructorElement? _getActualConstructorElement(
4444
var seenConstructors = <ConstructorElement?>{};
4545
while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
4646
var enclosing = constructor.enclosingElement3;
47-
if (enclosing is ClassElement && enclosing.isMixinApplication) {
47+
if (enclosing is ClassElementImpl && enclosing.isMixinApplication) {
4848
var superInvocation = constructor.constantInitializers
4949
.whereType<SuperConstructorInvocation>()
5050
.singleOrNull;

pkg/analyzer/lib/src/error/null_safe_api_verifier.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class NullSafeApiVerifier {
2525
/// Reports an error if the expression creates a `Future<T>.value` with a non-
2626
/// nullable value `T` and an argument that is effectively `null`.
2727
void instanceCreation(InstanceCreationExpression expression) {
28-
var constructor = expression.constructorName.staticElement;
28+
var constructor = expression.constructorName.element;
2929
if (constructor == null) return;
3030

3131
var type = constructor.returnType;
32-
var isFutureValue = type.isDartAsyncFuture && constructor.name == 'value';
32+
var isFutureValue = type.isDartAsyncFuture && constructor.name3 == 'value';
3333

3434
if (isFutureValue) {
3535
_checkTypes(expression, 'Future.value', type.typeArguments.single,
@@ -43,10 +43,10 @@ class NullSafeApiVerifier {
4343
var targetType = node.realTarget?.staticType;
4444
if (targetType is! InterfaceType) return;
4545

46-
var targetClass = targetType.element;
46+
var targetClass = targetType.element3;
4747

48-
if (targetClass.library.isDartAsync == true &&
49-
targetClass.name == 'Completer' &&
48+
if (targetClass.library2.isDartAsync == true &&
49+
targetClass.name3 == 'Completer' &&
5050
node.methodName.name == 'complete') {
5151
_checkTypes(node, 'Completer.complete', targetType.typeArguments.single,
5252
node.argumentList);

0 commit comments

Comments
 (0)