Skip to content

Commit

Permalink
Elements. Migrate ElementsTypesMixin, part#2
Browse files Browse the repository at this point in the history
Change-Id: I1438e2f2027c6e5fe3934497e4bd6d2de12a2575
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409541
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Feb 13, 2025
1 parent b755ee7 commit 61eeb2d
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 578 deletions.
14 changes: 8 additions & 6 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11456,7 +11456,6 @@ class TypeParameterElementImpl extends ElementImpl
return TypeParameterElementImpl2(
firstFragment: firstFragment,
name3: firstFragment.name.nullIfEmpty,
bound: firstFragment.bound,
);
}

Expand Down Expand Up @@ -11577,13 +11576,9 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
@override
final String? name3;

@override
TypeImpl? bound;

TypeParameterElementImpl2({
required this.firstFragment,
required this.name3,
required this.bound,
}) {
TypeParameterElementImpl? fragment = firstFragment;
while (fragment != null) {
Expand All @@ -11595,6 +11590,13 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
@override
TypeParameterElement2 get baseElement => this;

@override
TypeImpl? get bound => firstFragment.bound;

set bound(TypeImpl? value) {
firstFragment.bound = value;
}

@override
TypeImpl? get boundShared => bound;

Expand Down Expand Up @@ -11623,7 +11625,7 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2

shared.Variance get variance => firstFragment.variance;

set variance(shared.Variance value) {
set variance(shared.Variance? value) {
firstFragment.variance = value;
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/analyzer/lib/src/dart/element/type_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,10 @@ class TypeSystemImpl implements TypeSystem {
///
/// https://github.com/dart-lang/sdk/issues/27526#issuecomment-260021397
List<TypeImpl> instantiateTypeFormalsToBounds2(
List<TypeParameterElementImpl2> typeFormals,
List<TypeParameterElementImpl2> typeParameters,
{List<bool>? hasError,
Map<TypeParameterElement2, TypeImpl>? knownTypes}) {
int count = typeFormals.length;
int count = typeParameters.length;
if (count == 0) {
return const <TypeImpl>[];
}
Expand All @@ -832,7 +832,7 @@ class TypeSystemImpl implements TypeSystem {
// not ground
Map<TypeParameterElement2, TypeImpl> partials = {};

for (var typeParameter in typeFormals) {
for (var typeParameter in typeParameters) {
all.add(typeParameter);
if (!defaults.containsKey(typeParameter)) {
var bound = typeParameter.bound ?? DynamicTypeImpl.instance;
Expand Down Expand Up @@ -886,7 +886,7 @@ class TypeSystemImpl implements TypeSystem {
}

List<TypeImpl> orderedArguments =
typeFormals.map((p) => defaults[p]!).toFixedList();
typeParameters.map((p) => defaults[p]!).toFixedList();
return orderedArguments;
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/analyzer/lib/src/utilities/extensions/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:meta/meta.dart';

class MockLibraryImportElement implements Element2, PrefixFragment {
Expand Down Expand Up @@ -685,9 +684,6 @@ extension TypeParameterElement2Extension on TypeParameterElement2 {
return TypeParameterElementImpl2(
firstFragment: fragment,
name3: name3,
// TODO(paulberry): eliminate this cast by changing this extension to
// apply to `TypeParameterElementImpl2`.
bound: bound as TypeImpl?,
);
}
}
Expand All @@ -698,6 +694,12 @@ extension TypeParameterElementExtension on TypeParameterElement {
}
}

extension TypeParameterElementImpl2Extension on TypeParameterElementImpl2 {
TypeParameterElementImpl get asElement {
return firstFragment;
}
}

extension TypeParameterElementImplExtension on TypeParameterElementImpl {
TypeParameterElementImpl2 get asElement2 {
return element;
Expand Down
Loading

0 comments on commit 61eeb2d

Please sign in to comment.