Skip to content

Commit 7041cda

Browse files
bwilkersonCommit Queue
authored andcommitted
[Migrate] CorrectionProducer
Change-Id: Ia8fba6d745d04cef88d1beb7e6da7ed15d23fcb2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402588 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fe9c469 commit 7041cda

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
lib/edit/dart/correction_producer.dart

pkg/analysis_server_plugin/lib/edit/dart/correction_producer.dart

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:analysis_server_plugin/src/utilities/selection.dart';
1111
import 'package:analyzer/dart/analysis/analysis_options.dart';
1212
import 'package:analyzer/dart/analysis/code_style_options.dart';
1313
import 'package:analyzer/dart/analysis/results.dart';
14-
import 'package:analyzer/dart/element/element.dart';
1514
import 'package:analyzer/dart/element/element2.dart';
1615
import 'package:analyzer/dart/element/nullability_suffix.dart';
1716
import 'package:analyzer/dart/element/type.dart';
@@ -339,10 +338,6 @@ abstract class MultiCorrectionProducer
339338

340339
CorrectionProducerContext get context => _context;
341340

342-
/// The library element for the library in which a correction is being
343-
/// produced.
344-
LibraryElement get libraryElement => unitResult.libraryElement;
345-
346341
/// The library element for the library in which a correction is being
347342
/// produced.
348343
LibraryElement2 get libraryElement2 => unitResult.libraryElement2;
@@ -375,7 +370,7 @@ abstract class ResolvedCorrectionProducer
375370
.getAnalysisOptionsForFile(unitResult.file);
376371

377372
InheritanceManager3 get inheritanceManager {
378-
return (libraryElement as LibraryElementImpl).session.inheritanceManager;
373+
return (libraryElement2 as LibraryElementImpl).session.inheritanceManager;
379374
}
380375

381376
/// Whether [node] is in a static context.
@@ -394,10 +389,6 @@ abstract class ResolvedCorrectionProducer
394389
return method != null && method.isStatic;
395390
}
396391

397-
/// The library element for the library in which a correction is being
398-
/// produced.
399-
LibraryElement get libraryElement => unitResult.libraryElement;
400-
401392
/// The library element for the library in which a correction is being
402393
/// produced.
403394
LibraryElement2 get libraryElement2 => unitResult.libraryElement2;
@@ -464,21 +455,6 @@ abstract class ResolvedCorrectionProducer
464455
return null;
465456
}
466457

467-
/// Returns the class element associated with the [target], or `null` if there
468-
/// is no such element.
469-
InterfaceElement? getTargetInterfaceElement(Expression target) {
470-
var type = target.staticType;
471-
if (type is InterfaceType) {
472-
return type.element;
473-
} else if (target is Identifier) {
474-
var element = target.staticElement;
475-
if (element is InterfaceElement) {
476-
return element;
477-
}
478-
}
479-
return null;
480-
}
481-
482458
/// Returns the class element associated with the [target], or `null` if there
483459
/// is no such element.
484460
InterfaceElement2? getTargetInterfaceElement2(Expression target) {
@@ -512,7 +488,7 @@ abstract class ResolvedCorrectionProducer
512488
if (conditionalExpression.condition == expression) {
513489
return _coreTypeBool;
514490
} else {
515-
var type = conditionalExpression.staticParameterElement?.type;
491+
var type = conditionalExpression.correspondingParameter?.type;
516492
if (type is InterfaceType && type.isDartCoreFunction) {
517493
return FunctionTypeImpl(
518494
typeFormals: const [],
@@ -526,19 +502,19 @@ abstract class ResolvedCorrectionProducer
526502
}
527503
// `=> myFunction();`.
528504
if (parent is ExpressionFunctionBody) {
529-
var executable = expression.enclosingExecutableElement;
505+
var executable = expression.enclosingExecutableElement2;
530506
return executable?.returnType;
531507
}
532508
// `return myFunction();`.
533509
if (parent is ReturnStatement) {
534-
var executable = expression.enclosingExecutableElement;
510+
var executable = expression.enclosingExecutableElement2;
535511
return executable?.returnType;
536512
}
537513
// `int v = myFunction();`.
538514
if (parent is VariableDeclaration) {
539515
var variableDeclaration = parent;
540516
if (variableDeclaration.initializer == expression) {
541-
var variableElement = variableDeclaration.declaredElement;
517+
var variableElement = variableDeclaration.declaredFragment?.element;
542518
if (variableElement != null) {
543519
return variableElement.type;
544520
}
@@ -561,9 +537,9 @@ abstract class ResolvedCorrectionProducer
561537
return assignment.writeType;
562538
} else {
563539
// `v += myFunction();`.
564-
var method = assignment.staticElement;
540+
var method = assignment.element;
565541
if (method != null) {
566-
var parameters = method.parameters;
542+
var parameters = method.formalParameters;
567543
if (parameters.length == 1) {
568544
return parameters[0].type;
569545
}
@@ -574,17 +550,17 @@ abstract class ResolvedCorrectionProducer
574550
// `v + myFunction();`.
575551
if (parent is BinaryExpression) {
576552
var binary = parent;
577-
var method = binary.staticElement;
553+
var method = binary.element;
578554
if (method != null) {
579555
if (binary.rightOperand == expression) {
580-
var parameters = method.parameters;
556+
var parameters = method.formalParameters;
581557
return parameters.length == 1 ? parameters[0].type : null;
582558
}
583559
}
584560
}
585561
// `foo( myFunction() );`.
586562
if (parent is ArgumentList) {
587-
var parameter = expression.staticParameterElement;
563+
var parameter = expression.correspondingParameter;
588564
return parameter?.type;
589565
}
590566
// `bool`.

pkg/analyzer/lib/src/utilities/extensions/ast.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
89
import 'package:analyzer/src/dart/element/element.dart';
910

1011
extension AstNodeExtension on AstNode {
@@ -42,6 +43,22 @@ extension AstNodeExtension on AstNode {
4243
return null;
4344
}
4445

46+
/// The [ExecutableElement2] of the enclosing executable [AstNode].
47+
ExecutableElement2? get enclosingExecutableElement2 {
48+
for (var node in withParents) {
49+
if (node is FunctionDeclaration) {
50+
return node.declaredFragment?.element;
51+
}
52+
if (node is ConstructorDeclaration) {
53+
return node.declaredFragment?.element;
54+
}
55+
if (node is MethodDeclaration) {
56+
return node.declaredFragment?.element;
57+
}
58+
}
59+
return null;
60+
}
61+
4562
AstNode? get enclosingUnitChild {
4663
for (var node in withParents) {
4764
if (node.parent is CompilationUnit) {

pkg/linter/analyzer_use_new_elements.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)