Skip to content

Commit 8d845f6

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Migrate signature computers to new element model
Change-Id: I72d5c9f841d9f85b7f9597a309b14ba4b7e0d3a8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391800 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 1d7b790 commit 8d845f6

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ lib/src/computer/computer_highlights.dart
4242
lib/src/computer/computer_outline.dart
4343
lib/src/computer/computer_overrides.dart
4444
lib/src/computer/computer_selection_ranges.dart
45+
lib/src/computer/computer_signature.dart
46+
lib/src/computer/computer_type_arguments_signature.dart
4547
lib/src/context_manager.dart
4648
lib/src/domain_analysis_flags.dart
4749
lib/src/domains/analysis/occurrences.dart

pkg/analysis_server/lib/src/computer/computer_signature.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:analysis_server/src/computer/computer_documentation.dart';
66
import 'package:analysis_server/src/protocol_server.dart' hide Element;
77
import 'package:analysis_server/src/utilities/extensions/ast.dart';
88
import 'package:analyzer/dart/ast/ast.dart';
9-
import 'package:analyzer/dart/element/element.dart';
9+
import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/src/dart/ast/element_locator.dart';
1212
import 'package:analyzer/src/dart/ast/utilities.dart';
@@ -40,33 +40,35 @@ class DartUnitSignatureComputer {
4040
return null;
4141
}
4242
String? name;
43-
Element? element;
44-
List<ParameterElement>? parameters;
43+
Element2? element;
44+
List<FormalParameterElement>? parameters;
4545
var parent = argumentList.parent;
4646
if (parent is MethodInvocation) {
4747
name = parent.methodName.name;
48-
element = ElementLocator.locate(parent);
49-
parameters = element is FunctionTypedElement ? element.parameters : null;
48+
element = ElementLocator.locate2(parent);
49+
parameters =
50+
element is FunctionTypedElement2 ? element.formalParameters : null;
5051
} else if (parent is InstanceCreationExpression) {
5152
name = parent.constructorName.type.qualifiedName;
5253
var constructorName = parent.constructorName.name;
5354
if (constructorName != null) {
5455
name += '.${constructorName.name}';
5556
}
56-
element = ElementLocator.locate(parent);
57-
parameters = element is FunctionTypedElement ? element.parameters : null;
57+
element = ElementLocator.locate2(parent);
58+
parameters =
59+
element is FunctionTypedElement2 ? element.formalParameters : null;
5860
} else if (parent
5961
case FunctionExpressionInvocation(function: Identifier function)) {
6062
name = function.name;
6163

6264
if (function.staticType case FunctionType functionType) {
6365
// Standard function expression.
64-
element = function.staticElement;
65-
parameters = functionType.parameters;
66-
} else if (parent.staticElement case ExecutableElement staticElement) {
66+
element = function.element;
67+
parameters = functionType.formalParameters;
68+
} else if (parent.element case ExecutableElement2 executableElement) {
6769
// Callable class instance (where we'll look at the `call` method).
68-
element = staticElement;
69-
parameters = staticElement.parameters;
70+
element = executableElement;
71+
parameters = executableElement.formalParameters;
7072
}
7173
}
7274

@@ -76,7 +78,7 @@ class DartUnitSignatureComputer {
7678

7779
_argumentList = argumentList;
7880
var convertedParameters = parameters.map((p) => _convertParam(p)).toList();
79-
var dartdoc = _documentationComputer.computePreferred(
81+
var dartdoc = _documentationComputer.computePreferred2(
8082
element,
8183
documentationPreference,
8284
);
@@ -88,7 +90,7 @@ class DartUnitSignatureComputer {
8890
);
8991
}
9092

91-
ParameterInfo _convertParam(ParameterElement param) {
93+
ParameterInfo _convertParam(FormalParameterElement param) {
9294
return ParameterInfo(
9395
param.isOptionalNamed
9496
? ParameterKind.OPTIONAL_NAMED

pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:analysis_server/src/computer/computer_documentation.dart';
77
import 'package:analysis_server/src/lsp/dartdoc.dart';
88
import 'package:analysis_server/src/lsp/mapping.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/src/dart/ast/element_locator.dart';
1212
import 'package:analyzer/src/dart/ast/utilities.dart';
1313
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
@@ -43,27 +43,27 @@ class DartTypeArgumentsSignatureComputer {
4343
return null;
4444
}
4545
var parent = argumentList.parent;
46-
Element? element;
46+
Element2? element;
4747
if (parent is NamedType) {
48-
element = parent.element;
48+
element = parent.element2;
4949
} else if (parent is MethodInvocation) {
50-
element = ElementLocator.locate(parent.methodName);
50+
element = ElementLocator.locate2(parent.methodName);
5151
}
52-
if (element is! TypeParameterizedElement ||
53-
element.typeParameters.isEmpty) {
52+
if (element is! TypeParameterizedElement2 ||
53+
element.typeParameters2.isEmpty) {
5454
return null;
5555
}
5656

5757
_argumentList = argumentList;
5858

59-
var label = element.getDisplayString();
60-
var documentation = _documentationComputer.computePreferred(
59+
var label = element.displayString2();
60+
var documentation = _documentationComputer.computePreferred2(
6161
element, documentationPreference);
6262

6363
return _toSignatureHelp(
6464
label,
6565
cleanDartdoc(documentation),
66-
element.typeParameters,
66+
element.typeParameters2,
6767
);
6868
}
6969

@@ -85,11 +85,11 @@ class DartTypeArgumentsSignatureComputer {
8585
lsp.SignatureHelp? _toSignatureHelp(
8686
String label,
8787
String? documentation,
88-
List<TypeParameterElement> typeParameters,
88+
List<TypeParameterElement2> typeParameters,
8989
) {
9090
var parameters = typeParameters
9191
.map((param) => lsp.ParameterInformation(
92-
label: param.getDisplayString(),
92+
label: param.displayString2(),
9393
))
9494
.toList();
9595

0 commit comments

Comments
 (0)