Skip to content

Commit 6526f6c

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add more type specific extensions.
Change-Id: Ia69931e1777111f2b2396e89c552317e51e6b809 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396701 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 8183de1 commit 6526f6c

File tree

11 files changed

+101
-63
lines changed

11 files changed

+101
-63
lines changed

pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ class DartCompletionRequest {
403403
return analysisSession.inheritanceManager;
404404
}
405405

406-
/// Getter for the [Element2] repersentation of [libraryElement].
407-
LibraryElement2 get libraryElement2 =>
408-
libraryElement.asElement2 as LibraryElement2;
406+
/// Getter for the [Element2] representation of [libraryElement].
407+
LibraryElement2 get libraryElement2 => libraryElement.asElement2;
409408

410409
/// Answer the [DartType] for Object in dart:core
411410
InterfaceType get objectType => libraryElement.typeProvider.objectType;

pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class DeclarationHelper {
339339
if (matcherScore != -1) {
340340
collector.addSuggestion(
341341
ImportPrefixSuggestion(
342-
libraryElement: importedLibrary.asElement2 as LibraryElement2,
342+
libraryElement: importedLibrary.asElement2,
343343
prefixElement: prefixElement.asElement2,
344344
matcherScore: matcherScore,
345345
),
@@ -902,17 +902,17 @@ class DeclarationHelper {
902902
var suggestion = switch (element) {
903903
ClassElement() => ClassSuggestion(
904904
importData: null,
905-
element: element.asElement2 as ClassElement2,
905+
element: element.asElement2,
906906
matcherScore: matcherScore,
907907
),
908908
EnumElement() => EnumSuggestion(
909909
importData: null,
910-
element: element.asElement2 as EnumElement2,
910+
element: element.asElement2,
911911
matcherScore: matcherScore,
912912
),
913913
ExtensionElement() => ExtensionSuggestion(
914914
importData: null,
915-
element: element.asElement2 as ExtensionElement2,
915+
element: element.asElement2,
916916
matcherScore: matcherScore,
917917
),
918918
ExtensionTypeElement() => ExtensionTypeSuggestion(
@@ -928,7 +928,7 @@ class DeclarationHelper {
928928
),
929929
MixinElement() => MixinSuggestion(
930930
importData: null,
931-
element: element.asElement2 as MixinElement2,
931+
element: element.asElement2,
932932
matcherScore: matcherScore,
933933
),
934934
PropertyAccessorElement() => _createSuggestionFromTopLevelProperty(
@@ -937,7 +937,7 @@ class DeclarationHelper {
937937
),
938938
TopLevelVariableElement() => TopLevelVariableSuggestion(
939939
importData: null,
940-
element: element.asElement2 as TopLevelVariableElement2,
940+
element: element.asElement2,
941941
matcherScore: matcherScore,
942942
),
943943
TypeAliasElement() => TypeAliasSuggestion(
@@ -1498,7 +1498,7 @@ class DeclarationHelper {
14981498
if (variable is TopLevelVariableElement) {
14991499
return TopLevelVariableSuggestion(
15001500
importData: importData,
1501-
element: variable.asElement2 as TopLevelVariableElement2,
1501+
element: variable.asElement2,
15021502
matcherScore: matcherScore,
15031503
);
15041504
}
@@ -1559,7 +1559,7 @@ class DeclarationHelper {
15591559
if (matcherScore != -1) {
15601560
var suggestion = ClassSuggestion(
15611561
importData: importData,
1562-
element: element.asElement2 as ClassElement2,
1562+
element: element.asElement2,
15631563
matcherScore: matcherScore,
15641564
);
15651565
collector.addSuggestion(suggestion);
@@ -1667,7 +1667,7 @@ class DeclarationHelper {
16671667
if (matcherScore != -1) {
16681668
var suggestion = EnumSuggestion(
16691669
importData: importData,
1670-
element: element.asElement2 as EnumElement2,
1670+
element: element.asElement2,
16711671
matcherScore: matcherScore,
16721672
);
16731673
collector.addSuggestion(suggestion);
@@ -1696,7 +1696,7 @@ class DeclarationHelper {
16961696
if (matcherScore != -1) {
16971697
var suggestion = ExtensionSuggestion(
16981698
importData: importData,
1699-
element: element.asElement2 as ExtensionElement2,
1699+
element: element.asElement2,
17001700
matcherScore: matcherScore,
17011701
);
17021702
collector.addSuggestion(suggestion);
@@ -1857,7 +1857,7 @@ class DeclarationHelper {
18571857
if (matcherScore != -1) {
18581858
var suggestion = MixinSuggestion(
18591859
importData: importData,
1860-
element: element.asElement2 as MixinElement2,
1860+
element: element.asElement2,
18611861
matcherScore: matcherScore,
18621862
);
18631863
collector.addSuggestion(suggestion);
@@ -1878,7 +1878,7 @@ class DeclarationHelper {
18781878
var matcherScore = state.matcher.score(element.displayName);
18791879
if (matcherScore != -1) {
18801880
var suggestion = FormalParameterSuggestion(
1881-
element: element.asElement2 as FormalParameterElement,
1881+
element: element.asElement2,
18821882
distance: _variableDistance++,
18831883
matcherScore: matcherScore,
18841884
);
@@ -2054,7 +2054,7 @@ class DeclarationHelper {
20542054
if (matcherScore != -1) {
20552055
collector.addSuggestion(
20562056
SuperParameterSuggestion(
2057-
element: element.asElement2 as FormalParameterElement,
2057+
element: element.asElement2,
20582058
matcherScore: matcherScore,
20592059
),
20602060
);
@@ -2132,7 +2132,7 @@ class DeclarationHelper {
21322132
if (matcherScore != -1) {
21332133
var suggestion = TopLevelVariableSuggestion(
21342134
importData: importData,
2135-
element: element.asElement2 as TopLevelVariableElement2,
2135+
element: element.asElement2,
21362136
matcherScore: matcherScore,
21372137
);
21382138
collector.addSuggestion(suggestion);

pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import 'package:analyzer/dart/ast/syntactic_entity.dart';
2323
import 'package:analyzer/dart/ast/token.dart';
2424
import 'package:analyzer/dart/ast/visitor.dart';
2525
import 'package:analyzer/dart/element/element.dart';
26-
import 'package:analyzer/dart/element/element2.dart';
2726
import 'package:analyzer/dart/element/type.dart';
2827
import 'package:analyzer/source/source_range.dart';
2928
import 'package:analyzer/src/dart/ast/ast.dart';
@@ -380,7 +379,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
380379
var isWidget = isFlutterWidgetParameter(parameter);
381380
collector.addSuggestion(
382381
NamedArgumentSuggestion(
383-
parameter: parameter.asElement2 as FormalParameterElement,
382+
parameter: parameter.asElement2,
384383
appendColon: true,
385384
appendComma: appendComma,
386385
replacementLength: replacementLength,
@@ -2022,7 +2021,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
20222021
collector.addSuggestion(
20232022
NamedArgumentSuggestion(
20242023
parameter:
2025-
parameter.asElement2 as FormalParameterElement,
2024+
parameter.asElement2,
20262025
matcherScore: matcherScore,
20272026
appendColon: appendColon,
20282027
appendComma: false,

pkg/analysis_server/lib/src/services/search/hierarchy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Future<List<FormalParameterElement>> getHierarchyNamedParameters2(
306306
searchEngine,
307307
element.asElement as ParameterElement,
308308
);
309-
return result.map((e) => e.asElement2 as FormalParameterElement).toList();
309+
return result.map((e) => e.asElement2).toList();
310310
}
311311

312312
/// Returns non-synthetic members of the given [InterfaceElement] and its super

pkg/analysis_server/lib/src/services/search/search_engine_internal.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ class SearchMatchImpl implements SearchMatch {
292292
Element2 get element2 => element.asElement2!;
293293

294294
@override
295-
LibraryElement2 get libraryElement2 =>
296-
libraryElement.asElement2 as LibraryElement2;
295+
LibraryElement2 get libraryElement2 => libraryElement.asElement2;
297296

298297
@override
299298
String toString() {

pkg/analysis_server/test/abstract_single_unit.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
3232
late FindElement findElement;
3333
late FindElement2 findElement2;
3434

35-
LibraryElement2 get testLibraryElement2 =>
36-
testLibraryElement.asElement2 as LibraryElement2;
35+
LibraryElement2 get testLibraryElement2 => testLibraryElement.asElement2;
3736

3837
void addTestSource(String code) {
3938
testCode = code;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ final class ArgumentListImpl extends AstNodeImpl implements ArgumentList {
454454

455455
List<FormalParameterElement?>? get correspondingStaticParameters2 =>
456456
_correspondingStaticParameters
457-
?.map((parameter) => parameter.asElement2 as FormalParameterElement)
457+
?.map((parameter) => parameter?.asElement2)
458458
.toList();
459459

460460
@override

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6232,7 +6232,7 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
62326232

62336233
@override
62346234
ConstructorElement2? get unnamedConstructor2 =>
6235-
unnamedConstructor.asElement2 as ConstructorElement2;
6235+
unnamedConstructor?.asElement2;
62366236

62376237
@override
62386238
ConstructorElement? getNamedConstructor(String name) {
@@ -9903,20 +9903,12 @@ class SuperFormalParameterElementImpl2 extends FormalParameterElementImpl
99039903
SuperFormalParameterElementImpl2(super.firstFragment);
99049904

99059905
@override
9906-
SuperFormalParameterFragment get firstFragment =>
9907-
super.firstFragment as SuperFormalParameterFragment;
9906+
SuperFormalParameterElementImpl get firstFragment =>
9907+
super.firstFragment as SuperFormalParameterElementImpl;
99089908

99099909
@override
99109910
FormalParameterElement? get superConstructorParameter2 {
9911-
var superConstructorParameter =
9912-
(firstFragment as SuperFormalParameterElementImpl)
9913-
.superConstructorParameter;
9914-
return switch (superConstructorParameter) {
9915-
ParameterMember() =>
9916-
superConstructorParameter.asElement2 as FormalParameterElement?,
9917-
FormalParameterFragment()? => superConstructorParameter.element,
9918-
_ => null,
9919-
};
9911+
return firstFragment.superConstructorParameter?.asElement2;
99209912
}
99219913
}
99229914

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ class ConstructorMember extends ExecutableMember
111111
}
112112

113113
@override
114-
ConstructorElement2? get superConstructor2 =>
115-
superConstructor.asElement2 as ConstructorElement2;
114+
ConstructorElement2? get superConstructor2 => superConstructor?.asElement2;
116115

117116
@override
118117
ConstructorElement2 get _element2 => declaration.asElement2;
@@ -224,10 +223,8 @@ abstract class ExecutableMember extends Member
224223
Element2? get enclosingElement2 => _element2.enclosingElement2;
225224

226225
@override
227-
List<FormalParameterElement> get formalParameters => parameters
228-
.map((fragment) => fragment.asElement2 as FormalParameterElement?)
229-
.nonNulls
230-
.toList();
226+
List<FormalParameterElement> get formalParameters =>
227+
parameters.map((fragment) => fragment.asElement2).toList();
231228

232229
@override
233230
bool get hasImplicitReturnType => declaration.hasImplicitReturnType;
@@ -1174,8 +1171,7 @@ class ParameterMember extends VariableMember
11741171
@override
11751172
List<TypeParameterElement2> get typeParameters2 => _element2.typeParameters2;
11761173

1177-
FormalParameterElement get _element2 =>
1178-
declaration.asElement2 as FormalParameterElement;
1174+
FormalParameterElement get _element2 => declaration.asElement2;
11791175

11801176
@override
11811177
T? accept<T>(ElementVisitor<T> visitor) =>

0 commit comments

Comments
 (0)