Skip to content

Commit 150c791

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate SimpleIdentifierResolver.
Change-Id: I4ab857ab64ae787bc4106f2f2a9c81e5fd7f4f8b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407260 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3396a7b commit 150c791

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:analyzer/dart/ast/token.dart';
8-
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
97
import 'package:analyzer/dart/element/type.dart';
108
import 'package:analyzer/error/listener.dart';
119
import 'package:analyzer/src/dart/ast/ast.dart';
@@ -52,14 +50,14 @@ class SimpleIdentifierResolver with ScopeHelpers {
5250
/// @return the type that should be recorded for a node that resolved to the given accessor
5351
///
5452
// TODO(scheglov): this is duplicate
55-
DartType _getTypeOfProperty(PropertyAccessorElement accessor) {
53+
DartType _getTypeOfProperty(PropertyAccessorElement2 accessor) {
5654
FunctionType functionType = accessor.type;
57-
if (accessor.isSetter) {
55+
if (accessor is SetterElement) {
5856
var parameterTypes = functionType.normalParameterTypes;
5957
if (parameterTypes.isNotEmpty) {
6058
return parameterTypes[0];
6159
}
62-
var getter = accessor.variable2?.getter;
60+
var getter = accessor.variable3?.getter2;
6361
if (getter != null) {
6462
functionType = getter.type;
6563
return functionType.returnType;
@@ -135,8 +133,8 @@ class SimpleIdentifierResolver with ScopeHelpers {
135133
if (node.inDeclarationContext()) {
136134
return null;
137135
}
138-
if (node.staticElement is LocalVariableElement ||
139-
node.staticElement is ParameterElement) {
136+
if (node.element is LocalVariableElement2 ||
137+
node.element is FormalParameterElement) {
140138
return null;
141139
}
142140
var parent = node.parent;
@@ -187,9 +185,9 @@ class SimpleIdentifierResolver with ScopeHelpers {
187185
return null;
188186
}
189187

190-
var element = hasRead ? result.readElement : result.writeElement;
188+
var element = hasRead ? result.readElement2 : result.writeElement2;
191189

192-
var enclosingClass = _resolver.enclosingClass?.augmented.firstFragment;
190+
var enclosingClass = _resolver.enclosingClass2;
193191
if (_isFactoryConstructorReturnType(node) &&
194192
!identical(element, enclosingClass)) {
195193
errorReporter.atNode(
@@ -200,15 +198,17 @@ class SimpleIdentifierResolver with ScopeHelpers {
200198
!identical(element, enclosingClass)) {
201199
// This error is now reported by the parser.
202200
element = null;
203-
} else if (element is PrefixElement && !_isValidAsPrefix(node)) {
204-
errorReporter.atNode(
205-
node,
206-
CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
207-
arguments: [element.name],
208-
);
201+
} else if (element is PrefixElement2 && !_isValidAsPrefix(node)) {
202+
if (element.name3 case var name?) {
203+
errorReporter.atNode(
204+
node,
205+
CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
206+
arguments: [name],
207+
);
208+
}
209209
} else if (element == null) {
210210
// TODO(brianwilkerson): Recover from this error.
211-
if (node.name == "await" && _resolver.enclosingFunction != null) {
211+
if (node.name == "await" && _resolver.enclosingFunction2 != null) {
212212
errorReporter.atNode(
213213
node,
214214
CompileTimeErrorCode.UNDEFINED_IDENTIFIER_AWAIT,
@@ -222,7 +222,7 @@ class SimpleIdentifierResolver with ScopeHelpers {
222222
);
223223
}
224224
}
225-
node.staticElement = element;
225+
node.element = element;
226226
return result;
227227
}
228228

@@ -233,52 +233,52 @@ class SimpleIdentifierResolver with ScopeHelpers {
233233
return;
234234
}
235235

236-
var element = node.staticElement;
236+
var element = node.element;
237237

238-
if (element is ExtensionElement) {
238+
if (element is ExtensionElement2) {
239239
_setExtensionIdentifierType(node);
240240
inferenceLogWriter?.recordExpressionWithNoType(node);
241241
return;
242242
}
243243

244244
DartType staticType = InvalidTypeImpl.instance;
245-
if (element is InterfaceElement) {
245+
if (element is InterfaceElement2) {
246246
if (_isExpressionIdentifier(node)) {
247247
node.recordStaticType(_typeProvider.typeType, resolver: _resolver);
248248
} else {
249249
inferenceLogWriter?.recordExpressionWithNoType(node);
250250
}
251251
return;
252-
} else if (element is TypeAliasElement) {
252+
} else if (element is TypeAliasElement2) {
253253
if (_isExpressionIdentifier(node) ||
254254
element.aliasedType is! InterfaceType) {
255255
node.recordStaticType(_typeProvider.typeType, resolver: _resolver);
256256
} else {
257257
inferenceLogWriter?.recordExpressionWithNoType(node);
258258
}
259259
return;
260-
} else if (element is MethodElement) {
260+
} else if (element is MethodElement2) {
261261
staticType = element.type;
262-
} else if (element is PropertyAccessorElement) {
262+
} else if (element is PropertyAccessorElement2) {
263263
staticType = propertyResult?.getType ?? _getTypeOfProperty(element);
264-
} else if (element is ExecutableElement) {
264+
} else if (element is ExecutableElement2) {
265265
staticType = element.type;
266-
} else if (element is TypeParameterElement) {
266+
} else if (element is TypeParameterElement2) {
267267
staticType = _typeProvider.typeType;
268-
} else if (element is VariableElement) {
268+
} else if (element is VariableElement2) {
269269
staticType = _resolver.localVariableTypeProvider
270270
.getType(node, isRead: node.inGetterContext());
271-
} else if (element is PrefixElement) {
271+
} else if (element is PrefixElement2) {
272272
var parent = node.parent;
273273
if (parent is PrefixedIdentifier && parent.prefix == node ||
274274
parent is MethodInvocation && parent.target == node) {
275275
inferenceLogWriter?.recordExpressionWithNoType(node);
276276
return;
277277
}
278278
staticType = InvalidTypeImpl.instance;
279-
} else if (element is DynamicElementImpl) {
279+
} else if (element is DynamicElementImpl2) {
280280
staticType = _typeProvider.typeType;
281-
} else if (element is NeverElementImpl) {
281+
} else if (element is NeverElementImpl2) {
282282
staticType = _typeProvider.typeType;
283283
} else {
284284
staticType = InvalidTypeImpl.instance;

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,24 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
430430
/// current node is inside a function body.
431431
BodyInferenceContext? get bodyContext => _bodyContext;
432432

433+
/// The class containing the AST nodes being visited,
434+
/// or `null` if we are not in the scope of a class.
435+
InterfaceElementImpl2? get enclosingClass2 {
436+
return enclosingClass?.asElement2;
437+
}
438+
433439
/// Return the element representing the function containing the current node,
434440
/// or `null` if the current node is not contained in a function.
435441
///
436442
/// @return the element representing the function containing the current node
437443
ExecutableElement? get enclosingFunction => _enclosingFunction;
438444

445+
/// Return the element representing the function containing the current node,
446+
/// or `null` if the current node is not contained in a function.
447+
///
448+
/// @return the element representing the function containing the current node
449+
ExecutableElement2? get enclosingFunction2 => _enclosingFunction.asElement2;
450+
439451
@override
440452
FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
441453
PromotableElementImpl2, SharedTypeView> get flow => flowAnalysis.flow!;

0 commit comments

Comments
 (0)