Deprecate DartType.element, use specific element accessor for InterfaceType, TypeParameterType.

For `InterfaceType` keep `element2` deprecated and define
`InterfaceElement get element2` instead. Most changes are because
of this.

Change-Id: I13b888610fc707438c3c97b676f1460e7fc2b040
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253564
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-08-04 16:18:06 +00:00 committed by Commit Bot
parent 468507bd10
commit cbfad8f802
144 changed files with 1065 additions and 880 deletions

View file

@ -106,7 +106,7 @@ class _OverriddenElementsFinder {
final List<Element> _superElements = <Element>[];
final List<Element> _interfaceElements = <Element>[];
final Set<ClassElement> _visited = <ClassElement>{};
final Set<InterfaceElement> _visited = {};
factory _OverriddenElementsFinder(Element seed) {
var class_ = seed.enclosingElement3 as ClassElement;
@ -143,7 +143,7 @@ class _OverriddenElementsFinder {
return OverriddenElements(_seed, _superElements, _interfaceElements);
}
void _addInterfaceOverrides(ClassElement? class_, bool checkType) {
void _addInterfaceOverrides(InterfaceElement? class_, bool checkType) {
if (class_ == null) {
return;
}
@ -159,13 +159,16 @@ class _OverriddenElementsFinder {
}
// interfaces
for (var interfaceType in class_.interfaces) {
_addInterfaceOverrides(interfaceType.element, true);
_addInterfaceOverrides(interfaceType.element2, true);
}
// super
_addInterfaceOverrides(class_.supertype?.element, checkType);
if (class_ is ClassElement) {
_addInterfaceOverrides(class_.supertype?.element2, checkType);
}
}
void _addSuperOverrides(ClassElement? class_, {bool withThisType = true}) {
void _addSuperOverrides(InterfaceElement? class_,
{bool withThisType = true}) {
if (class_ == null) {
return;
}
@ -180,16 +183,20 @@ class _OverriddenElementsFinder {
}
}
_addSuperOverrides(class_.supertype?.element);
for (var mixin_ in class_.mixins) {
_addSuperOverrides(mixin_.element);
if (class_ is ClassElement) {
_addSuperOverrides(class_.supertype?.element2);
}
for (var constraint in class_.superclassConstraints) {
_addSuperOverrides(constraint.element);
for (var mixin_ in class_.mixins) {
_addSuperOverrides(mixin_.element2);
}
if (class_ is MixinElement) {
for (var constraint in class_.superclassConstraints) {
_addSuperOverrides(constraint.element2);
}
}
}
Element? _lookupMember(ClassElement classElement) {
Element? _lookupMember(InterfaceElement classElement) {
Element? member;
// method
if (_kinds.contains(ElementKind.METHOD)) {

View file

@ -9,6 +9,7 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
/// Computer for Flutter specific outlines.
class FlutterOutlineComputer {
@ -131,10 +132,10 @@ class FlutterOutlineComputer {
/// a widget reference outline item.
protocol.FlutterOutline? _createOutline(Expression node, bool withGeneric) {
var type = node.staticType;
if (type == null || !_flutter.isWidgetType(type)) {
if (type is! InterfaceType || !_flutter.isWidgetType(type)) {
return null;
}
var className = type.element!.displayName;
var className = type.element2.displayName;
if (node is InstanceCreationExpression) {
var attributes = <protocol.FlutterOutlineAttribute>[];

View file

@ -7,11 +7,12 @@ import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element.dart' as analyzer;
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/element/element.dart' show ElementImpl;
import 'package:analyzer/src/dart/element/element.dart' as analyzer;
import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin;
import 'package:analyzer_plugin/utilities/analyzer_converter.dart';
@ -69,8 +70,13 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
}
final type = node is Expression ? _getType(node) : null;
final element = type?.element;
if (element is! ElementImpl) {
analyzer.Element? element;
if (type is InterfaceType) {
element = type.element2;
} else if (type is TypeParameterType) {
element = type.element;
}
if (element is! analyzer.ElementImpl) {
return success(_emptyResult);
}
@ -118,7 +124,7 @@ class TypeDefinitionHandler extends MessageHandler<TypeDefinitionParams,
LineInfo originLineInfo,
LineInfo targetLineInfo,
AstNode originNode,
ElementImpl targetElement,
analyzer.ElementImpl targetElement,
plugin.Location targetLocation,
) {
final nameRange =

View file

@ -23,7 +23,7 @@ class TypeHierarchyComputer {
ClassElement? _pivotClass;
final List<TypeHierarchyItem> _items = <TypeHierarchyItem>[];
final List<ClassElement> _itemClassElements = <ClassElement>[];
final List<InterfaceElement> _itemClassElements = [];
final Map<Element, TypeHierarchyItem> _elementItemMap =
HashMap<Element, TypeHierarchyItem>();
@ -81,7 +81,7 @@ class TypeHierarchyComputer {
}
Future _createSubclasses(
TypeHierarchyItem item, int itemId, ClassElement classElement) async {
TypeHierarchyItem item, int itemId, InterfaceElement classElement) async {
var subElements = await getDirectSubClasses(_searchEngine, classElement);
var subItemIds = <int>[];
for (var subElement in subElements) {
@ -120,7 +120,7 @@ class TypeHierarchyComputer {
}
int _createSuperItem(
ClassElement classElement, List<DartType>? typeArguments) {
InterfaceElement classElement, List<DartType>? typeArguments) {
// check for recursion
var cachedItem = _elementItemMap[classElement];
if (cachedItem != null) {
@ -154,30 +154,30 @@ class TypeHierarchyComputer {
_itemClassElements.add(classElement);
}
// superclass
{
if (classElement is ClassElement) {
var superType = classElement.supertype;
if (superType != null) {
item.superclass = _createSuperItem(
superType.element,
superType.element2,
superType.typeArguments,
);
}
}
// mixins
for (var type in classElement.mixins) {
var id = _createSuperItem(type.element, type.typeArguments);
var id = _createSuperItem(type.element2, type.typeArguments);
item.mixins.add(id);
}
// interfaces
for (var type in classElement.interfaces) {
var id = _createSuperItem(type.element, type.typeArguments);
var id = _createSuperItem(type.element2, type.typeArguments);
item.interfaces.add(id);
}
// done
return itemId;
}
ExecutableElement? _findMemberElement(ClassElement clazz) {
ExecutableElement? _findMemberElement(InterfaceElement clazz) {
var pivotName = _pivotName;
if (pivotName == null) {
return null;
@ -201,7 +201,7 @@ class TypeHierarchyComputer {
}
// try to find in the class mixin
for (var mixin in clazz.mixins.reversed) {
var mixinElement = mixin.element;
var mixinElement = mixin.element2;
if (_pivotKind == ElementKind.METHOD) {
result = mixinElement.lookUpMethod(pivotName, _pivotLibrary);
} else if (_pivotKind == ElementKind.GETTER) {

View file

@ -251,9 +251,9 @@ class DartCompletionManager {
var type = request.contextType;
if (type is InterfaceType) {
var element = type.element;
var element = type.element2;
var tag = '${element.librarySource.uri}::${element.name}';
if (element.isEnum) {
if (element is EnumElement) {
includedSuggestionRelevanceTags.add(
IncludedSuggestionRelevanceTag(
tag,

View file

@ -44,7 +44,7 @@ class ExtensionMemberContributor extends DartCompletionContributor {
for (var type in types) {
var inheritanceDistance = memberBuilder.request.featureComputer
.inheritanceDistanceFeature(
thisExtendedType.element, type.element);
thisExtendedType.element2, type.element2);
_addTypeMembers(type, defaultKind, inheritanceDistance);
}
_addExtensionMembers(extensions, defaultKind, thisExtendedType);
@ -114,7 +114,7 @@ class ExtensionMemberContributor extends DartCompletionContributor {
var inheritanceDistance = 0.0;
if (type is InterfaceType && extendedType is InterfaceType) {
inheritanceDistance = memberBuilder.request.featureComputer
.inheritanceDistanceFeature(type.element, extendedType.element);
.inheritanceDistanceFeature(type.element2, extendedType.element2);
}
// TODO(brianwilkerson) We might want to apply the substitution to the
// members of the extension for display purposes.

View file

@ -276,7 +276,8 @@ class FeatureComputer {
/// must be traversed in the type graph to get from the subtype to the
/// supertype if the two types are not the same. Return `-1` if the [subclass]
/// is not a subclass of the [superclass].
int inheritanceDistance(ClassElement subclass, ClassElement superclass) {
int inheritanceDistance(
InterfaceElement subclass, InterfaceElement superclass) {
// This method is only visible for the metrics computation and might be made
// private at some future date.
return _inheritanceDistance(subclass, superclass, {});
@ -286,7 +287,7 @@ class FeatureComputer {
/// defined in the [superclass] that is being accessed through an expression
/// whose static type is the [subclass].
double inheritanceDistanceFeature(
ClassElement subclass, ClassElement superclass) {
InterfaceElement subclass, InterfaceElement superclass) {
var distance = _inheritanceDistance(subclass, superclass, {});
return _distanceToPercent(distance);
}
@ -460,8 +461,8 @@ class FeatureComputer {
/// cycles in the type graph.
///
/// This is the implementation of [inheritanceDistance].
int _inheritanceDistance(ClassElement? subclass, ClassElement superclass,
Set<ClassElement> visited) {
int _inheritanceDistance(InterfaceElement? subclass,
InterfaceElement superclass, Set<InterfaceElement> visited) {
if (subclass == null) {
return -1;
} else if (subclass == superclass) {
@ -469,19 +470,24 @@ class FeatureComputer {
} else if (!visited.add(subclass)) {
return -1;
}
var minDepth =
_inheritanceDistance(subclass.supertype?.element, superclass, visited);
var minDepth = 0;
if (subclass is ClassElement) {
minDepth = _inheritanceDistance(
subclass.supertype?.element2, superclass, visited);
}
void visitTypes(List<InterfaceType> types) {
for (var type in types) {
var depth = _inheritanceDistance(type.element, superclass, visited);
var depth = _inheritanceDistance(type.element2, superclass, visited);
if (minDepth < 0 || (depth >= 0 && depth < minDepth)) {
minDepth = depth;
}
}
}
visitTypes(subclass.superclassConstraints);
if (subclass is MixinElement) {
visitTypes(subclass.superclassConstraints);
}
visitTypes(subclass.mixins);
visitTypes(subclass.interfaces);

View file

@ -149,7 +149,7 @@ class LocalReferenceContributor extends DartCompletionContributor {
: CompletionSuggestionKind.INVOCATION;
for (var type in classElement.allSupertypes) {
var inheritanceDistance = request.featureComputer
.inheritanceDistanceFeature(classElement, type.element);
.inheritanceDistanceFeature(classElement, type.element2);
_addSuggestionsForType(type, inheritanceDistance,
isFunctionalArgument: isFunctionalArgument);
}

View file

@ -22,13 +22,13 @@ class NamedConstructorContributor extends DartCompletionContributor {
if (node is ConstructorName) {
if (node.parent is ConstructorReference) {
var element = node.type.name.staticElement;
if (element is ClassElement) {
if (element is InterfaceElement) {
_buildSuggestions(element);
}
} else {
var type = node.type.type;
if (type is InterfaceType) {
var element = type.element;
var element = type.element2;
_buildSuggestions(element);
}
}
@ -40,7 +40,11 @@ class NamedConstructorContributor extends DartCompletionContributor {
}
}
void _buildSuggestions(ClassElement element) {
void _buildSuggestions(InterfaceElement element) {
if (element is! ClassElement) {
return;
}
var tearOff = request.shouldSuggestTearOff(element);
var isLocalClassDecl = element.library == request.libraryElement;
for (var constructor in element.constructors) {

View file

@ -38,7 +38,7 @@ class RedirectingContributor extends DartCompletionContributor {
var containingClass =
parent.thisOrAncestorOfType<ClassOrMixinDeclaration>();
var superclassElement =
containingClass?.declaredElement?.supertype?.element;
containingClass?.declaredElement?.supertype?.element2;
if (superclassElement != null) {
for (var constructor in superclassElement.constructors) {
if (constructor.isAccessibleIn2(request.libraryElement)) {

View file

@ -7,6 +7,7 @@ import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
import 'package:analysis_server/src/utilities/extensions/completion_request.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
/// A contributor that produces suggestions based on the static members of a
/// given class, enum, or extension. More concretely, this class produces
@ -24,9 +25,11 @@ class StaticMemberContributor extends DartCompletionContributor {
var element = targetId.staticElement;
if (element is TypeAliasElement) {
var aliasedType = element.aliasedType;
element = aliasedType.element;
if (aliasedType is InterfaceType) {
element = aliasedType.element2;
}
}
if (element is ClassElement) {
if (element is InterfaceElement) {
for (var accessor in element.accessors) {
if (accessor.isStatic &&
!accessor.isSynthetic &&
@ -34,7 +37,7 @@ class StaticMemberContributor extends DartCompletionContributor {
builder.suggestAccessor(accessor, inheritanceDistance: 0.0);
}
}
if (!request.shouldSuggestTearOff(element)) {
if (element is ClassElement && !request.shouldSuggestTearOff(element)) {
for (var constructor in element.constructors) {
if (isVisible(constructor)) {
if (!element.isAbstract || constructor.isFactory) {
@ -45,7 +48,7 @@ class StaticMemberContributor extends DartCompletionContributor {
}
for (var field in element.fields) {
if (field.isStatic &&
(!field.isSynthetic || element.isEnum) &&
(!field.isSynthetic || element is EnumElement) &&
isVisible(field)) {
builder.suggestField(field, inheritanceDistance: 0.0);
}

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:collection';
import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
@ -251,7 +249,7 @@ class _SuggestionBuilder extends MemberSuggestionBuilder {
}
for (var targetType in types) {
var inheritanceDistance = request.featureComputer
.inheritanceDistanceFeature(type.element, targetType.element);
.inheritanceDistanceFeature(type.element2, targetType.element2);
for (var method in targetType.methods) {
// Exclude static methods when completion on an instance.
if (!method.isStatic) {
@ -288,11 +286,11 @@ class _SuggestionBuilder extends MemberSuggestionBuilder {
// classes seen (not the interfaces) so that we won't be fooled by nonsense
// like "class C<T> extends C<List<T>> {}"
var result = <InterfaceType>[];
Set<ClassElement> classesSeen = HashSet<ClassElement>();
final classesSeen = <InterfaceElement>{};
var typesToVisit = <InterfaceType>[type];
while (typesToVisit.isNotEmpty) {
var nextType = typesToVisit.removeLast();
if (!classesSeen.add(nextType.element)) {
if (!classesSeen.add(nextType.element2)) {
// Class had already been seen, so ignore this type.
continue;
}

View file

@ -54,7 +54,7 @@ abstract class CorrectionProducer extends SingleCorrectionProducer {
/// Return the class, enum or mixin declaration for the given [element].
Future<ClassOrMixinDeclaration?> getClassOrMixinDeclaration(
ClassElement element) async {
InterfaceElement element) async {
var result = await sessionHelper.getElementDeclaration(element);
var node = result?.node;
if (node is ClassOrMixinDeclaration) {
@ -76,10 +76,10 @@ abstract class CorrectionProducer extends SingleCorrectionProducer {
/// Return the class element associated with the [target], or `null` if there
/// is no such class element.
ClassElement? getTargetClassElement(Expression target) {
InterfaceElement? getTargetClassElement(Expression target) {
var type = target.staticType;
if (type is InterfaceType) {
return type.element;
return type.element2;
} else if (target is Identifier) {
var element = target.staticElement;
if (element is ClassElement) {

View file

@ -209,8 +209,7 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
}
bool _isEnum(DartType type) {
final element = type.element;
return element is ClassElement && element.isEnum;
return type is InterfaceType && type.element2 is EnumElement;
}
bool _isIterable(DartType type) {

View file

@ -35,8 +35,8 @@ class AddMissingEnumCaseClauses extends CorrectionProducer {
var enumConstantNames = <String>[];
var expressionType = statement.expression.staticType;
if (expressionType is InterfaceType) {
var enumElement = expressionType.element;
if (enumElement.isEnum) {
var enumElement = expressionType.element2;
if (enumElement is EnumElement) {
enumName = enumElement.name;
for (var field in enumElement.fields) {
if (field.isEnumConstant) {

View file

@ -26,7 +26,7 @@ class AddMissingEnumLikeCaseClauses extends CorrectionProducer {
if (expressionType is! InterfaceType) {
return;
}
var classElement = expressionType.element;
var classElement = expressionType.element2;
var className = classElement.name;
var caseNames = _caseNames(node);
var missingNames = _constantNames(classElement)
@ -86,7 +86,7 @@ class AddMissingEnumLikeCaseClauses extends CorrectionProducer {
}
/// Return the names of the constants defined in [classElement].
List<String> _constantNames(ClassElement classElement) {
List<String> _constantNames(InterfaceElement classElement) {
var type = classElement.thisType;
var constantNames = <String>[];
for (var field in classElement.fields) {

View file

@ -320,7 +320,7 @@ class ChangeTo extends CorrectionProducer {
}
void _updateFinderWithClassMembers(
_ClosestElementFinder finder, ClassElement clazz) {
_ClosestElementFinder finder, InterfaceElement clazz) {
var members = getMembers(clazz);
finder._updateList(members);
}

View file

@ -560,7 +560,7 @@ class _EnumDescription {
// class.
if (fieldElement.isConst &&
fieldType is InterfaceType &&
fieldType.element == classElement) {
fieldType.element2 == classElement) {
var initializer = field.initializer;
if (initializer is InstanceCreationExpression) {
var constructorElement =
@ -728,13 +728,13 @@ class _NonEnumVisitor extends _BaseVisitor {
throw _CannotConvertException('Unresolved');
}
if (element != classElement) {
if (element.supertype?.element == classElement) {
if (element.supertype?.element2 == classElement) {
throw _CannotConvertException('Class is extended');
} else if (element.interfaces
.map((e) => e.element)
.map((e) => e.element2)
.contains(classElement)) {
throw _CannotConvertException('Class is implemented');
} else if (element.mixins.map((e) => e.element).contains(classElement)) {
} else if (element.mixins.map((e) => e.element2).contains(classElement)) {
// This case won't occur unless there's an error in the source code, but
// it's easier to check for the condition than it is to check for the
// diagnostic.

View file

@ -38,7 +38,7 @@ class ConvertClassToMixin extends CorrectionProducer {
var classElement = classDeclaration.declaredElement!;
for (var type in classElement.mixins) {
if (referencedClasses.contains(type.element)) {
if (referencedClasses.contains(type.element2)) {
superclassConstraints.add(type);
} else {
interfaces.add(type);

View file

@ -52,7 +52,7 @@ class ConvertIntoForIndex extends CorrectionProducer {
{
var iterableType = iterable.staticType;
if (iterableType is! InterfaceType ||
iterableType.element != typeProvider.listElement) {
iterableType.element2 != typeProvider.listElement) {
return;
}
}

View file

@ -41,7 +41,7 @@ class ConvertToListLiteral extends CorrectionProducer {
var type = creation.staticType;
if (node.offset > creation.argumentList.offset ||
type is! InterfaceType ||
type.element != typeProvider.listElement ||
type.element2 != typeProvider.listElement ||
creation.constructorName.name != null ||
creation.argumentList.arguments.isNotEmpty) {
return;

View file

@ -45,7 +45,7 @@ class ConvertToMapLiteral extends CorrectionProducer {
creation.constructorName.name != null ||
creation.argumentList.arguments.isNotEmpty ||
type is! InterfaceType ||
!_isMapClass(type.element)) {
!_isMapClass(type.element2)) {
return;
}
//
@ -67,7 +67,7 @@ class ConvertToMapLiteral extends CorrectionProducer {
/// Return `true` if the [element] represents either the class `Map` or
/// `LinkedHashMap`.
bool _isMapClass(ClassElement element) =>
bool _isMapClass(InterfaceElement element) =>
element == typeProvider.mapElement ||
(element.name == 'LinkedHashMap' &&
element.library.name == 'dart.collection');

View file

@ -145,7 +145,7 @@ class ConvertToSetLiteral extends CorrectionProducer {
}
// TODO(brianwilkerson) Consider also accepting uses of LinkedHashSet.
if (type.element != typeProvider.setElement) {
if (type.element2 != typeProvider.setElement) {
return null;
}
return creation;
@ -195,13 +195,16 @@ class ConvertToSetLiteral extends CorrectionProducer {
var parent = creation.parent!;
if (parent is VariableDeclaration) {
var parent2 = parent.parent;
if (parent2 is VariableDeclarationList &&
parent2.type?.type?.element == typeProvider.setElement) {
return true;
if (parent2 is VariableDeclarationList) {
final type = parent2.type?.type;
if (type is InterfaceType && type.element2 == typeProvider.setElement) {
return true;
}
}
} else if (parent.parent is InvocationExpression) {
var parameterElement = creation.staticParameterElement;
if (parameterElement?.type.element == typeProvider.setElement) {
final type = parameterElement?.type;
if (type is InterfaceType && type.element2 == typeProvider.setElement) {
return true;
}
}

View file

@ -77,7 +77,7 @@ class CreateConstructor extends CorrectionProducer {
}
// prepare target ClassDeclaration
var targetElement = targetType.element;
var targetElement = targetType.element2;
var targetResult = await sessionHelper.getElementDeclaration(targetElement);
if (targetResult == null) {
return;
@ -202,7 +202,7 @@ class CreateConstructor extends CorrectionProducer {
Future<void> _write(
ChangeBuilder builder,
Token name,
ClassElement targetElement,
InterfaceElement targetElement,
InsertionLocation targetLocation, {
Token? constructorName,
bool isConst = false,

View file

@ -76,7 +76,7 @@ class CreateField extends CorrectionProducer {
}
// prepare target ClassElement
var staticModifier = false;
ClassElement? targetClassElement;
InterfaceElement? targetClassElement;
if (target != null) {
targetClassElement = getTargetClassElement(target);
// maybe static

View file

@ -55,7 +55,7 @@ class CreateGetter extends CorrectionProducer {
if (targetType is! InterfaceType) {
return;
}
targetElement = targetType.element;
targetElement = targetType.element2;
// maybe static
if (target is Identifier) {
var targetIdentifier = target;

View file

@ -30,14 +30,14 @@ class CreateMethodOrFunction extends CorrectionProducer {
var nameNode = node;
if (nameNode is SimpleIdentifier) {
// prepare argument expression (to get parameter)
ClassElement? targetElement;
InterfaceElement? targetElement;
Expression argument;
{
var target = getQualifiedPropertyTarget(node);
if (target != null) {
var targetType = target.staticType;
if (targetType is InterfaceType) {
targetElement = targetType.element;
targetElement = targetType.element2;
argument = target.parent as Expression;
} else {
return;
@ -140,7 +140,7 @@ class CreateMethodOrFunction extends CorrectionProducer {
/// Adds proposal for creating method corresponding to the given
/// [FunctionType] in the given [ClassElement].
Future<void> _createMethod(ChangeBuilder builder,
ClassElement targetClassElement, FunctionType functionType) async {
InterfaceElement targetClassElement, FunctionType functionType) async {
var name = (node as SimpleIdentifier).name;
// prepare environment
var targetSource = targetClassElement.source;

View file

@ -54,7 +54,7 @@ class CreateSetter extends CorrectionProducer {
if (targetType is! InterfaceType) {
return;
}
targetElement = targetType.element;
targetElement = targetType.element2;
// maybe static
if (target is Identifier) {
var targetIdentifier = target;

View file

@ -16,6 +16,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
import 'package:collection/collection.dart';
class FlutterConvertToStatelessWidget extends CorrectionProducer {
@override
@ -250,15 +251,15 @@ class FlutterConvertToStatelessWidget extends CorrectionProducer {
}
static bool _isState(ClassElement widgetClassElement, DartType? type) {
if (type is! ParameterizedType) return false;
if (type is! InterfaceType) return false;
var typeArguments = type.typeArguments;
if (typeArguments.length != 1 ||
typeArguments[0].element != widgetClassElement) {
final firstArgument = type.typeArguments.singleOrNull;
if (firstArgument is! InterfaceType ||
firstArgument.element2 != widgetClassElement) {
return false;
}
var classElement = type.element;
var classElement = type.element2;
return classElement is ClassElement &&
Flutter.instance.isExactState(classElement);
}
@ -381,7 +382,8 @@ class _StateUsageVisitor extends RecursiveAstVisitor<void> {
@override
void visitInstanceCreationExpression(InstanceCreationExpression node) {
super.visitInstanceCreationExpression(node);
if (node.staticType?.element != stateClassElement) {
final type = node.staticType;
if (type is! InterfaceType || type.element2 != stateClassElement) {
return;
}
var methodDeclaration = node.thisOrAncestorOfType<MethodDeclaration>();
@ -397,9 +399,10 @@ class _StateUsageVisitor extends RecursiveAstVisitor<void> {
@override
void visitMethodInvocation(MethodInvocation node) {
var type = node.staticType;
if (node.methodName.name == 'createState' &&
if (type is InterfaceType &&
node.methodName.name == 'createState' &&
(FlutterConvertToStatelessWidget._isState(widgetClassElement, type) ||
type?.element == stateClassElement)) {
type.element2 == stateClassElement)) {
used = true;
}
}

View file

@ -5,7 +5,7 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
@ -32,14 +32,16 @@ class MoveTypeArgumentsToClass extends CorrectionProducer {
return;
}
var element = namedType.typeOrThrow.element;
if (element is ClassElement &&
element.typeParameters.length == typeArguments.arguments.length) {
await builder.addDartFileEdit(file, (builder) {
var argumentText = utils.getNodeText(typeArguments);
builder.addSimpleInsertion(namedType.end, argumentText);
builder.addDeletion(range.node(typeArguments));
});
final type = namedType.typeOrThrow;
if (type is InterfaceType) {
final element = type.element2;
if (element.typeParameters.length == typeArguments.arguments.length) {
await builder.addDartFileEdit(file, (builder) {
var argumentText = utils.getNodeText(typeArguments);
builder.addSimpleInsertion(namedType.end, argumentText);
builder.addDeletion(range.node(typeArguments));
});
}
}
}
}

View file

@ -153,12 +153,12 @@ class ElementDescriptor {
// that the method might have been in the element's class.
return true;
}
if (components[1] == type.element?.name) {
return true;
}
if (type is InterfaceType) {
if (components[1] == type.element2.name) {
return true;
}
for (var supertype in type.allSupertypes) {
if (components[1] == supertype.element.name) {
if (components[1] == supertype.element2.name) {
return true;
}
}

View file

@ -381,7 +381,7 @@ class _MatcherBuilder {
var targetType = node.prefix.staticType;
if (targetType is InterfaceType) {
_addMatcher(
components: [node.identifier.name, targetType.element.name],
components: [node.identifier.name, targetType.element2.name],
kinds: const [
ElementKind.constantKind,
ElementKind.fieldKind,
@ -527,7 +527,7 @@ class _MatcherBuilder {
var type = target.staticType;
if (type != null) {
if (type is InterfaceType) {
return type.element.name;
return type.element2.name;
} else if (type.isDynamic) {
// The name is likely to be undefined.
return target.name;
@ -538,7 +538,7 @@ class _MatcherBuilder {
} else if (target != null) {
var type = target.staticType;
if (type is InterfaceType) {
return type.element.name;
return type.element2.name;
}
return null;
}

View file

@ -66,7 +66,7 @@ List<String> getVariableNameSuggestionsForExpression(DartType? expectedType,
} else if (expectedType.isDartCoreString) {
_addSingleCharacterName(excluded, res, 0x73);
} else if (expectedType is InterfaceType) {
var className = expectedType.element.name;
var className = expectedType.element2.name;
_addAll(excluded, res, getCamelWordCombinations(className));
}
}

View file

@ -530,7 +530,7 @@ class CorrectionUtils {
/// The [ClassElement] the generated code is inserted to, so we can decide if
/// a type parameter may or may not be used.
ClassElement? targetClassElement;
InterfaceElement? targetClassElement;
ExecutableElement? targetExecutableElement;
@ -914,7 +914,7 @@ class CorrectionUtils {
if (type is InterfaceType) {
return _getTypeCodeElementArguments(
librariesToImport: librariesToImport,
element: type.element,
element: type.element2,
isNullable: type.nullabilitySuffix == NullabilitySuffix.question,
typeArguments: type.typeArguments,
);

View file

@ -38,7 +38,11 @@ class ClassDescriptionRegistry {
/// If we know how to materialize the [element], return [ClassDescription].
/// Otherwise return `null`.
ClassDescription? get(ClassElement element) {
ClassDescription? get(InterfaceElement element) {
if (element is! ClassElement) {
return null;
}
var description = _map[element];
if (description == null) {
description = _classDescription(element);
@ -52,7 +56,7 @@ class ClassDescriptionRegistry {
/// Return `true` if properties should be created for instances of [type].
bool hasNestedProperties(DartType type) {
if (type is InterfaceType) {
return _isOptedInClass(type.element);
return _isOptedInClass(type.element2);
}
return false;
}
@ -72,7 +76,11 @@ class ClassDescriptionRegistry {
return ClassDescription(element, constructor);
}
bool _isOptedInClass(ClassElement element) {
bool _isOptedInClass(InterfaceElement element) {
if (element is! ClassElement) {
return false;
}
return _isClass(
element,
'package:flutter/src/widgets/container.dart',

View file

@ -390,7 +390,7 @@ class _WidgetDescriptionComputer {
var type = parameter.type;
if (type is InterfaceType) {
var classDescription = classRegistry.get(
type.element,
type.element2,
);
if (classDescription != null) {
_addProperties(
@ -404,7 +404,7 @@ class _WidgetDescriptionComputer {
}
List<protocol.FlutterWidgetPropertyValueEnumItem> _enumItemsForEnum(
ClassElement element,
EnumElement element,
) {
return element.fields
.where((field) => field.isStatic && field.isEnumConstant)
@ -462,8 +462,8 @@ class _WidgetDescriptionComputer {
);
}
if (type is InterfaceType) {
var classElement = type.element;
if (classElement.isEnum) {
var classElement = type.element2;
if (classElement is EnumElement) {
return protocol.FlutterWidgetPropertyEditor(
protocol.FlutterWidgetPropertyEditorKind.ENUM,
enumItems: _enumItemsForEnum(classElement),

View file

@ -305,7 +305,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
// extends
var supertype = _enclosingClassElement!.supertype;
var supertypeElement = supertype?.element;
var supertypeElement = supertype?.element2;
if (supertypeElement != null) {
var recordSupertypeVName =
_vNameFromElement(supertypeElement, schema.RECORD_KIND);
@ -317,7 +317,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
var interfaces = _enclosingClassElement!.interfaces;
for (var interface in interfaces) {
var recordInterfaceVName =
_vNameFromElement(interface.element, schema.RECORD_KIND);
_vNameFromElement(interface.element2, schema.RECORD_KIND);
addEdge(
_enclosingClassVName!, schema.EXTENDS_EDGE, recordInterfaceVName);
}
@ -326,7 +326,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
var mixins = _enclosingClassElement!.mixins;
for (var mixin in mixins) {
var recordMixinVName =
_vNameFromElement(mixin.element, schema.RECORD_KIND);
_vNameFromElement(mixin.element2, schema.RECORD_KIND);
addEdge(_enclosingClassVName!, schema.EXTENDS_EDGE, recordMixinVName);
}
@ -383,7 +383,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
var interfaces = _enclosingClassElement!.interfaces;
for (var interface in interfaces) {
var recordInterfaceVName =
_vNameFromElement(interface.element, schema.RECORD_KIND);
_vNameFromElement(interface.element2, schema.RECORD_KIND);
addEdge(
_enclosingClassVName!, schema.EXTENDS_EDGE, recordInterfaceVName);
}
@ -392,7 +392,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
var mixins = _enclosingClassElement!.mixins;
for (var mixin in mixins) {
var recordMixinVName =
_vNameFromElement(mixin.element, schema.RECORD_KIND);
_vNameFromElement(mixin.element2, schema.RECORD_KIND);
addEdge(_enclosingClassVName!, schema.EXTENDS_EDGE, recordMixinVName);
}
@ -1023,18 +1023,18 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
void _handleThisOrSuper(Expression thisOrSuperNode) {
var type = thisOrSuperNode.staticType;
if (type != null && type.element != null) {
if (type is InterfaceType) {
// Expected SuperExpression.staticType to return the type of the
// supertype, but it returns the type of the enclosing class (same as
// ThisExpression), do some additional work to correct assumption:
if (thisOrSuperNode is SuperExpression && type.element is ClassElement) {
var supertype = (type.element as ClassElement).supertype;
if (thisOrSuperNode is SuperExpression && type.element2 is ClassElement) {
var supertype = (type.element2 as ClassElement).supertype;
if (supertype != null) {
type = supertype;
}
}
// vname
var vName = _vNameFromElement(type.element, schema.RECORD_KIND);
var vName = _vNameFromElement(type.element2, schema.RECORD_KIND);
// anchor
var anchorVName = addAnchorEdgesContainingEdge(
@ -1318,8 +1318,8 @@ mixin OutputUtils {
var paramTypeVName = dynamicBuiltin;
var declaredElement = paramNode.declaredElement!;
var type = declaredElement.type;
if (!type.isDynamic) {
paramTypeVName = _vNameFromElement(type.element, schema.TAPP_KIND);
if (type is InterfaceType) {
paramTypeVName = _vNameFromElement(type.element2, schema.TAPP_KIND);
}
addEdge(funcTypeVName, schema.PARAM_EDGE, paramTypeVName,
ordinalIntValue: i++);
@ -1395,8 +1395,8 @@ mixin OutputUtils {
return dynamicBuiltin;
} else if (type.isVoid) {
return voidBuiltin;
} else if (type.element is ClassElement) {
return _vNameFromElement(type.element, schema.RECORD_KIND);
} else if (type is InterfaceType) {
return _vNameFromElement(type.element2, schema.RECORD_KIND);
} else {
return dynamicBuiltin;
}

View file

@ -794,7 +794,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
} else {
variableType = _getTypeCode(returnTypeObj);
if (_hasAwait) {
if (returnTypeObj.element != typeProvider.futureElement) {
if (returnTypeObj is InterfaceType &&
returnTypeObj.element2 != typeProvider.futureElement) {
returnType = _getTypeCode(typeProvider.futureType(returnTypeObj));
}
} else {

View file

@ -617,7 +617,7 @@ class _ParametersCollector extends RecursiveAstVisitor<void> {
final Set<Element> uniqueElements = <Element>{};
final List<_Parameter> parameters = [];
List<ClassElement>? enclosingClasses;
List<InterfaceElement>? enclosingClasses;
_ParametersCollector(this.enclosingClass, this.expressionRange);
@ -665,9 +665,9 @@ class _ParametersCollector extends RecursiveAstVisitor<void> {
bool _isMemberOfEnclosingClass(Element element) {
final enclosingClass = this.enclosingClass;
if (enclosingClass != null) {
final enclosingClasses = this.enclosingClasses ??= <ClassElement>[
final enclosingClasses = this.enclosingClasses ??= <InterfaceElement>[
enclosingClass,
...enclosingClass.allSupertypes.map((t) => t.element)
...enclosingClass.allSupertypes.map((t) => t.element2)
];
return enclosingClasses.contains(element.enclosingElement3);
}

View file

@ -162,7 +162,7 @@ Set<String> _getNamesConflictingAt(AstNode node) {
var enclosingClassElement = getEnclosingClassElement(node);
if (enclosingClassElement != null) {
var elements = [
...enclosingClassElement.allSupertypes.map((e) => e.element),
...enclosingClassElement.allSupertypes.map((e) => e.element2),
enclosingClassElement,
];
for (var classElement in elements) {

View file

@ -161,9 +161,10 @@ class _BaseClassMemberValidator {
Future<void> _checkHierarchy({
required bool isRename,
required Set<ClassElement> subClasses,
required Set<InterfaceElement> subClasses,
}) async {
var superClasses = elementClass.allSupertypes.map((e) => e.element).toSet();
var superClasses =
elementClass.allSupertypes.map((e) => e.element2).toSet();
// check shadowing in the hierarchy
var declarations = await searchEngine.searchMemberDeclarations(name);
for (var declaration in declarations) {

View file

@ -24,7 +24,7 @@ List<Element> getChildren(Element parent, [String? name]) {
///
/// Includes: fields, accessors and methods.
/// Excludes: constructors and synthetic elements.
List<Element> getClassMembers(ClassElement clazz, [String? name]) {
List<Element> getClassMembers(InterfaceElement clazz, [String? name]) {
var members = <Element>[];
visitChildren(clazz, (Element element) {
if (element.isSynthetic) {
@ -49,7 +49,7 @@ List<Element> getClassMembers(ClassElement clazz, [String? name]) {
/// Returns a [Set] with direct subclasses of [seed].
Future<Set<ClassElement>> getDirectSubClasses(
SearchEngine searchEngine, ClassElement seed) async {
SearchEngine searchEngine, InterfaceElement seed) async {
var matches = await searchEngine.searchSubtypes(seed);
return matches.map((match) => match.element).cast<ClassElement>().toSet();
}
@ -96,7 +96,7 @@ Future<Set<ClassMemberElement>> getHierarchyMembers(
if (enclosingElement is ClassElement) {
var name = member.displayName;
var searchClasses = [
...enclosingElement.allSupertypes.map((e) => e.element),
...enclosingElement.allSupertypes.map((e) => e.element2),
enclosingElement,
];
for (var superClass in searchClasses) {
@ -153,9 +153,9 @@ Future<List<ParameterElement>> getHierarchyNamedParameters(
/// Includes: fields, accessors and methods.
///
/// Excludes: constructors and synthetic elements.
List<Element> getMembers(ClassElement clazz) {
List<Element> getMembers(InterfaceElement clazz) {
var classElements = [
...clazz.allSupertypes.map((e) => e.element),
...clazz.allSupertypes.map((e) => e.element2),
clazz,
];
var members = <Element>[];

View file

@ -53,8 +53,8 @@ abstract class SearchEngine {
/// Returns all subtypes of the given [type].
///
/// [type] - the [ClassElement] being subtyped by the found matches.
Future<Set<ClassElement>> searchAllSubtypes(ClassElement type);
/// [type] - the [InterfaceElement] being subtyped by the found matches.
Future<Set<InterfaceElement>> searchAllSubtypes(InterfaceElement type);
/// Returns declarations of class members with the given name.
///
@ -75,7 +75,7 @@ abstract class SearchEngine {
/// Returns direct subtypes of the given [type].
///
/// [type] - the [ClassElement] being subtyped by the found matches.
Future<List<SearchMatch>> searchSubtypes(ClassElement type);
Future<List<SearchMatch>> searchSubtypes(InterfaceElement type);
/// Returns all the top-level declarations matching the given pattern.
///

View file

@ -51,13 +51,13 @@ class SearchEngineImpl implements SearchEngine {
}
@override
Future<Set<ClassElement>> searchAllSubtypes(ClassElement type) async {
var allSubtypes = <ClassElement>{};
Future<Set<InterfaceElement>> searchAllSubtypes(InterfaceElement type) async {
var allSubtypes = <InterfaceElement>{};
Future<void> addSubtypes(ClassElement type) async {
Future<void> addSubtypes(InterfaceElement type) async {
var directResults = await _searchDirectSubtypes(type);
for (var directResult in directResults) {
var directSubtype = directResult.enclosingElement as ClassElement;
var directSubtype = directResult.enclosingElement as InterfaceElement;
if (allSubtypes.add(directSubtype)) {
await addSubtypes(directSubtype);
}
@ -106,7 +106,7 @@ class SearchEngineImpl implements SearchEngine {
}
@override
Future<List<SearchMatch>> searchSubtypes(ClassElement type) async {
Future<List<SearchMatch>> searchSubtypes(InterfaceElement type) async {
var results = await _searchDirectSubtypes(type);
return results.map(SearchMatchImpl.forSearchResult).toList();
}
@ -133,7 +133,8 @@ class SearchEngineImpl implements SearchEngine {
return searchedFiles;
}
Future<List<SearchResult>> _searchDirectSubtypes(ClassElement type) async {
Future<List<SearchResult>> _searchDirectSubtypes(
InterfaceElement type) async {
var allResults = <SearchResult>[];
var drivers = _drivers.toList();
var searchedFiles = _createSearchedFiles(drivers);

View file

@ -15,7 +15,7 @@ extension DartCompletionRequestExtensions on DartCompletionRequest {
///
/// TODO(scheglov) Validate that suggesting a tear-off instead of invocation
/// is statistically a good choice.
bool shouldSuggestTearOff(ClassElement element) {
bool shouldSuggestTearOff(InterfaceElement element) {
if (!libraryElement.featureSet.isEnabled(Feature.constructor_tearoffs)) {
return false;
}

View file

@ -293,22 +293,22 @@ class Flutter {
return false;
}
bool isColorElement(ClassElement element) {
bool isExactColor(ClassElement element) =>
bool isColorElement(InterfaceElement element) {
bool isExactColor(InterfaceElement element) =>
element.name == 'Color' && element.library.name == 'dart.ui';
if (isExactColor(element)) {
return true;
}
for (var type in element.allSupertypes) {
if (isExactColor(type.element)) {
if (isExactColor(type.element2)) {
return true;
}
}
return false;
}
return isColorElement(type.element);
return isColorElement(type.element2);
}
/// Return `true` if the given [type] is the flutter mixin `Diagnosticable`
@ -318,8 +318,8 @@ class Flutter {
return false;
}
bool isDiagnosticableElement(ClassElement element) {
bool isExactDiagnosticable(ClassElement element) =>
bool isDiagnosticableElement(InterfaceElement element) {
bool isExactDiagnosticable(InterfaceElement element) =>
element.name == 'Diagnosticable' &&
element.source.uri == _uriDiagnostics;
@ -327,14 +327,14 @@ class Flutter {
return true;
}
for (var type in element.allSupertypes) {
if (isExactDiagnosticable(type.element)) {
if (isExactDiagnosticable(type.element2)) {
return true;
}
}
return false;
}
return isDiagnosticableElement(type.element);
return isDiagnosticableElement(type.element2);
}
/// Return `true` if the [element] is the Flutter class `Alignment`.
@ -349,14 +349,14 @@ class Flutter {
}
/// Return `true` if the [element] is the Flutter class `AlignmentGeometry`.
bool isExactAlignmentGeometry(ClassElement element) {
bool isExactAlignmentGeometry(InterfaceElement element) {
return _isExactWidget(element, 'AlignmentGeometry', _uriAlignment);
}
/// Return `true` if the [type] is the Flutter type `EdgeInsetsGeometry`.
bool isExactEdgeInsetsGeometryType(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, 'EdgeInsetsGeometry', _uriEdgeInsets);
_isExactWidget(type.element2, 'EdgeInsetsGeometry', _uriEdgeInsets);
}
/// Return `true` if the [node] is creation of `Align`.
@ -380,13 +380,13 @@ class Flutter {
/// Return `true` if the given [type] is the Flutter class `StatefulWidget`.
bool isExactlyStatefulWidgetType(DartType? type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameStatefulWidget, _uriFramework);
_isExactWidget(type.element2, _nameStatefulWidget, _uriFramework);
}
/// Return `true` if the given [type] is the Flutter class `StatelessWidget`.
bool isExactlyStatelessWidgetType(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameStatelessWidget, _uriFramework);
_isExactWidget(type.element2, _nameStatelessWidget, _uriFramework);
}
/// Return `true` if the given [element] is the Flutter class `State`.
@ -397,43 +397,43 @@ class Flutter {
/// Return `true` if the given [type] is the Flutter class `Align`.
bool isExactWidgetTypeAlign(DartType? type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameAlign, _uriBasic);
_isExactWidget(type.element2, _nameAlign, _uriBasic);
}
/// Return `true` if the given [type] is the Flutter class `StreamBuilder`.
bool isExactWidgetTypeBuilder(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameBuilder, _uriBasic);
_isExactWidget(type.element2, _nameBuilder, _uriBasic);
}
/// Return `true` if the given [type] is the Flutter class `Center`.
bool isExactWidgetTypeCenter(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameCenter, _uriBasic);
_isExactWidget(type.element2, _nameCenter, _uriBasic);
}
/// Return `true` if the given [type] is the Flutter class `Container`.
bool isExactWidgetTypeContainer(DartType? type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameContainer, _uriContainer);
_isExactWidget(type.element2, _nameContainer, _uriContainer);
}
/// Return `true` if the given [type] is the Flutter class `Padding`.
bool isExactWidgetTypePadding(DartType? type) {
return type is InterfaceType &&
_isExactWidget(type.element, _namePadding, _uriBasic);
_isExactWidget(type.element2, _namePadding, _uriBasic);
}
/// Return `true` if the given [type] is the Flutter class `SizedBox`.
bool isExactWidgetTypeSizedBox(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameSizedBox, _uriBasic);
_isExactWidget(type.element2, _nameSizedBox, _uriBasic);
}
/// Return `true` if the given [type] is the Flutter class `StreamBuilder`.
bool isExactWidgetTypeStreamBuilder(DartType type) {
return type is InterfaceType &&
_isExactWidget(type.element, _nameStreamBuilder, _uriAsync);
_isExactWidget(type.element2, _nameStreamBuilder, _uriAsync);
}
/// Return `true` if the given [type] is the Flutter class `Widget`, or its
@ -451,22 +451,22 @@ class Flutter {
return false;
}
bool isMatrix4Element(ClassElement element) {
bool isExactMatrix4(ClassElement element) =>
bool isMatrix4Element(InterfaceElement element) {
bool isExactMatrix4(InterfaceElement element) =>
element.name == 'Matrix4' && element.library.name == 'vector_math_64';
if (isExactMatrix4(element)) {
return true;
}
for (var type in element.allSupertypes) {
if (isExactMatrix4(type.element)) {
if (isExactMatrix4(type.element2)) {
return true;
}
}
return false;
}
return isMatrix4Element(type.element);
return isMatrix4Element(type.element2);
}
/// Return `true` if the given [element] has the Flutter class `State` as
@ -494,7 +494,7 @@ class Flutter {
return true;
}
for (var type in element.allSupertypes) {
if (_isExactWidget(type.element, _nameWidget, _uriFramework)) {
if (_isExactWidget(type.element2, _nameWidget, _uriFramework)) {
return true;
}
}
@ -532,7 +532,7 @@ class Flutter {
/// Return `true` if the given [type] is the Flutter class `Widget`, or its
/// subtype.
bool isWidgetType(DartType? type) {
return type is InterfaceType && isWidget(type.element);
return type is InterfaceType && isWidget(type.element2);
}
/// Return `true` if the given [element] has a supertype with the
@ -543,8 +543,8 @@ class Flutter {
return false;
}
for (var type in element.allSupertypes) {
if (type.element.name == requiredName) {
var uri = type.element.source.uri;
if (type.element2.name == requiredName) {
var uri = type.element2.source.uri;
if (uri == requiredUri) {
return true;
}

View file

@ -585,8 +585,14 @@ class B extends A {}
}
}
static void _assertContainsClass(Set<ClassElement> subtypes, String name) {
expect(subtypes, contains(predicate((ClassElement e) => e.name == name)));
static void _assertContainsClass(
Set<InterfaceElement> subtypes, String name) {
expect(
subtypes,
contains(
predicate((InterfaceElement e) => e.name == name),
),
);
}
}

View file

@ -32,7 +32,7 @@ class BulkFixDetails {
var classElement = classDecl.declaredElement;
if (classElement != null &&
classElement.allSupertypes.any(
(element) => element.element.name == 'CorrectionProducer')) {
(element) => element.element2.name == 'CorrectionProducer')) {
var correctionName = classDecl.name2.lexeme;
for (var method in classDecl.members.whereType<MethodDeclaration>()) {

View file

@ -22,6 +22,7 @@ import 'package:analyzer/dart/element/element.dart'
Element,
ExecutableElement,
ExtensionElement,
InterfaceElement,
LibraryElement,
LocalVariableElement,
ParameterElement,
@ -1570,7 +1571,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
return;
}
if (targetType is InterfaceType) {
var targetClass = targetType.element;
var targetClass = targetType.element2;
var extension = member.thisOrAncestorOfType<ExtensionElement>();
if (extension != null) {
_recordDistance('member (extension)', 0);
@ -1585,19 +1586,23 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
/// superclasses caused by mixins.
int getSuperclassDepth() {
var depth = 0;
ClassElement? currentClass = targetClass;
InterfaceElement? currentClass = targetClass;
while (currentClass != null) {
if (currentClass == memberClass) {
return depth;
}
for (var mixin in currentClass.mixins.reversed) {
depth++;
if (mixin.element == memberClass) {
if (mixin.element2 == memberClass) {
return depth;
}
}
depth++;
currentClass = currentClass.supertype?.element;
if (currentClass is ClassElement) {
currentClass = currentClass.supertype?.element2;
} else {
currentClass = null;
}
}
return -1;
}
@ -1606,10 +1611,14 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
/// includes all of the implicit superclasses caused by mixins.
int getTargetDepth() {
var depth = 0;
ClassElement? currentClass = targetClass;
InterfaceElement? currentClass = targetClass;
while (currentClass != null) {
depth += currentClass.mixins.length + 1;
currentClass = currentClass.supertype?.element;
if (currentClass is ClassElement) {
currentClass = currentClass.supertype?.element2;
} else {
break;
}
}
return depth;
}
@ -1816,20 +1825,20 @@ class RelevanceDataCollector extends RecursiveAstVisitor<void> {
argumentType is InterfaceType &&
parameterType is InterfaceType) {
int distance;
if (parameterType.element == typeProvider.futureOrElement) {
if (parameterType.element2 == typeProvider.futureOrElement) {
var typeArgument = parameterType.typeArguments[0];
distance = featureComputer.inheritanceDistance(
argumentType.element, typeProvider.futureElement);
argumentType.element2, typeProvider.futureElement);
if (typeArgument is InterfaceType) {
var argDistance = featureComputer.inheritanceDistance(
argumentType.element, typeArgument.element);
argumentType.element2, typeArgument.element2);
if (distance < 0 || (argDistance >= 0 && argDistance < distance)) {
distance = argDistance;
}
}
} else {
distance = featureComputer.inheritanceDistance(
argumentType.element, parameterType.element);
argumentType.element2, parameterType.element2);
}
data.recordDistance('Subtype of context type ($descriptor)', distance);
data.recordDistance('Subtype of context type (all)', distance);

View file

@ -18,6 +18,7 @@
* Deprecated `Element.enclosingElement2`, use `enclosingElement3` instead. The meaningful change is that
`ConstructorElement.enclosingElement3` returns now `IntefaceElement`, not `ClassElement`.
* Deprecated `get enums/mixin`, use `get enums2/mixins2` instead.
* Deprecated `DartType.element`, check for `InterfaceType`, `TypeParameterType`, and then ask the element.
## 4.3.1
* Fix `identifier` for `LibraryExportElement` and `LibraryImportElement`.

View file

@ -197,18 +197,6 @@ abstract class ClassElement
_TmpSharedClassElement {
/// Returns the result of applying augmentations to this class.
AugmentedClassElement get augmented;
/// Return the superclass of this class, or `null` if either the class
/// represents the class 'Object'. If the superclass was not explicitly
/// declared then the implicit superclass 'Object' will be returned.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
/// a cycle. Clients that traverse the inheritance structure must explicitly
/// guard against infinite loops.
@override
InterfaceType? get supertype;
}
/// An element that is contained within a [ClassElement].
@ -1103,10 +1091,6 @@ abstract class EnumElement
_TmpSharedClassElement {
/// Returns the result of applying augmentations to this element.
AugmentedEnumElement get augmented;
/// Returns `Enum` from `dart:core`.
@override
InterfaceType? get supertype;
}
/// Shared interface between [EnumElement] and [EnumAugmentationElement].
@ -1405,6 +1389,23 @@ abstract class InterfaceElement
/// superclass constraints.
List<InterfaceType> get allSupertypes;
/// Return the superclass of this element.
///
/// For [ClassElement] returns `null` only if this class is `Object`. If the
/// superclass is not explicitly specified, or the superclass cannot be
/// resolved, then the implicit superclass `Object` is returned.
///
/// For [EnumElement] returns `Enum` from `dart:core`.
///
/// For [MixinElement] always returns `null`.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
/// a cycle. Clients that traverse the inheritance structure must explicitly
/// guard against infinite loops.
InterfaceType? get supertype;
/// Return the type of `this` expression for this element.
///
/// For a class like `class MyClass<T, U> {}` the returned type is equivalent
@ -1452,6 +1453,24 @@ abstract class InterfaceElement
required NullabilitySuffix nullabilitySuffix,
});
/// Return the element representing the method that results from looking up
/// the given [methodName] in this class with respect to the given [library],
/// ignoring abstract methods, or `null` if the look up fails. The behavior of
/// this method is defined by the Dart Language Specification in section
/// 16.15.1:
/// <blockquote>
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
/// library <i>L</i> is: If <i>C</i> declares an instance method named
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
/// result of the lookup is the result of looking up method <i>m</i> in
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
/// failed.
/// </blockquote>
/// TODO(scheglov) Deprecate and remove it.
MethodElement? lookUpConcreteMethod(
String methodName, LibraryElement library);
/// Return the element representing the getter that results from looking up
/// the given [getterName] in this class with respect to the given [library],
/// or `null` if the look up fails. The behavior of this method is defined by
@ -1502,6 +1521,24 @@ abstract class InterfaceElement
/// </blockquote>
/// TODO(scheglov) Deprecate and remove it.
MethodElement? lookUpMethod(String methodName, LibraryElement library);
/// Return the element representing the setter that results from looking up
/// the given [setterName] in this class with respect to the given [library],
/// or `null` if the look up fails. The behavior of this method is defined by
/// the Dart Language Specification in section 16.15.2:
/// <blockquote>
/// The result of looking up getter (respectively setter) <i>m</i> in class
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
/// instance getter (respectively setter) named <i>m</i> that is accessible to
/// <i>L</i>, then that getter (respectively setter) is the result of the
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
/// of the lookup is the result of looking up getter (respectively setter)
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
/// lookup has failed.
/// </blockquote>
/// TODO(scheglov) Deprecate and remove it.
PropertyAccessorElement? lookUpSetter(
String setterName, LibraryElement library);
}
/// Shared interface between [InterfaceElement] and augmentations.
@ -1551,6 +1588,10 @@ abstract class InterfaceOrAugmentationElement
/// Return a list containing all of the mixins that are applied to the class
/// being extended in order to derive the superclass of this class.
///
/// [ClassElement] and [EnumElement] can have mixins.
///
/// [MixinElement] cannot have mixins, so the empty list is returned.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
@ -2491,37 +2532,6 @@ abstract class _TmpSharedClassElement {
/// TODO(scheglov) Deprecate and remove it.
List<InterfaceType> get superclassConstraints;
/// Return the superclass of this class, or `null` if either the class
/// represents the class 'Object' or if the class represents a mixin
/// declaration. All other classes will have a non-`null` superclass. If the
/// superclass was not explicitly declared then the implicit superclass
/// 'Object' will be returned.
///
/// <b>Note:</b> Because the element model represents the state of the code,
/// it is possible for it to be semantically invalid. In particular, it is not
/// safe to assume that the inheritance structure of a class does not contain
/// a cycle. Clients that traverse the inheritance structure must explicitly
/// guard against infinite loops.
InterfaceType? get supertype;
/// Return the element representing the method that results from looking up
/// the given [methodName] in this class with respect to the given [library],
/// ignoring abstract methods, or `null` if the look up fails. The behavior of
/// this method is defined by the Dart Language Specification in section
/// 16.15.1:
/// <blockquote>
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
/// library <i>L</i> is: If <i>C</i> declares an instance method named
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
/// result of the lookup is the result of looking up method <i>m</i> in
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
/// failed.
/// </blockquote>
/// TODO(scheglov) Deprecate and remove it.
MethodElement? lookUpConcreteMethod(
String methodName, LibraryElement library);
/// Return the element representing the getter that results from looking up
/// the given [getterName] in the superclass of this class with respect to the
/// given [library], ignoring abstract getters, or `null` if the look up
@ -2577,22 +2587,4 @@ abstract class _TmpSharedClassElement {
/// TODO(scheglov) Deprecate and remove it.
PropertyAccessorElement? lookUpInheritedConcreteSetter(
String setterName, LibraryElement library);
/// Return the element representing the setter that results from looking up
/// the given [setterName] in this class with respect to the given [library],
/// or `null` if the look up fails. The behavior of this method is defined by
/// the Dart Language Specification in section 16.15.2:
/// <blockquote>
/// The result of looking up getter (respectively setter) <i>m</i> in class
/// <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
/// instance getter (respectively setter) named <i>m</i> that is accessible to
/// <i>L</i>, then that getter (respectively setter) is the result of the
/// lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
/// of the lookup is the result of looking up getter (respectively setter)
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
/// lookup has failed.
/// </blockquote>
/// TODO(scheglov) Deprecate and remove it.
PropertyAccessorElement? lookUpSetter(
String setterName, LibraryElement library);
}

View file

@ -44,6 +44,7 @@ abstract class DartType {
/// the type has not, or cannot, be associated with an element. The former
/// case will occur if the element model is not yet complete; the latter case
/// will occur if this object represents an undefined type.
@Deprecated('Check for specific DartType subtype and use element2 instead')
Element? get element;
/// Return `true` if this type represents the bottom type.
@ -155,7 +156,7 @@ abstract class DartType {
///
/// For a [TypeParameterType] with a bound (declared or promoted), returns
/// the interface implemented by the bound.
InterfaceType? asInstanceOf(ClassElement element);
InterfaceType? asInstanceOf(InterfaceElement element);
/// Return the presentation of this type as it should appear when presented
/// to users in contexts such as error messages.
@ -277,9 +278,13 @@ abstract class InterfaceType implements ParameterizedType {
/// Return a list containing all of the constructors declared in this type.
List<ConstructorElement> get constructors;
@Deprecated('Use element2 instead')
@override
ClassElement get element;
/// Return the element representing the declaration of this type.
InterfaceElement get element2;
/// Return a list containing all of the interfaces that are implemented by
/// this interface. Note that this is <b>not</b>, in general, equivalent to
/// getting the interfaces from this type's element because the types returned
@ -391,7 +396,10 @@ abstract class InterfaceType implements ParameterizedType {
}
/// The type `Never` represents the uninhabited bottom type.
abstract class NeverType implements DartType {}
abstract class NeverType implements DartType {
@override
Element get element;
}
/// A type that can track substituted type parameters, either for itself after
/// instantiation, or from a surrounding context.

View file

@ -82,7 +82,7 @@ abstract class TypeProvider {
InterfaceType get mapObjectObjectType;
/// Return the type representing the built-in type `Never`.
DartType get neverType;
NeverType get neverType;
/// Return the element representing the built-in class `Null`.
ClassElement get nullElement;
@ -138,7 +138,7 @@ abstract class TypeProvider {
InterfaceType futureType(DartType valueType);
/// Return `true` if [element] cannot be extended, implemented, or mixed in.
bool isNonSubtypableClass(ClassElement element);
bool isNonSubtypableClass(InterfaceElement element);
/// Return 'true' if [id] is the name of a getter on the `Object` type.
bool isObjectGetter(String id);

View file

@ -299,7 +299,7 @@ class _TypeToConvert {
addElementsFrom(parameter.type);
}
} else if (type is InterfaceType) {
if (elements.add(type.element)) {
if (elements.add(type.element2)) {
for (DartType typeArgument in type.typeArguments) {
addElementsFrom(typeArgument);
}

View file

@ -563,7 +563,7 @@ class _IndexContributor extends GeneralizingAstVisitor {
_addSubtypeForClassDeclaration(node);
var declaredElement = node.declaredElement!;
if (node.extendsClause == null) {
ClassElement? objectElement = declaredElement.supertype?.element;
final objectElement = declaredElement.supertype?.element2;
recordRelationOffset(objectElement, IndexRelationKind.IS_EXTENDED_BY,
node.name2.offset, 0, true);
}
@ -1024,8 +1024,8 @@ class _IndexContributor extends GeneralizingAstVisitor {
return parent is Combinator || parent is Label;
}
void _recordIsAncestorOf(Element descendant, ClassElement ancestor,
bool includeThis, List<ClassElement> visitedElements) {
void _recordIsAncestorOf(Element descendant, InterfaceElement ancestor,
bool includeThis, List<InterfaceElement> visitedElements) {
if (visitedElements.contains(ancestor)) {
return;
}
@ -1037,21 +1037,26 @@ class _IndexContributor extends GeneralizingAstVisitor {
ancestor, IndexRelationKind.IS_ANCESTOR_OF, offset, length, false);
}
{
var superType = ancestor.supertype;
if (superType != null) {
_recordIsAncestorOf(
descendant, superType.element, true, visitedElements);
if (ancestor is ClassElement) {
var superType = ancestor.supertype;
if (superType != null) {
_recordIsAncestorOf(
descendant, superType.element2, true, visitedElements);
}
}
}
for (InterfaceType mixinType in ancestor.mixins) {
_recordIsAncestorOf(descendant, mixinType.element, true, visitedElements);
_recordIsAncestorOf(
descendant, mixinType.element2, true, visitedElements);
}
for (InterfaceType type in ancestor.superclassConstraints) {
_recordIsAncestorOf(descendant, type.element, true, visitedElements);
if (ancestor is MixinElement) {
for (InterfaceType type in ancestor.superclassConstraints) {
_recordIsAncestorOf(descendant, type.element2, true, visitedElements);
}
}
for (InterfaceType implementedType in ancestor.interfaces) {
_recordIsAncestorOf(
descendant, implementedType.element, true, visitedElements);
descendant, implementedType.element2, true, visitedElements);
}
}
}

View file

@ -286,7 +286,7 @@ class Search {
/// [Search] object, so should be only searched by it to avoid duplicate
/// results; and updated to take ownership if the file is not owned yet.
Future<List<SearchResult>> subTypes(
ClassElement? type, SearchedFiles searchedFiles) async {
InterfaceElement? type, SearchedFiles searchedFiles) async {
if (type == null) {
return const <SearchResult>[];
}

View file

@ -369,7 +369,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
}
// prepare ClassElement
if (type is InterfaceType) {
var element = type.element;
var element = type.element2;
// lookup for ==
var method = element.lookUpConcreteMethod("==", _currentLibrary);
if (method == null ||

View file

@ -252,7 +252,7 @@ class ConstantEvaluationEngine {
var superclass = constant.returnType.superclass;
if (superclass != null && !superclass.isDartCoreObject) {
var unnamedConstructor =
superclass.element.unnamedConstructor?.declaration;
superclass.element2.unnamedConstructor?.declaration;
if (unnamedConstructor != null && unnamedConstructor.isConst) {
callback(unnamedConstructor);
}
@ -1423,7 +1423,9 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
/// [identifier] is "length".
bool _isStringLength(
DartObjectImpl targetResult, SimpleIdentifier identifier) {
if (targetResult.type.element != _typeProvider.stringElement) {
final targetType = targetResult.type;
if (!(targetType is InterfaceType &&
targetType.element2 == _typeProvider.stringElement)) {
return false;
}
return identifier.name == 'length' &&

View file

@ -9,13 +9,13 @@ import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
class ClassHierarchy {
final Map<ClassElement, _Hierarchy> _map = {};
final Map<InterfaceElement, _Hierarchy> _map = {};
List<ClassHierarchyError> errors(ClassElement element) {
return _getHierarchy(element).errors;
}
List<InterfaceType> implementedInterfaces(ClassElement element) {
List<InterfaceType> implementedInterfaces(InterfaceElement element) {
return _getHierarchy(element).interfaces;
}
@ -30,7 +30,7 @@ class ClassHierarchy {
});
}
_Hierarchy _getHierarchy(ClassElement element) {
_Hierarchy _getHierarchy(InterfaceElement element) {
var hierarchy = _map[element];
if (hierarchy != null) {
@ -55,7 +55,7 @@ class ClassHierarchy {
interfacesMerger.add(type);
var substitution = Substitution.fromInterfaceType(type);
var rawInterfaces = implementedInterfaces(type.element);
var rawInterfaces = implementedInterfaces(type.element2);
for (var rawInterface in rawInterfaces) {
var newInterface =
substitution.substituteType(rawInterface) as InterfaceType;
@ -65,9 +65,13 @@ class ClassHierarchy {
}
}
append(element.supertype);
for (var type in element.superclassConstraints) {
append(type);
if (element is ClassElement) {
append(element.supertype);
}
if (element is MixinElement) {
for (var type in element.superclassConstraints) {
append(type);
}
}
for (var type in element.interfaces) {
append(type);
@ -114,7 +118,7 @@ class IncompatibleInterfacesClassHierarchyError extends ClassHierarchyError {
class InterfacesMerger {
final TypeSystemImpl _typeSystem;
final _map = <ClassElement, _ClassInterfaceType>{};
final Map<InterfaceElement, _ClassInterfaceType> _map = {};
InterfacesMerger(this._typeSystem);
@ -123,7 +127,7 @@ class InterfacesMerger {
}
void add(InterfaceType type) {
var element = type.element;
var element = type.element2;
var classResult = _map[element];
if (classResult == null) {
classResult = _ClassInterfaceType(_typeSystem);

View file

@ -144,7 +144,7 @@ class ElementDisplayStringBuilder {
}
void writeInterfaceType(InterfaceType type) {
_write(type.element.name);
_write(type.element2.name);
_writeTypeArguments(type.typeArguments);
_writeNullability(type.nullabilitySuffix);
}

View file

@ -299,7 +299,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
required NullabilitySuffix nullabilitySuffix,
}) {
return InterfaceTypeImpl(
element: this,
element2: this,
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
@ -436,20 +436,24 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
/// Object contains a definition of the getter it will occur last.
Iterable<PropertyAccessorElement> _implementationsOfGetter(
String getterName) sync* {
ClassElement? classElement = this;
HashSet<ClassElement> visitedClasses = HashSet<ClassElement>();
final visitedClasses = <InterfaceElement>{};
InterfaceElement? classElement = this;
while (classElement != null && visitedClasses.add(classElement)) {
var getter = classElement.getGetter(getterName);
if (getter != null) {
yield getter;
}
for (InterfaceType mixin in classElement.mixins.reversed) {
getter = mixin.element.getGetter(getterName);
getter = mixin.element2.getGetter(getterName);
if (getter != null) {
yield getter;
}
}
classElement = classElement.supertype?.element;
if (classElement is ClassElement) {
classElement = classElement.supertype?.element2;
} else {
break;
}
}
}
@ -465,20 +469,24 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
/// this class contains a definition of the method it will occur first, if
/// Object contains a definition of the method it will occur last.
Iterable<MethodElement> _implementationsOfMethod(String methodName) sync* {
ClassElement? classElement = this;
HashSet<ClassElement> visitedClasses = HashSet<ClassElement>();
final visitedClasses = <InterfaceElement>{};
InterfaceElement? classElement = this;
while (classElement != null && visitedClasses.add(classElement)) {
var method = classElement.getMethod(methodName);
if (method != null) {
yield method;
}
for (InterfaceType mixin in classElement.mixins.reversed) {
method = mixin.element.getMethod(methodName);
method = mixin.element2.getMethod(methodName);
if (method != null) {
yield method;
}
}
classElement = classElement.supertype?.element;
if (classElement is ClassElement) {
classElement = classElement.supertype?.element2;
} else {
break;
}
}
}
@ -495,20 +503,24 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
/// Object contains a definition of the setter it will occur last.
Iterable<PropertyAccessorElement> _implementationsOfSetter(
String setterName) sync* {
ClassElement? classElement = this;
HashSet<ClassElement> visitedClasses = HashSet<ClassElement>();
final visitedClasses = <InterfaceElement>{};
InterfaceElement? classElement = this;
while (classElement != null && visitedClasses.add(classElement)) {
var setter = classElement.getSetter(setterName);
if (setter != null) {
yield setter;
}
for (InterfaceType mixin in classElement.mixins.reversed) {
setter = mixin.element.getSetter(setterName);
setter = mixin.element2.getSetter(setterName);
if (setter != null) {
yield setter;
}
}
classElement = classElement.supertype?.element;
if (classElement is ClassElement) {
classElement = classElement.supertype?.element2;
} else {
break;
}
}
}
@ -689,11 +701,11 @@ class ClassElementImpl extends AbstractClassElementImpl {
@override
bool get hasNonFinalField {
List<ClassElement> classesToVisit = <ClassElement>[];
HashSet<ClassElement> visitedClasses = HashSet<ClassElement>();
final classesToVisit = <InterfaceElement>[];
final visitedClasses = <InterfaceElement>{};
classesToVisit.add(this);
while (classesToVisit.isNotEmpty) {
ClassElement currentElement = classesToVisit.removeAt(0);
final currentElement = classesToVisit.removeAt(0);
if (visitedClasses.add(currentElement)) {
// check fields
for (FieldElement field in currentElement.fields) {
@ -706,13 +718,14 @@ class ClassElementImpl extends AbstractClassElementImpl {
}
// check mixins
for (InterfaceType mixinType in currentElement.mixins) {
ClassElement mixinElement = mixinType.element;
classesToVisit.add(mixinElement);
classesToVisit.add(mixinType.element2);
}
// check super
InterfaceType? supertype = currentElement.supertype;
if (supertype != null) {
classesToVisit.add(supertype.element);
if (currentElement is ClassElement) {
final supertype = currentElement.supertype;
if (supertype != null) {
classesToVisit.add(supertype.element2);
}
}
}
}
@ -792,7 +805,7 @@ class ClassElementImpl extends AbstractClassElementImpl {
// No subclasses in the library.
for (var unit in library.units) {
for (var class_ in unit.classes) {
if (class_.supertype?.element == this) {
if (class_.supertype?.element2 == this) {
return false;
}
}
@ -929,7 +942,7 @@ class ClassElementImpl extends AbstractClassElementImpl {
return <ConstructorElement>[];
}
var superElement = supertype!.element as ClassElementImpl;
var superElement = supertype!.element2 as ClassElementImpl;
// First get the list of constructors of the superclass which need to be
// forwarded to this class.
@ -975,7 +988,7 @@ class ClassElementImpl extends AbstractClassElementImpl {
Substitution.fromPairs(superClassParameters, argumentTypes);
bool typeHasInstanceVariables(InterfaceType type) =>
type.element.fields.any((e) => !e.isSynthetic);
type.element2.fields.any((e) => !e.isSynthetic);
// Now create an implicit constructor for every constructor found above,
// substituting type parameters as appropriate.
@ -6342,7 +6355,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl
if (aliasedType_ is! InterfaceType) {
return false;
}
var aliasedClass = aliasedType_.element;
var aliasedClass = aliasedType_.element2;
var typeArguments = aliasedType_.typeArguments;
var typeParameterCount = typeParameters.length;
if (typeParameterCount != aliasedClass.typeParameters.length) {
@ -6356,7 +6369,9 @@ class TypeAliasElementImpl extends _ExistingElementImpl
!library.typeSystem.isSubtypeOf(aliasedBound, bound)) {
return false;
}
if (typeParameters[i] != typeArguments[i].element) {
final typeArgument = typeArguments[i];
if (typeArgument is TypeParameterType &&
typeParameters[i] != typeArgument.element) {
return false;
}
}
@ -6466,7 +6481,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl
);
} else if (type is InterfaceType) {
return InterfaceTypeImpl(
element: type.element,
element2: type.element2,
typeArguments: type.typeArguments,
nullabilitySuffix: resultNullability,
alias: InstantiatedTypeAliasElementImpl(

View file

@ -21,7 +21,7 @@ extension ElementAnnotationExtensions on ElementAnnotation {
if (element.isGetter) {
var type = element.returnType;
if (type is InterfaceType) {
interfaceElement = type.element;
interfaceElement = type.element2;
}
}
} else if (element is ConstructorElement) {
@ -41,7 +41,7 @@ extension ElementAnnotationExtensions on ElementAnnotation {
// may have been compiled with a different version of pkg:meta.
var index = kindObject.getField('index')!.toIntValue()!;
var targetKindClass =
(kindObject.type as InterfaceType).element as EnumElementImpl;
(kindObject.type as InterfaceType).element2 as EnumElementImpl;
// Instead, map constants to their TargetKind by comparing getter
// names.
var getter = targetKindClass.constants[index];

View file

@ -564,7 +564,7 @@ class GenericInferrer {
return;
}
if (errorNode is ConstructorName &&
!(errorNode.type.type as InterfaceType).element.hasOptionalTypeArgs) {
!(errorNode.type.type as InterfaceType).element2.hasOptionalTypeArgs) {
String constructorName = errorNode.name == null
? errorNode.type.name.name
: '${errorNode.type}.${errorNode.name}';
@ -592,7 +592,7 @@ class GenericInferrer {
if (element is VariableElement) {
// For variable elements, we check their type and possible alias type.
var type = element.type;
var typeElement = type.element;
final typeElement = type is InterfaceType ? type.element2 : null;
if (typeElement != null && typeElement.hasOptionalTypeArgs) {
return;
}

View file

@ -115,7 +115,7 @@ class InheritanceManager3 {
/// Return the result of [getInherited2] with [type] substitution.
ExecutableElement? getInherited(InterfaceType type, Name name) {
var rawElement = getInherited2(type.element, name);
var rawElement = getInherited2(type.element2, name);
if (rawElement == null) {
return null;
}
@ -237,7 +237,7 @@ class InheritanceManager3 {
bool forSuper = false,
}) {
var rawElement = getMember2(
type.element,
type.element2,
name,
concrete: concrete,
forMixinIndex: forMixinIndex,
@ -466,7 +466,7 @@ class InheritanceManager3 {
Interface? superTypeInterface;
if (superType != null) {
var substitution = Substitution.fromInterfaceType(superType);
superTypeInterface = getInterface(superType.element);
superTypeInterface = getInterface(superType.element2);
_addCandidates(
namedCandidates: namedCandidates,
substitution: substitution,
@ -492,7 +492,7 @@ class InheritanceManager3 {
// interfaces. Consider using `Map<Name, ExecutableElement>` here.
var mixinsConflicts = <List<Conflict>>[];
for (var mixin in element.mixins) {
var mixinElement = mixin.element;
var mixinElement = mixin.element2;
var substitution = Substitution.fromInterfaceType(mixin);
var mixinInterface = getInterface(mixinElement);
// `class X extends S with M1, M2 {}` is semantically a sequence of:
@ -583,7 +583,7 @@ class InheritanceManager3 {
_addCandidates(
namedCandidates: namedCandidates,
substitution: Substitution.fromInterfaceType(interface),
interface: getInterface(interface.element),
interface: getInterface(interface.element2),
isNonNullableByDefault: isNonNullableByDefault,
);
}
@ -660,7 +660,7 @@ class InheritanceManager3 {
var superCandidates = <Name, List<ExecutableElement>>{};
for (var constraint in element.superclassConstraints) {
var substitution = Substitution.fromInterfaceType(constraint);
var interfaceObj = getInterface(constraint.element);
var interfaceObj = getInterface(constraint.element2);
_addCandidates(
namedCandidates: superCandidates,
substitution: substitution,
@ -684,7 +684,7 @@ class InheritanceManager3 {
_addCandidates(
namedCandidates: interfaceCandidates,
substitution: Substitution.fromInterfaceType(interface),
interface: getInterface(interface.element),
interface: getInterface(interface.element2),
isNonNullableByDefault: isNonNullableByDefault,
);
}

View file

@ -23,7 +23,7 @@ import 'package:meta/meta.dart';
/// But it should be used where nullability does not make sense - to specify
/// superclasses, mixins, and implemented interfaces.
class InstantiatedClass {
final ClassElement element;
final InterfaceElement element;
final List<DartType> arguments;
final Substitution _substitution;
@ -37,7 +37,7 @@ class InstantiatedClass {
/// Return the [InstantiatedClass] that corresponds to the [type] - with the
/// same element and type arguments, ignoring its nullability suffix.
factory InstantiatedClass.of(InterfaceType type) {
return InstantiatedClass(type.element, type.typeArguments);
return InstantiatedClass(type.element2, type.typeArguments);
}
@override
@ -70,6 +70,11 @@ class InstantiatedClass {
/// Return the superclass of this type, or `null` if this type represents
/// the class 'Object'.
InstantiatedClass? get superclass {
final element = this.element;
if (element is! ClassElement) {
return null;
}
var supertype = element.supertype;
if (supertype == null) return null;
@ -83,8 +88,13 @@ class InstantiatedClass {
/// the declaration does not have an `on` clause, then the list will contain
/// the type for the class `Object`.
List<InstantiatedClass> get superclassConstraints {
var constraints = element.superclassConstraints;
return _toInstantiatedClasses(constraints);
final element = this.element;
if (element is MixinElement) {
var constraints = element.superclassConstraints;
return _toInstantiatedClasses(constraints);
} else {
return [];
}
}
@visibleForTesting
@ -126,7 +136,7 @@ class InstantiatedClass {
InterfaceTypeImpl withNullability(NullabilitySuffix nullability) {
return InterfaceTypeImpl(
element: element,
element2: element,
typeArguments: arguments,
nullabilitySuffix: nullability,
);
@ -190,10 +200,10 @@ class InterfaceLeastUpperBoundHelper {
return type1.withNullability(nullability);
}
if (type1.element == type2.element) {
if (type1.element2 == type2.element2) {
var args1 = type1.typeArguments;
var args2 = type2.typeArguments;
var params = type1.element.typeParameters;
var params = type1.element2.typeParameters;
assert(args1.length == args2.length);
assert(args1.length == params.length);
@ -226,7 +236,7 @@ class InterfaceLeastUpperBoundHelper {
}
return InterfaceTypeImpl(
element: type1.element,
element2: type1.element2,
typeArguments: args,
nullabilitySuffix: nullability,
);
@ -278,8 +288,9 @@ class InterfaceLeastUpperBoundHelper {
/// Return the length of the longest inheritance path from the [element] to
/// Object.
@visibleForTesting
static int computeLongestInheritancePathToObject(ClassElement element) {
return _computeLongestInheritancePathToObject(element, <ClassElement>{});
static int computeLongestInheritancePathToObject(InterfaceElement element) {
return _computeLongestInheritancePathToObject(
element, <InterfaceElement>{});
}
/// Add all of the superinterfaces of the given [type] to the given [set].
@ -339,9 +350,10 @@ class InterfaceLeastUpperBoundHelper {
/// is used to prevent infinite recursion in the case of a cyclic type
/// structure.
static int _computeLongestInheritancePathToObject(
ClassElement element, Set<ClassElement> visitedElements) {
InterfaceElement element, Set<InterfaceElement> visitedElements) {
// Object case
if (element.isDartCoreObject || visitedElements.contains(element)) {
if (element is ClassElement && element.isDartCoreObject ||
visitedElements.contains(element)) {
return 0;
}
int longestPath = 0;
@ -350,34 +362,40 @@ class InterfaceLeastUpperBoundHelper {
// loop through each of the superinterfaces recursively calling this
// method and keeping track of the longest path to return
for (InterfaceType interface in element.superclassConstraints) {
var pathLength = _computeLongestInheritancePathToObject(
interface.element, visitedElements);
longestPath = max(longestPath, 1 + pathLength);
if (element is MixinElement) {
for (InterfaceType interface in element.superclassConstraints) {
var pathLength = _computeLongestInheritancePathToObject(
interface.element2, visitedElements);
longestPath = max(longestPath, 1 + pathLength);
}
}
// loop through each of the superinterfaces recursively calling this
// method and keeping track of the longest path to return
for (InterfaceType interface in element.interfaces) {
var pathLength = _computeLongestInheritancePathToObject(
interface.element, visitedElements);
interface.element2, visitedElements);
longestPath = max(longestPath, 1 + pathLength);
}
if (element is! ClassElement) {
return longestPath;
}
var supertype = element.supertype;
if (supertype == null) {
return longestPath;
}
var superLength = _computeLongestInheritancePathToObject(
supertype.element, visitedElements);
supertype.element2, visitedElements);
var mixins = element.mixins;
for (var i = 0; i < mixins.length; i++) {
// class _X&S&M extends S implements M {}
// So, we choose the maximum length from S and M.
var mixinLength = _computeLongestInheritancePathToObject(
mixins[i].element,
mixins[i].element2,
visitedElements,
);
superLength = max(superLength, mixinLength);
@ -444,7 +462,7 @@ class LeastUpperBoundHelper {
LeastUpperBoundHelper(this._typeSystem);
InterfaceType get _interfaceTypeFunctionNone {
return _typeSystem.typeProvider.functionType.element.instantiate(
return _typeSystem.typeProvider.functionType.element2.instantiate(
typeArguments: const [],
nullabilitySuffix: NullabilitySuffix.none,
);

View file

@ -139,7 +139,7 @@ class NormalizeHelper {
// NORM(C<T0, ..., Tn>) = C<R0, ..., Rn> where Ri is NORM(Ti)
if (T is InterfaceType) {
return T.element.instantiate(
return T.element2.instantiate(
typeArguments: T.typeArguments.map(_normalize).toList(),
nullabilitySuffix: NullabilitySuffix.none,
);

View file

@ -113,7 +113,7 @@ class ReplaceTopBottomVisitor {
}
DartType _interfaceType(InterfaceType type, Variance variance) {
var typeParameters = type.element.typeParameters;
var typeParameters = type.element2.typeParameters;
if (typeParameters.isEmpty) {
return type;
}
@ -128,7 +128,7 @@ class ReplaceTopBottomVisitor {
}
return InterfaceTypeImpl(
element: type.element,
element2: type.element2,
nullabilitySuffix: type.nullabilitySuffix,
typeArguments: newTypeArguments,
);

View file

@ -85,7 +85,7 @@ class ReplacementVisitor
}
return InterfaceTypeImpl(
element: type.element,
element2: type.element2,
typeArguments: newTypeArguments ?? type.typeArguments,
nullabilitySuffix: newNullability ?? type.nullabilitySuffix,
alias: newAlias ?? type.alias,
@ -372,7 +372,7 @@ class ReplacementVisitor
}
var newTypeArguments = _typeArguments(
type.element.typeParameters,
type.element2.typeParameters,
type.typeArguments,
);

View file

@ -88,7 +88,7 @@ class RuntimeTypeEqualityVisitor
@override
bool visitInterfaceType(InterfaceType T1, DartType T2) {
if (T2 is InterfaceType &&
T1.element == T2.element &&
T1.element2 == T2.element2 &&
_compatibleNullability(T1, T2)) {
var T1_typeArguments = T1.typeArguments;
var T2_typeArguments = T2.typeArguments;

View file

@ -301,7 +301,7 @@ class SubtypeHelper {
}
bool _interfaceArguments(
ClassElement element,
InterfaceElement element,
InterfaceType subType,
InterfaceType superType,
) {
@ -446,8 +446,8 @@ class SubtypeHelper {
return false;
}
var subElement = subType.element;
var superElement = superType.element;
var subElement = subType.element2;
var superElement = superType.element2;
if (subElement == superElement) {
return _interfaceArguments(superElement, subType, superType);
}
@ -458,7 +458,7 @@ class SubtypeHelper {
}
for (var interface in subElement.allSupertypes) {
if (interface.element == superElement) {
if (interface.element2 == superElement) {
var substitution = Substitution.fromInterfaceType(subType);
var substitutedInterface =
substitution.substituteType(interface) as InterfaceType;

View file

@ -271,7 +271,7 @@ class TopMergeHelper {
}
InterfaceType _interfaceTypes(InterfaceType T, InterfaceType S) {
if (T.element != S.element) {
if (T.element2 != S.element2) {
throw _TopMergeStateError(T, S, 'Different class elements');
}
@ -284,7 +284,7 @@ class TopMergeHelper {
T_arguments.length,
(i) => topMerge(T_arguments[i], S_arguments[i]),
);
return T.element.instantiate(
return T.element2.instantiate(
typeArguments: arguments,
nullabilitySuffix: NullabilitySuffix.none,
);

View file

@ -25,6 +25,11 @@ class DynamicTypeImpl extends TypeImpl implements DynamicType {
/// Prevent the creation of instances of this class.
DynamicTypeImpl._() : super(DynamicElementImpl());
@override
Element get element {
return super.element!;
}
@override
int get hashCode => 1;
@ -425,6 +430,9 @@ class InstantiatedTypeAliasElementImpl implements InstantiatedTypeAliasElement {
/// A concrete implementation of an [InterfaceType].
class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
final InterfaceElement element2;
@override
final List<DartType> typeArguments;
@ -441,18 +449,17 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
List<MethodElement>? _methods;
InterfaceTypeImpl({
required ClassElement element,
required this.element2,
required this.typeArguments,
required this.nullabilitySuffix,
InstantiatedTypeAliasElement? alias,
}) : super(element, alias: alias) {
var typeParameters = element.typeParameters;
}) : super(element2 as ClassElement, alias: alias) {
var typeParameters = element2.typeParameters;
if (typeArguments.length != typeParameters.length) {
throw ArgumentError(
'[typeParameters.length: ${typeParameters.length}]'
'[typeArguments.length: ${typeArguments.length}]'
'[element: $element]'
'[reference: ${element is ClassElementImpl ? element.reference : null}]'
'[element: $element2]'
'[typeParameters: $typeParameters]'
'[typeArguments: $typeArguments]',
);
@ -462,7 +469,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
List<PropertyAccessorElement> get accessors {
if (_accessors == null) {
List<PropertyAccessorElement> accessors = element.accessors;
List<PropertyAccessorElement> accessors = element2.accessors;
var members = <PropertyAccessorElement>[];
for (int i = 0; i < accessors.length; i++) {
members.add(PropertyAccessorMember.from(accessors[i], this)!);
@ -475,7 +482,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
List<InterfaceType> get allSupertypes {
var substitution = Substitution.fromInterfaceType(this);
return element.allSupertypes
return element2.allSupertypes
.map((t) => substitution.substituteType(t) as InterfaceType)
.toList();
}
@ -483,7 +490,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
List<ConstructorElement> get constructors {
if (_constructors == null) {
List<ConstructorElement> constructors = element.constructors;
List<ConstructorElement> constructors = element2.constructors;
var members = <ConstructorElement>[];
for (int i = 0; i < constructors.length; i++) {
members.add(ConstructorMember.from(constructors[i], this));
@ -493,108 +500,110 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
return _constructors!;
}
@Deprecated('Check for specific DartType subtype and use element2 instead')
@override
ClassElement get element => super.element as ClassElement;
@override
int get hashCode {
return element.hashCode;
return element2.hashCode;
}
@override
List<InterfaceType> get interfaces {
return _instantiateSuperTypes(element.interfaces);
return _instantiateSuperTypes(element2.interfaces);
}
@override
bool get isDartAsyncFuture {
return element.name == "Future" && element.library.isDartAsync;
return element2.name == "Future" && element2.library.isDartAsync;
}
@override
bool get isDartAsyncFutureOr {
return element.name == "FutureOr" && element.library.isDartAsync;
return element2.name == "FutureOr" && element2.library.isDartAsync;
}
@override
bool get isDartAsyncStream {
return element.name == "Stream" && element.library.isDartAsync;
return element2.name == "Stream" && element2.library.isDartAsync;
}
@override
bool get isDartCoreBool {
return element.name == "bool" && element.library.isDartCore;
return element2.name == "bool" && element2.library.isDartCore;
}
@override
bool get isDartCoreDouble {
return element.name == "double" && element.library.isDartCore;
return element2.name == "double" && element2.library.isDartCore;
}
@override
bool get isDartCoreEnum {
return element.isDartCoreEnum;
final element2 = this.element2;
return element2 is ClassElement && element2.isDartCoreEnum;
}
@override
bool get isDartCoreFunction {
return element.name == "Function" && element.library.isDartCore;
return element2.name == "Function" && element2.library.isDartCore;
}
@override
bool get isDartCoreInt {
return element.name == "int" && element.library.isDartCore;
return element2.name == "int" && element2.library.isDartCore;
}
@override
bool get isDartCoreIterable {
return element.name == "Iterable" && element.library.isDartCore;
return element2.name == "Iterable" && element2.library.isDartCore;
}
@override
bool get isDartCoreList {
return element.name == "List" && element.library.isDartCore;
return element2.name == "List" && element2.library.isDartCore;
}
@override
bool get isDartCoreMap {
return element.name == "Map" && element.library.isDartCore;
return element2.name == "Map" && element2.library.isDartCore;
}
@override
bool get isDartCoreNull {
return element.name == "Null" && element.library.isDartCore;
return element2.name == "Null" && element2.library.isDartCore;
}
@override
bool get isDartCoreNum {
return element.name == "num" && element.library.isDartCore;
return element2.name == "num" && element2.library.isDartCore;
}
@override
bool get isDartCoreObject {
return element.name == "Object" && element.library.isDartCore;
return element2.name == "Object" && element2.library.isDartCore;
}
@override
bool get isDartCoreSet {
return element.name == "Set" && element.library.isDartCore;
return element2.name == "Set" && element2.library.isDartCore;
}
@override
bool get isDartCoreString {
return element.name == "String" && element.library.isDartCore;
return element2.name == "String" && element2.library.isDartCore;
}
@override
bool get isDartCoreSymbol {
return element.name == "Symbol" && element.library.isDartCore;
return element2.name == "Symbol" && element2.library.isDartCore;
}
@override
List<MethodElement> get methods {
if (_methods == null) {
List<MethodElement> methods = element.methods;
List<MethodElement> methods = element2.methods;
var members = <MethodElement>[];
for (int i = 0; i < methods.length; i++) {
members.add(MethodMember.from(methods[i], this)!);
@ -606,7 +615,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
List<InterfaceType> get mixins {
List<InterfaceType> mixins = element.mixins;
List<InterfaceType> mixins = element2.mixins;
return _instantiateSuperTypes(mixins);
}
@ -616,7 +625,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
InterfaceType? get superclass {
var supertype = element.supertype;
var supertype = element2.supertype;
if (supertype == null) {
return null;
}
@ -627,12 +636,17 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
List<InterfaceType> get superclassConstraints {
List<InterfaceType> constraints = element.superclassConstraints;
return _instantiateSuperTypes(constraints);
final element2 = this.element2;
if (element2 is MixinElement) {
final constraints = element2.superclassConstraints;
return _instantiateSuperTypes(constraints);
} else {
return [];
}
}
InheritanceManager3 get _inheritanceManager =>
(element.library.session as AnalysisSessionImpl).inheritanceManager;
(element2.library.session as AnalysisSessionImpl).inheritanceManager;
@override
bool operator ==(Object other) {
@ -643,7 +657,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
if (other.nullabilitySuffix != nullabilitySuffix) {
return false;
}
return other.element == element &&
return other.element2 == element2 &&
TypeImpl.equalArrays(other.typeArguments, typeArguments);
}
return false;
@ -668,13 +682,13 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
@override
InterfaceType? asInstanceOf(ClassElement targetElement) {
if (element == targetElement) {
InterfaceType? asInstanceOf(InterfaceElement targetElement) {
if (element2 == targetElement) {
return this;
}
for (var rawInterface in element.allSupertypes) {
if (rawInterface.element == targetElement) {
for (var rawInterface in element2.allSupertypes) {
if (rawInterface.element2 == targetElement) {
var substitution = Substitution.fromInterfaceType(this);
return substitution.substituteType(rawInterface) as InterfaceType;
}
@ -685,15 +699,15 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
PropertyAccessorElement? getGetter(String getterName) =>
PropertyAccessorMember.from(element.getGetter(getterName), this);
PropertyAccessorMember.from(element2.getGetter(getterName), this);
@override
MethodElement? getMethod(String methodName) =>
MethodMember.from(element.getMethod(methodName), this);
MethodMember.from(element2.getMethod(methodName), this);
@override
PropertyAccessorElement? getSetter(String setterName) =>
PropertyAccessorMember.from(element.getSetter(setterName), this);
PropertyAccessorMember.from(element2.getSetter(setterName), this);
@override
ConstructorElement? lookUpConstructor(
@ -701,9 +715,9 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
// prepare base ConstructorElement
ConstructorElement? constructorElement;
if (constructorName == null) {
constructorElement = element.unnamedConstructor;
constructorElement = element2.unnamedConstructor;
} else {
constructorElement = element.getNamedConstructor(constructorName);
constructorElement = element2.getNamedConstructor(constructorName);
}
// not found or not accessible
if (constructorElement == null ||
@ -746,8 +760,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
if (recoveryStatic) {
final element = this.element as AbstractClassElementImpl;
return element.lookupStaticGetter(name, library);
final element2 = this.element2 as AbstractClassElementImpl;
return element2.lookupStaticGetter(name, library);
}
return null;
@ -785,8 +799,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
if (recoveryStatic) {
final element = this.element as AbstractClassElementImpl;
return element.lookupStaticMethod(name, library);
final element2 = this.element2 as AbstractClassElementImpl;
return element2.lookupStaticMethod(name, library);
}
return null;
@ -824,8 +838,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
}
if (recoveryStatic) {
final element = this.element as AbstractClassElementImpl;
return element.lookupStaticSetter(name, library);
final element2 = this.element2 as AbstractClassElementImpl;
return element2.lookupStaticSetter(name, library);
}
return null;
@ -844,7 +858,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
if (this.nullabilitySuffix == nullabilitySuffix) return this;
return InterfaceTypeImpl(
element: element,
element2: element2,
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
@ -853,7 +867,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
List<InterfaceType> _instantiateSuperTypes(List<InterfaceType> defined) {
if (defined.isEmpty) return defined;
var typeParameters = element.typeParameters;
var typeParameters = element2.typeParameters;
if (typeParameters.isEmpty) return defined;
var substitution = Substitution.fromInterfaceType(this);
@ -1041,7 +1055,7 @@ abstract class TypeImpl implements DartType {
void appendTo(ElementDisplayStringBuilder builder);
@override
InterfaceType? asInstanceOf(ClassElement targetElement) => null;
InterfaceType? asInstanceOf(InterfaceElement targetElement) => null;
@override
String getDisplayString({
@ -1191,7 +1205,7 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
}
@override
InterfaceType? asInstanceOf(ClassElement targetElement) {
InterfaceType? asInstanceOf(InterfaceElement targetElement) {
return bound.asInstanceOf(targetElement);
}

View file

@ -183,7 +183,7 @@ abstract class Substitution {
if (type.typeArguments.isEmpty) {
return _NullSubstitution.instance;
}
return fromPairs(type.element.typeParameters, type.typeArguments);
return fromPairs(type.element2.typeParameters, type.typeArguments);
}
/// Substitutes each parameter to the type it maps to in [map].
@ -514,7 +514,7 @@ abstract class _TypeSubstitutor
}
return InterfaceTypeImpl(
element: type.element,
element2: type.element2,
typeArguments: typeArguments,
nullabilitySuffix: type.nullabilitySuffix,
alias: alias,

View file

@ -543,7 +543,7 @@ class TypeConstraintGatherer {
// holds under constraints `C0 + ... + Ck`:
// If `Mi` is a subtype match for `Ni` with respect to L under
// constraints `Ci`.
if (P.element == Q.element) {
if (P.element2 == Q.element2) {
if (!_interfaceType_arguments(P, Q, leftSchema)) {
return false;
}
@ -555,10 +555,10 @@ class TypeConstraintGatherer {
// If `C1<B0, ..., Bj>` is a superinterface of `C0<M0, ..., Mk>` and
// `C1<B0, ..., Bj>` is a subtype match for `C1<N0, ..., Nj>` with
// respect to `L` under constraints `C`.
var C0 = P.element;
var C1 = Q.element;
var C0 = P.element2;
var C1 = Q.element2;
for (var interface in C0.allSupertypes) {
if (interface.element == C1) {
if (interface.element2 == C1) {
var substitution = Substitution.fromInterfaceType(P);
return _interfaceType_arguments(
substitution.substituteType(interface) as InterfaceType,
@ -578,13 +578,13 @@ class TypeConstraintGatherer {
InterfaceType Q,
bool leftSchema,
) {
assert(P.element == Q.element);
assert(P.element2 == Q.element2);
var rewind = _constraints.length;
for (var i = 0; i < P.typeArguments.length; i++) {
var variance =
(P.element.typeParameters[i] as TypeParameterElementImpl).variance;
(P.element2.typeParameters[i] as TypeParameterElementImpl).variance;
var M = P.typeArguments[i];
var N = Q.typeArguments[i];
if ((variance.isCovariant || variance.isInvariant) &&

View file

@ -79,7 +79,7 @@ const Set<String> _nonSubtypableDartTypedDataClassNames = {
abstract class TypeProviderBase implements TypeProvider {
@override
bool isObjectGetter(String id) {
var element = objectType.element.getGetter(id);
var element = objectType.element2.getGetter(id);
return element != null && !element.isStatic;
}
@ -90,7 +90,7 @@ abstract class TypeProviderBase implements TypeProvider {
@override
bool isObjectMethod(String id) {
var element = objectType.element.getMethod(id);
var element = objectType.element2.getMethod(id);
return element != null && !element.isStatic;
}
}
@ -238,7 +238,7 @@ class TypeProviderImpl extends TypeProviderBase {
var element = enumElement;
if (element != null) {
_enumType = InterfaceTypeImpl(
element: element,
element2: element,
typeArguments: const [],
nullabilitySuffix: _nullabilitySuffix,
);
@ -255,7 +255,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get futureDynamicType {
return _futureDynamicType ??= InterfaceTypeImpl(
element: futureElement,
element2: futureElement,
typeArguments: [dynamicType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -269,7 +269,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get futureNullType {
return _futureNullType ??= InterfaceTypeImpl(
element: futureElement,
element2: futureElement,
typeArguments: [nullType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -283,7 +283,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get futureOrNullType {
return _futureOrNullType ??= InterfaceTypeImpl(
element: futureOrElement,
element2: futureOrElement,
typeArguments: [nullType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -306,7 +306,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get iterableDynamicType {
return _iterableDynamicType ??= InterfaceTypeImpl(
element: iterableElement,
element2: iterableElement,
typeArguments: [dynamicType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -320,7 +320,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get iterableObjectType {
return _iterableObjectType ??= InterfaceTypeImpl(
element: iterableElement,
element2: iterableElement,
typeArguments: [objectType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -339,14 +339,14 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get mapObjectObjectType {
return _mapObjectObjectType ??= InterfaceTypeImpl(
element: mapElement,
element2: mapElement,
typeArguments: [objectType, objectType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
DartType get neverType => isNonNullableByDefault
NeverType get neverType => isNonNullableByDefault
? NeverTypeImpl.instance
: NeverTypeImpl.instanceLegacy;
@ -403,7 +403,7 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get streamDynamicType {
return _streamDynamicType ??= InterfaceTypeImpl(
element: streamElement,
element2: streamElement,
typeArguments: [dynamicType],
nullabilitySuffix: _nullabilitySuffix,
);
@ -467,7 +467,7 @@ class TypeProviderImpl extends TypeProviderBase {
}
@override
bool isNonSubtypableClass(ClassElement element) {
bool isNonSubtypableClass(InterfaceElement element) {
var name = element.name;
if (_nonSubtypableClassNames.contains(name)) {
var libraryUriStr = element.library.source.uri.toString();
@ -544,7 +544,7 @@ class TypeProviderImpl extends TypeProviderBase {
}
return InterfaceTypeImpl(
element: element,
element2: element,
typeArguments: typeArguments,
nullabilitySuffix: _nullabilitySuffix,
);

View file

@ -332,7 +332,7 @@ class TypeSystemImpl implements TypeSystem {
}
}
return candidates
.where((type) => type.element.typeParameters.isNotEmpty)
.where((type) => type.element2.typeParameters.isNotEmpty)
.toList();
}
@ -345,7 +345,7 @@ class TypeSystemImpl implements TypeSystem {
FunctionType? getCallMethodType(DartType t) {
if (t is InterfaceType) {
return t
.lookUpMethod2(FunctionElement.CALL_METHOD_NAME, t.element.library)
.lookUpMethod2(FunctionElement.CALL_METHOD_NAME, t.element2.library)
?.type;
}
return null;
@ -555,7 +555,7 @@ class TypeSystemImpl implements TypeSystem {
return type.instantiate(typeArguments);
} else if (type is InterfaceTypeImpl) {
// TODO(scheglov) Use `ClassElement.instantiate()`, don't use raw types.
return type.element.instantiate(
return type.element2.instantiate(
typeArguments: typeArguments,
nullabilitySuffix: type.nullabilitySuffix,
);
@ -1595,7 +1595,7 @@ class TypeSystemImpl implements TypeSystem {
if (type is FunctionType) {
return type.typeFormals;
} else if (type is InterfaceType) {
return type.element.typeParameters;
return type.element2.typeParameters;
} else {
return const <TypeParameterElement>[];
}

View file

@ -84,8 +84,8 @@ class TypeBoundedHelper {
typeParameters = alias.element.typeParameters;
typeArguments = alias.typeArguments;
} else if (type is InterfaceType) {
elementName = type.element.name;
typeParameters = type.element.typeParameters;
elementName = type.element2.name;
typeParameters = type.element2.typeParameters;
typeArguments = type.typeArguments;
} else {
return const RegularBoundedTypeResult._();

View file

@ -374,7 +374,7 @@ class AnnotationResolver {
ExecutableElement? getter;
var aliasedType = typeAliasElement.aliasedType;
if (aliasedType is InterfaceType) {
var classElement = aliasedType.element;
var classElement = aliasedType.element2;
if (getterName != null) {
getter = classElement.getGetter(getterName.name);
getter = _resolver.toLegacyElement(getter);

View file

@ -184,7 +184,7 @@ class AstRewriter {
node: node,
typeIdentifier: target,
constructorIdentifier: methodName,
classElement: aliasedType.element,
classElement: aliasedType.element2,
);
}
}
@ -209,7 +209,7 @@ class AstRewriter {
node: node,
typeNameIdentifier: target,
constructorIdentifier: methodName,
classElement: aliasedType.element,
classElement: aliasedType.element2,
);
}
}
@ -262,7 +262,9 @@ class AstRewriter {
// typedef X = C;
// X.named
return _toConstructorReference_prefixed(
node: node, classElement: aliasedType.element);
node: node,
classElement: aliasedType.element2,
);
}
}
return node;
@ -350,7 +352,7 @@ class AstRewriter {
node: node,
receiver: receiverIdentifier,
typeArguments: typeArguments,
classElement: aliasedType.element,
classElement: aliasedType.element2,
);
}
}
@ -374,7 +376,7 @@ class AstRewriter {
required MethodInvocationImpl node,
required PrefixedIdentifierImpl typeNameIdentifier,
required SimpleIdentifierImpl constructorIdentifier,
required ClassElement classElement,
required InterfaceElement classElement,
}) {
var constructorElement = classElement.getNamedConstructor(
constructorIdentifier.name,
@ -408,7 +410,7 @@ class AstRewriter {
AstNode _toConstructorReference_prefixed({
required PrefixedIdentifierImpl node,
required ClassElement classElement,
required InterfaceElement classElement,
}) {
var name = node.identifier.name;
var constructorElement = name == 'new'
@ -435,7 +437,7 @@ class AstRewriter {
required PropertyAccessImpl node,
required IdentifierImpl receiver,
required TypeArgumentListImpl? typeArguments,
required ClassElement classElement,
required InterfaceElement classElement,
}) {
var name = node.propertyName.name;
var constructorElement = name == 'new'
@ -514,7 +516,7 @@ class AstRewriter {
required MethodInvocationImpl node,
required SimpleIdentifierImpl typeIdentifier,
required SimpleIdentifierImpl constructorIdentifier,
required ClassElement classElement,
required InterfaceElement classElement,
}) {
var name = constructorIdentifier.name;
var constructorElement = classElement.getNamedConstructor(name);

View file

@ -53,7 +53,9 @@ class ConstructorReferenceResolver {
// to avoid reporting redundant errors.
var enclosingElement = node.constructorName.type.name.staticElement;
if (enclosingElement is TypeAliasElement) {
enclosingElement = enclosingElement.aliasedType.element;
final aliasedType = enclosingElement.aliasedType;
enclosingElement =
aliasedType is InterfaceType ? aliasedType.element2 : null;
}
// TODO(srawlins): Handle `enclosingElement` being a function typedef:
// typedef F<T> = void Function(); var a = F<int>.extensionOnType;`.

View file

@ -164,7 +164,7 @@ class FunctionReferenceResolver {
// Otherwise, a 'call' method on the interface, or on an applicable
// extension method applies.
return type.lookUpMethod2(
FunctionElement.CALL_METHOD_NAME, type.element.library) ??
FunctionElement.CALL_METHOD_NAME, type.element2.library) ??
_extensionResolver
.findExtension(type, node, FunctionElement.CALL_METHOD_NAME)
.getter;
@ -777,7 +777,7 @@ class FunctionReferenceResolver {
/// Returns the element that represents the property named [propertyName] on
/// [classElement].
ExecutableElement? _resolveStaticElement(
ClassElement classElement, SimpleIdentifier propertyName) {
InterfaceElement classElement, SimpleIdentifier propertyName) {
String name = propertyName.name;
ExecutableElement? element;
if (propertyName.inSetterContext()) {
@ -846,7 +846,7 @@ class FunctionReferenceResolver {
} else if (receiverElement is TypeAliasElement) {
var aliasedType = receiverElement.aliasedType;
if (aliasedType is InterfaceType) {
var element = _resolveStaticElement(aliasedType.element, name);
var element = _resolveStaticElement(aliasedType.element2, name);
name.staticElement = element;
return element?.referenceType;
} else {

View file

@ -143,7 +143,7 @@ class MethodInvocationResolver with ScopeHelpers {
var aliasedType = element.aliasedType;
if (aliasedType is InterfaceType) {
_resolveReceiverTypeLiteral(
node, aliasedType.element, nameNode, name, whyNotPromotedList,
node, aliasedType.element2, nameNode, name, whyNotPromotedList,
contextType: contextType);
return;
}
@ -347,7 +347,7 @@ class MethodInvocationResolver with ScopeHelpers {
/// Given that we are accessing a property of the given [classElement] with the
/// given [propertyName], return the element that represents the property.
Element? _resolveElement(
ClassElement classElement, SimpleIdentifier propertyName) {
InterfaceElement classElement, SimpleIdentifier propertyName) {
// TODO(scheglov) Replace with class hierarchy.
String name = propertyName.name;
Element? element;
@ -819,7 +819,7 @@ class MethodInvocationResolver with ScopeHelpers {
String receiverClassName = '<unknown>';
if (receiverType is InterfaceType) {
receiverClassName = receiverType.element.name;
receiverClassName = receiverType.element2.name;
} else if (receiverType is FunctionType) {
receiverClassName = 'Function';
}
@ -835,13 +835,13 @@ class MethodInvocationResolver with ScopeHelpers {
void _resolveReceiverTypeLiteral(
MethodInvocationImpl node,
ClassElement receiver,
InterfaceElement receiver,
SimpleIdentifierImpl nameNode,
String name,
List<WhyNotPromotedGetter> whyNotPromotedList,
{required DartType? contextType}) {
if (node.isCascaded) {
receiver = _typeType.element;
receiver = _typeType.element2;
}
var element = _resolveElement(receiver, nameNode);

View file

@ -237,7 +237,7 @@ class NamedTypeResolver with ScopeHelpers {
if (element is ClassElement) {
if (identical(node, withClause_namedType)) {
for (var mixin in enclosingClass!.mixins) {
if (mixin.element == element) {
if (mixin.element2 == element) {
return mixin;
}
}

View file

@ -370,7 +370,7 @@ class PropertyElementResolver with ScopeHelpers {
if (target is Identifier) {
var targetElement = target.staticElement;
if (targetElement is ClassElement) {
return _resolveTargetClassElement(
return _resolveTargetInterfaceElement(
typeReference: targetElement,
isCascaded: isCascaded,
propertyName: propertyName,
@ -380,8 +380,8 @@ class PropertyElementResolver with ScopeHelpers {
} else if (targetElement is TypeAliasElement) {
var aliasedType = targetElement.aliasedType;
if (aliasedType is InterfaceType) {
return _resolveTargetClassElement(
typeReference: aliasedType.element,
return _resolveTargetInterfaceElement(
typeReference: aliasedType.element2,
isCascaded: isCascaded,
propertyName: propertyName,
hasRead: hasRead,
@ -495,87 +495,6 @@ class PropertyElementResolver with ScopeHelpers {
);
}
PropertyElementResolverResult _resolveTargetClassElement({
required ClassElement typeReference,
required bool isCascaded,
required SimpleIdentifier propertyName,
required bool hasRead,
required bool hasWrite,
}) {
if (isCascaded) {
typeReference = _resolver.typeProvider.typeType.element;
}
ExecutableElement? readElement;
ExecutableElement? readElementRecovery;
if (hasRead) {
readElement = typeReference.getGetter(propertyName.name);
if (readElement != null && !_isAccessible(readElement)) {
readElement = null;
}
if (readElement == null) {
readElement = typeReference.getMethod(propertyName.name);
if (readElement != null && !_isAccessible(readElement)) {
readElement = null;
}
}
if (readElement != null) {
readElement = _resolver.toLegacyElement(readElement);
if (_checkForStaticAccessToInstanceMember(propertyName, readElement)) {
readElementRecovery = readElement;
readElement = null;
}
} else {
var code = typeReference.isEnum
? CompileTimeErrorCode.UNDEFINED_ENUM_CONSTANT
: CompileTimeErrorCode.UNDEFINED_GETTER;
errorReporter.reportErrorForNode(
code,
propertyName,
[propertyName.name, typeReference.name],
);
}
}
ExecutableElement? writeElement;
ExecutableElement? writeElementRecovery;
if (hasWrite) {
writeElement = typeReference.getSetter(propertyName.name);
if (writeElement != null) {
writeElement = _resolver.toLegacyElement(writeElement);
if (!_isAccessible(writeElement)) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.PRIVATE_SETTER,
propertyName,
[propertyName.name],
);
}
if (_checkForStaticAccessToInstanceMember(propertyName, writeElement)) {
writeElementRecovery = writeElement;
writeElement = null;
}
} else {
// Recovery, try to use getter.
writeElementRecovery = typeReference.getGetter(propertyName.name);
AssignmentVerifier(_definingLibrary, errorReporter).verify(
node: propertyName,
requested: null,
recovery: writeElementRecovery,
receiverType: typeReference.thisType,
);
}
}
return PropertyElementResolverResult(
readElementRequested: readElement,
readElementRecovery: readElementRecovery,
writeElementRequested: writeElement,
writeElementRecovery: writeElementRecovery,
);
}
PropertyElementResolverResult _resolveTargetExtensionElement({
required ExtensionElement extension,
required SimpleIdentifier propertyName,
@ -696,6 +615,87 @@ class PropertyElementResolver with ScopeHelpers {
);
}
PropertyElementResolverResult _resolveTargetInterfaceElement({
required InterfaceElement typeReference,
required bool isCascaded,
required SimpleIdentifier propertyName,
required bool hasRead,
required bool hasWrite,
}) {
if (isCascaded) {
typeReference = _resolver.typeProvider.typeType.element2;
}
ExecutableElement? readElement;
ExecutableElement? readElementRecovery;
if (hasRead) {
readElement = typeReference.getGetter(propertyName.name);
if (readElement != null && !_isAccessible(readElement)) {
readElement = null;
}
if (readElement == null) {
readElement = typeReference.getMethod(propertyName.name);
if (readElement != null && !_isAccessible(readElement)) {
readElement = null;
}
}
if (readElement != null) {
readElement = _resolver.toLegacyElement(readElement);
if (_checkForStaticAccessToInstanceMember(propertyName, readElement)) {
readElementRecovery = readElement;
readElement = null;
}
} else {
var code = typeReference is EnumElement
? CompileTimeErrorCode.UNDEFINED_ENUM_CONSTANT
: CompileTimeErrorCode.UNDEFINED_GETTER;
errorReporter.reportErrorForNode(
code,
propertyName,
[propertyName.name, typeReference.name],
);
}
}
ExecutableElement? writeElement;
ExecutableElement? writeElementRecovery;
if (hasWrite) {
writeElement = typeReference.getSetter(propertyName.name);
if (writeElement != null) {
writeElement = _resolver.toLegacyElement(writeElement);
if (!_isAccessible(writeElement)) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.PRIVATE_SETTER,
propertyName,
[propertyName.name],
);
}
if (_checkForStaticAccessToInstanceMember(propertyName, writeElement)) {
writeElementRecovery = writeElement;
writeElement = null;
}
} else {
// Recovery, try to use getter.
writeElementRecovery = typeReference.getGetter(propertyName.name);
AssignmentVerifier(_definingLibrary, errorReporter).verify(
node: propertyName,
requested: null,
recovery: writeElementRecovery,
receiverType: typeReference.thisType,
);
}
}
return PropertyElementResolverResult(
readElementRequested: readElement,
readElementRecovery: readElementRecovery,
writeElementRequested: writeElement,
writeElementRecovery: writeElementRecovery,
);
}
PropertyElementResolverResult _resolveTargetPrefixElement({
required PrefixElement target,
required SimpleIdentifier identifier,
@ -755,7 +755,7 @@ class PropertyElementResolver with ScopeHelpers {
if (hasRead) {
var name = Name(_definingLibrary.source.uri, propertyName.name);
readElement = _resolver.inheritance
.getMember2(targetType.element, name, forSuper: true);
.getMember2(targetType.element2, name, forSuper: true);
if (readElement != null) {
readElement = _resolver.toLegacyElement(readElement);
@ -765,7 +765,7 @@ class PropertyElementResolver with ScopeHelpers {
// But we would like to give the user at least some resolution.
// So, we retry simply looking for an inherited member.
readElement =
_resolver.inheritance.getInherited2(targetType.element, name);
_resolver.inheritance.getInherited2(targetType.element2, name);
if (readElement != null) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,

View file

@ -1348,8 +1348,8 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
DartType type = namedType.typeOrThrow;
if (type is InterfaceType) {
ClassElement element = type.element;
if (element.isEnum || element.isMixin && asClass) {
final element = type.element2;
if (element is EnumElement || element is MixinElement && asClass) {
_errorReporter.reportErrorForNode(errorCode, namedType);
return;
}

View file

@ -236,7 +236,7 @@ class TypePropertyResolver {
_needsGetterError = _getterRequested == null;
if (_getterRequested == null && recoverWithStatic) {
var classElement = type.element as AbstractClassElementImpl;
var classElement = type.element2 as AbstractClassElementImpl;
_getterRecovery ??=
classElement.lookupStaticGetter(_name, _definingLibrary) ??
classElement.lookupStaticMethod(_name, _definingLibrary);
@ -249,7 +249,7 @@ class TypePropertyResolver {
_needsSetterError = _setterRequested == null;
if (_setterRequested == null && recoverWithStatic) {
var classElement = type.element as AbstractClassElementImpl;
var classElement = type.element2 as AbstractClassElementImpl;
_setterRecovery ??=
classElement.lookupStaticSetter(_name, _definingLibrary);
_needsSetterError = _setterRecovery == null;

View file

@ -691,10 +691,12 @@ class TypedLiteralResolver {
if (literalType.isDynamic) {
// The literal is ambiguous, and further analysis won't resolve the
// ambiguity. Leave it as neither a set nor a map.
} else if (literalType.element == _typeProvider.mapElement) {
} else if (literalType is InterfaceType &&
literalType.element2 == _typeProvider.mapElement) {
node.becomeMap();
} else {
assert(literalType.element == _typeProvider.setElement);
assert(literalType is InterfaceType &&
literalType.element2 == _typeProvider.setElement);
node.becomeSet();
}
if (_strictInference &&

View file

@ -36,7 +36,7 @@ class Variance {
var result = unrelated;
for (int i = 0; i < type.typeArguments.length; ++i) {
var argument = type.typeArguments[i];
var parameter = type.element.typeParameters[i];
var parameter = type.element2.typeParameters[i];
// TODO (kallentu) : Clean up TypeParameterElementImpl casting once
// variance is added to the interface.

View file

@ -739,7 +739,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
var type = node.typeOrThrow;
// Only report non-aliased, non-user-defined `Null?` and `dynamic?`. Do
// not report synthetic `dynamic` in place of an unresolved type.
if ((type.element == _nullType.element ||
if ((type is InterfaceType && type.element2 == _nullType.element2 ||
(type.isDynamic && name == 'dynamic')) &&
type.alias == null) {
_errorReporter.reportErrorForToken(
@ -990,7 +990,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
void _checkForImmutable(NamedCompilationUnitMember node) {
/// Return `true` if the given class [element] is annotated with the
/// `@immutable` annotation.
bool isImmutable(ClassElement element) {
bool isImmutable(InterfaceElement element) {
for (ElementAnnotation annotation in element.metadata) {
if (annotation.isImmutable) {
return true;
@ -1002,29 +1002,29 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
/// Return `true` if the given class [element] or any superclass of it is
/// annotated with the `@immutable` annotation.
bool isOrInheritsImmutable(
ClassElement element, HashSet<ClassElement> visited) {
InterfaceElement element, Set<InterfaceElement> visited) {
if (visited.add(element)) {
if (isImmutable(element)) {
return true;
}
for (InterfaceType interface in element.mixins) {
if (isOrInheritsImmutable(interface.element, visited)) {
if (isOrInheritsImmutable(interface.element2, visited)) {
return true;
}
}
for (InterfaceType mixin in element.interfaces) {
if (isOrInheritsImmutable(mixin.element, visited)) {
if (isOrInheritsImmutable(mixin.element2, visited)) {
return true;
}
}
if (element.supertype != null) {
return isOrInheritsImmutable(element.supertype!.element, visited);
return isOrInheritsImmutable(element.supertype!.element2, visited);
}
}
return false;
}
Iterable<String> nonFinalInstanceFields(ClassElement element) {
Iterable<String> nonFinalInstanceFields(InterfaceElement element) {
return element.fields
.where((FieldElement field) =>
!field.isSynthetic && !field.isFinal && !field.isStatic)
@ -1032,16 +1032,16 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
}
Iterable<String> definedOrInheritedNonFinalInstanceFields(
ClassElement element, HashSet<ClassElement> visited) {
InterfaceElement element, Set<InterfaceElement> visited) {
Iterable<String> nonFinalFields = [];
if (visited.add(element)) {
nonFinalFields = nonFinalInstanceFields(element);
nonFinalFields = nonFinalFields.followedBy(element.mixins.expand(
(InterfaceType mixin) => nonFinalInstanceFields(mixin.element)));
(InterfaceType mixin) => nonFinalInstanceFields(mixin.element2)));
if (element.supertype != null) {
nonFinalFields = nonFinalFields.followedBy(
definedOrInheritedNonFinalInstanceFields(
element.supertype!.element, visited));
element.supertype!.element2, visited));
}
}
return nonFinalFields;
@ -1172,7 +1172,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
// TODO(srawlins): Perhaps replace this with a getter on Element, like
// `Element.hasOrInheritsSealed`?
for (InterfaceType supertype in element.allSupertypes) {
ClassElement superclass = supertype.element;
final superclass = supertype.element2;
if (superclass.hasSealed) {
if (!currentPackageContains(superclass)) {
if (element.superclassConstraints.contains(supertype)) {

View file

@ -149,7 +149,7 @@ class CovariantParametersVerifier {
var superMembers = <_SuperMember>[];
for (var interface in interfaces) {
var superMember = _correspondingMember(interface.element, _thisMember);
var superMember = _correspondingMember(interface.element2, _thisMember);
if (superMember != null) {
superMembers.add(
_SuperMember(interface, superMember),
@ -218,7 +218,7 @@ class CovariantParametersVerifier {
/// Return a member from [classElement] that corresponds to the [proto],
/// or `null` if no such member exist.
static ExecutableElement? _correspondingMember(
ClassElement classElement,
InterfaceElement classElement,
ExecutableElement proto,
) {
if (proto is MethodElement) {

View file

@ -178,7 +178,7 @@ class DeprecatedMemberUseVerifier {
} else if (node is MethodInvocation &&
displayName == FunctionElement.CALL_METHOD_NAME) {
var invokeType = node.staticInvokeType as InterfaceType;
var invokeClass = invokeType.element;
var invokeClass = invokeType.element2;
displayName = "${invokeClass.name}.${element.displayName}";
}
var library = element is LibraryElement ? element : element.library;

View file

@ -251,8 +251,8 @@ class ErrorHandlerVerifier {
/// Returns whether [element] represents the []
bool _isDartCoreAsyncType(DartType type, String typeName) =>
type is InterfaceType &&
type.element.name == typeName &&
type.element.library.isDartAsync;
type.element2.name == typeName &&
type.element2.library.isDartAsync;
}
/// Visits a function body, looking for return statements.

View file

@ -375,7 +375,7 @@ class _ClassVerifier {
/// corresponding instance members in each of [directSuperInterfaces].
void _checkDeclaredMembers(AstNode node, InterfaceType type,
{required int mixinIndex}) {
var libraryUri = type.element.library.source.uri;
var libraryUri = type.element2.library.source.uri;
for (var method in type.methods) {
_checkDeclaredMember(node, libraryUri, method, mixinIndex: mixinIndex);
}
@ -402,9 +402,10 @@ class _ClassVerifier {
return false;
}
var interfaceElement = type.element;
var interfaceElement = type.element2;
if (interfaceElement.isDartCoreEnum &&
if (interfaceElement is ClassElement &&
interfaceElement.isDartCoreEnum &&
library.featureSet.isEnabled(Feature.enhanced_enums)) {
if (classElement.isAbstract || classElement.isEnum) {
return false;
@ -479,8 +480,8 @@ class _ClassVerifier {
return false;
}
var interfaceElement = type.element;
if (interfaceElement.isEnum) {
var interfaceElement = type.element2;
if (interfaceElement is EnumElement) {
return false;
}
@ -595,9 +596,9 @@ class _ClassVerifier {
/// [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_IMPLEMENTS],
/// [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_ON],
/// [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_WITH].
bool _checkForRecursiveInterfaceInheritance(ClassElement element,
[List<ClassElement>? path]) {
path ??= <ClassElement>[];
bool _checkForRecursiveInterfaceInheritance(InterfaceElement element,
[List<InterfaceElement>? path]) {
path ??= <InterfaceElement>[];
// Detect error condition.
int size = path.length;
@ -637,26 +638,30 @@ class _ClassVerifier {
path.add(element);
// n-case
var supertype = element.supertype;
if (supertype != null &&
_checkForRecursiveInterfaceInheritance(supertype.element, path)) {
return true;
}
for (InterfaceType type in element.mixins) {
if (_checkForRecursiveInterfaceInheritance(type.element, path)) {
if (element is ClassElement) {
var supertype = element.supertype;
if (supertype != null &&
_checkForRecursiveInterfaceInheritance(supertype.element2, path)) {
return true;
}
}
for (InterfaceType type in element.superclassConstraints) {
if (_checkForRecursiveInterfaceInheritance(type.element, path)) {
for (InterfaceType type in element.mixins) {
if (_checkForRecursiveInterfaceInheritance(type.element2, path)) {
return true;
}
}
if (element is MixinElement) {
for (InterfaceType type in element.superclassConstraints) {
if (_checkForRecursiveInterfaceInheritance(type.element2, path)) {
return true;
}
}
}
for (InterfaceType type in element.interfaces) {
if (_checkForRecursiveInterfaceInheritance(type.element, path)) {
if (_checkForRecursiveInterfaceInheritance(type.element2, path)) {
return true;
}
}
@ -743,19 +748,23 @@ class _ClassVerifier {
/// Return the error code that should be used when the given class [element]
/// references itself directly.
ErrorCode _getRecursiveErrorCode(ClassElement element) {
if (element.supertype?.element == classElement) {
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_EXTENDS;
ErrorCode _getRecursiveErrorCode(InterfaceElement element) {
if (element is ClassElement) {
if (element.supertype?.element2 == classElement) {
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_EXTENDS;
}
}
for (InterfaceType type in element.superclassConstraints) {
if (type.element == classElement) {
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_ON;
if (element is MixinElement) {
for (InterfaceType type in element.superclassConstraints) {
if (type.element2 == classElement) {
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_ON;
}
}
}
for (InterfaceType type in element.mixins) {
if (type.element == classElement) {
if (type.element2 == classElement) {
return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_WITH;
}
}

View file

@ -72,16 +72,26 @@ class MustCallSuperVerifier {
if (element.enclosingElement3 is! ClassElement) {
return null;
}
var classElement = element.enclosingElement3 as ClassElement;
var classElement = element.enclosingElement3 as InterfaceElement;
String name = element.name;
// Walk up the type hierarchy from [classElement], ignoring direct
// interfaces.
Queue<ClassElement?> superclasses =
Queue.of(classElement.mixins.map((i) => i.element))
..addAll(classElement.superclassConstraints.map((i) => i.element))
..add(classElement.supertype?.element);
var visitedClasses = <ClassElement>{};
final superclasses = Queue<InterfaceElement?>();
void addToQueue(InterfaceElement element) {
superclasses.addAll(element.mixins.map((i) => i.element2));
if (element is ClassElement) {
superclasses.add(element.supertype?.element2);
}
if (element is MixinElement) {
superclasses
.addAll(element.superclassConstraints.map((i) => i.element2));
}
}
final visitedClasses = <InterfaceElement>{};
addToQueue(classElement);
while (superclasses.isNotEmpty) {
var ancestor = superclasses.removeFirst();
if (ancestor == null || !visitedClasses.add(ancestor)) {
@ -99,10 +109,7 @@ class MustCallSuperVerifier {
// documentation of [mustCallSuper].
return member;
}
superclasses
..addAll(ancestor.mixins.map((i) => i.element))
..addAll(ancestor.superclassConstraints.map((i) => i.element))
..add(ancestor.supertype?.element);
addToQueue(ancestor);
}
return null;
}
@ -144,7 +151,7 @@ extension on InterfaceType? {
bool isConcrete(String name) {
var self = this;
if (self == null) return false;
var element = self.element;
var element = self.element2;
return element.lookUpConcreteMethod(name, element.library) != null;
}
}

View file

@ -45,10 +45,11 @@ class NullSafeApiVerifier {
if (!_typeSystem.isNonNullableByDefault) return;
final targetType = node.realTarget?.staticType;
final targetClass = targetType?.element;
if (targetClass == null || targetType is! InterfaceType) return;
if (targetType is! InterfaceType) return;
if (targetClass.library?.isDartAsync == true &&
final targetClass = targetType.element2;
if (targetClass.library.isDartAsync == true &&
targetClass.name == 'Completer' &&
node.methodName.name == 'complete') {
_checkTypes(node, 'Completer.complete', targetType.typeArguments.single,

View file

@ -330,8 +330,8 @@ class TypeArgumentsVerifier {
typeParameters = alias.element.typeParameters;
typeArguments = alias.typeArguments;
} else if (type is InterfaceType) {
elementName = type.element.name;
typeParameters = type.element.typeParameters;
elementName = type.element2.name;
typeParameters = type.element2.typeParameters;
typeArguments = type.typeArguments;
} else {
return;

View file

@ -485,7 +485,7 @@ class ElementResolver {
/// Checks whether the given [expression] is a reference to a class. If it is
/// then the element representing the class is returned, otherwise `null` is
/// returned.
static ClassElement? getTypeReference(Expression expression) {
static InterfaceElement? getTypeReference(Expression expression) {
if (expression is Identifier) {
var element = expression.staticElement;
if (element is ClassElement) {
@ -493,7 +493,7 @@ class ElementResolver {
} else if (element is TypeAliasElement) {
var aliasedType = element.aliasedType;
if (aliasedType is InterfaceType) {
return aliasedType.element;
return aliasedType.element2;
}
}
}

View file

@ -237,7 +237,7 @@ mixin ErrorDetectionHelpers {
type is InterfaceType &&
type.nullabilitySuffix != NullabilitySuffix.question) {
return type.lookUpMethod2(
FunctionElement.CALL_METHOD_NAME, type.element.library);
FunctionElement.CALL_METHOD_NAME, type.element2.library);
} else {
return null;
}

View file

@ -283,7 +283,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// The language team is thinking about adding abstract fields, or external
/// fields. But for now we will ignore such fields in `Struct` subtypes.
bool get _isEnclosingClassFfiStruct {
var superClass = _enclosingClass?.supertype?.element;
var superClass = _enclosingClass?.supertype?.element2;
return superClass != null &&
superClass.library.name == 'dart.ffi' &&
superClass.name == 'Struct';
@ -292,7 +292,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// The language team is thinking about adding abstract fields, or external
/// fields. But for now we will ignore such fields in `Struct` subtypes.
bool get _isEnclosingClassFfiUnion {
var superClass = _enclosingClass?.supertype?.element;
var superClass = _enclosingClass?.supertype?.element2;
return superClass != null &&
superClass.library.name == 'dart.ffi' &&
superClass.name == 'Union';
@ -1460,12 +1460,12 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
mixinName, CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS)) {
problemReported = true;
} else {
ClassElement mixinElement = mixinType.element;
final mixinElement = mixinType.element2;
if (_checkForExtendsOrImplementsDeferredClass(
mixinName, CompileTimeErrorCode.MIXIN_DEFERRED_CLASS)) {
problemReported = true;
}
if (mixinElement.isMixin) {
if (mixinElement is MixinElement) {
if (_checkForMixinSuperclassConstraints(
mixinNameIndex, mixinName)) {
problemReported = true;
@ -1504,7 +1504,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
// REDIRECT_TO_MISSING_CONSTRUCTOR case
NamedType constructorNamedType = redirectedConstructor.type;
DartType redirectedType = constructorNamedType.typeOrThrow;
if (redirectedType.element != null && !redirectedType.isDynamic) {
if (redirectedType is! DynamicType) {
// Prepare the constructor name
String constructorStrName = constructorNamedType.name.name;
if (redirectedConstructor.name != null) {
@ -2040,7 +2040,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
redirectingInitializerCount == 0 &&
superInitializerCount == 1 &&
superInitializer != declaration.initializers.last) {
var superNamedType = enclosingClass.supertype!.element.displayName;
var superNamedType = enclosingClass.supertype!.element2.displayName;
var constructorStrName = superNamedType;
var constructorName = superInitializer.constructorName;
if (constructorName != null) {
@ -2077,7 +2077,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
// check for mixins
var instanceFields = <FieldElement>[];
for (var mixin in enclosingClass.mixins) {
instanceFields.addAll(mixin.element.fields.where((field) {
instanceFields.addAll(mixin.element2.fields.where((field) {
if (field.isStatic) {
return false;
}
@ -2139,7 +2139,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (supertype.isDartCoreObject) {
return false;
}
var unnamedConstructor = supertype.element.unnamedConstructor;
var unnamedConstructor = supertype.element2.unnamedConstructor;
if (unnamedConstructor == null || unnamedConstructor.isConst) {
return false;
}
@ -2208,7 +2208,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
InstanceCreationExpression expression,
NamedType namedType,
InterfaceType type) {
if (type.element.isAbstract && !type.element.isMixin) {
final element = type.element2;
if (element is! MixinElement &&
element is ClassElement &&
element.isAbstract) {
var element = expression.constructorName.staticElement;
if (element != null && !element.isFactory) {
bool isImplicit =
@ -2227,7 +2230,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// Verify that the given [expression] is not a mixin instantiation.
void _checkForConstOrNewWithMixin(InstanceCreationExpression expression,
NamedType namedType, InterfaceType type) {
if (type.element.isMixin) {
if (type.element2 is MixinElement) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.MIXIN_INSTANTIATE, namedType);
}
@ -2273,8 +2276,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
DartType type = namedType.typeOrThrow;
if (type is InterfaceType) {
ClassElement element = type.element;
if (element.isEnum) {
if (type.element2 is EnumElement) {
// We have already reported the error.
return;
}
@ -2633,7 +2635,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
var type = namedType.type;
return type is InterfaceType &&
_typeProvider.isNonSubtypableClass(type.element);
_typeProvider.isNonSubtypableClass(type.element2);
}
void _checkForExtensionDeclaresMemberOfObject(MethodDeclaration node) {
@ -2921,8 +2923,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// the [name] is reference to an instance member.
///
/// See [CompileTimeErrorCode.INSTANCE_ACCESS_TO_STATIC_MEMBER].
void _checkForInstanceAccessToStaticMember(
ClassElement? typeReference, Expression? target, SimpleIdentifier name) {
void _checkForInstanceAccessToStaticMember(InterfaceElement? typeReference,
Expression? target, SimpleIdentifier name) {
if (_isInComment) {
// OK, in comment
return;
@ -3301,8 +3303,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
var hasCaseNull = false;
if (expressionType is InterfaceType) {
var enumElement = expressionType.element;
if (enumElement.isEnum) {
var enumElement = expressionType.element2;
if (enumElement is EnumElement) {
var constantNames = enumElement.fields
.where((field) => field.isEnumConstant)
.map((field) => field.name)
@ -3354,7 +3356,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
///
/// See [CompileTimeErrorCode.MIXIN_CLASS_DECLARES_CONSTRUCTOR].
bool _checkForMixinClassDeclaresConstructor(
NamedType mixinName, ClassElement mixinElement) {
NamedType mixinName, InterfaceElement mixinElement) {
for (ConstructorElement constructor in mixinElement.constructors) {
if (!constructor.isSynthetic && !constructor.isFactory) {
errorReporter.reportErrorForNode(
@ -3374,8 +3376,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
///
/// See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT].
bool _checkForMixinInheritsNotFromObject(
NamedType mixinName, ClassElement mixinElement) {
if (mixinElement.isEnum) {
NamedType mixinName, InterfaceElement mixinElement) {
if (mixinElement is EnumElement) {
return false;
}
if (mixinElement is! ClassElement) {
return false;
}
@ -3437,7 +3442,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
/// [mixinIndex] in the list of mixins of [_enclosingClass] has concrete
/// implementations of all the super-invoked members of the [mixinElement].
bool _checkForMixinSuperInvokedMembers(int mixinIndex, NamedType mixinName,
ClassElement mixinElement, InterfaceType mixinType) {
InterfaceElement mixinElement, InterfaceType mixinType) {
var mixinElementImpl = mixinElement as ClassElementImpl;
if (mixinElementImpl.superInvokedNames.isEmpty) {
return false;
@ -3517,7 +3522,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
names[name] = namedType.name.name;
var inheritedMember = _inheritanceManager.getMember2(
declaredSupertype.element,
declaredSupertype.element2,
Name(library.source.uri, name),
concrete: true,
);
@ -3541,7 +3546,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
for (NamedType mixinType in withClause.mixinTypes) {
DartType type = mixinType.typeOrThrow;
if (type is InterfaceType) {
LibraryElement library = type.element.library;
LibraryElement library = type.element2.library;
if (library != _currentLibrary) {
for (PropertyAccessorElement accessor in type.accessors) {
if (accessor.isStatic) {
@ -3592,8 +3597,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
DartType type = namedType.typeOrThrow;
if (type is InterfaceType) {
ClassElement element = type.element;
if (element.isEnum || element.isMixin) {
final element = type.element2;
if (element is EnumElement || element is MixinElement) {
// We have already reported the error.
return;
}
@ -3632,7 +3637,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (superType == null) {
return;
}
ClassElement superElement = superType.element;
final superElement = superType.element2;
// try to find default generative super constructor
var superUnnamedConstructor = superElement.unnamedConstructor;
superUnnamedConstructor = superUnnamedConstructor != null
@ -3654,7 +3659,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
}
if (!_typeProvider.isNonSubtypableClass(superType.element)) {
if (!_typeProvider.isNonSubtypableClass(superType.element2)) {
// Don't report this diagnostic for non-subtypable classes because the
// real problem was already reported.
errorReporter.reportErrorForToken(
@ -3675,7 +3680,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
// subclass has only factory constructors.
return false;
}
ClassElement superElement = superType.element;
final superElement = superType.element2;
if (superElement.constructors.isEmpty) {
// Exclude empty constructor set, which indicates other errors occurred.
return false;
@ -4120,11 +4125,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (!detectedRepeatOnIndex[i]) {
var type = namedTypes[i].type;
if (type is InterfaceType) {
var element = type.element;
var element = type.element2;
for (int j = i + 1; j < count; j++) {
var otherNode = namedTypes[j];
var otherType = otherNode.type;
if (otherType is InterfaceType && otherType.element == element) {
if (otherType is InterfaceType && otherType.element2 == element) {
detectedRepeatOnIndex[j] = true;
errorReporter
.reportErrorForNode(errorCode, otherNode, [element.name]);
@ -4205,7 +4210,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
///
/// See [CompileTimeErrorCode.STATIC_ACCESS_TO_INSTANCE_MEMBER].
void _checkForStaticAccessToInstanceMember(
ClassElement? typeReference, SimpleIdentifier name) {
InterfaceElement? typeReference, SimpleIdentifier name) {
// OK, in comment
if (_isInComment) {
return;
@ -4400,7 +4405,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (superType == null) {
return;
}
ClassElement superElement = superType.element;
final superElement = superType.element2;
if (superElement.constructors
.every((constructor) => constructor.isFactory)) {
@ -4925,14 +4930,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return;
}
var superElement = _enclosingClass!.supertype?.element;
var superElement = _enclosingClass!.supertype?.element2;
if (superElement == null) {
return;
}
for (var interfaceNode in implementsClause.interfaces) {
var type = interfaceNode.type;
if (type is InterfaceType && type.element == superElement) {
if (type is InterfaceType && type.element2 == superElement) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS,
interfaceNode,
@ -4972,14 +4977,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return;
}
var superElement = _enclosingClass!.supertype?.element;
var superElement = _enclosingClass!.supertype?.element2;
if (superElement == null) {
return;
}
for (var mixinNode in withClause.mixinTypes) {
var type = mixinNode.type;
if (type is InterfaceType && type.element == superElement) {
if (type is InterfaceType && type.element2 == superElement) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.MIXINS_SUPER_CLASS,
mixinNode,

View file

@ -156,7 +156,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
if (implementsClause != null) {
final compoundType = node.declaredElement!.thisType;
final structType = compoundType.superclass!;
final ffiLibrary = structType.element.library;
final ffiLibrary = structType.element2.library;
final finalizableElement = ffiLibrary.getType(_finalizableClassName)!;
final finalizableType = finalizableElement.thisType;
if (typeSystem.isSubtypeOf(compoundType, finalizableType)) {
@ -427,7 +427,12 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
'NativeFieldWrapperClass1') {
return true;
}
type = type.element.supertype;
final element = type.element2;
if (element is ClassElement) {
type = element.supertype;
} else {
break;
}
}
return false;
}
@ -538,7 +543,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
}
if (nativeType.isCompoundSubtype) {
if (!allowEmptyStruct) {
if (nativeType.element.isEmptyStruct) {
if (nativeType.element2.isEmptyStruct) {
// TODO(dartbug.com/36780): This results in an error message not
// mentioning empty structs at all.
return false;
@ -585,7 +590,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
_PrimitiveDartType _primitiveNativeType(DartType nativeType) {
if (nativeType is InterfaceType) {
final element = nativeType.element;
final element = nativeType.element2;
if (element.isFfiClass) {
final String name = element.name;
if (_primitiveIntegerNativeTypes.contains(name)) {
@ -669,13 +674,16 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
if (argument is SetOrMapLiteral) {
for (final element in argument.elements) {
if (element is MapLiteralEntry) {
final name = element.value.staticType?.element?.name;
if (name != null &&
!_primitiveIntegerNativeTypesFixedSize.contains(name)) {
_errorReporter.reportErrorForNode(
final valueType = element.value.staticType;
if (valueType is InterfaceType) {
final name = valueType.element2.name;
if (!_primitiveIntegerNativeTypesFixedSize.contains(name)) {
_errorReporter.reportErrorForNode(
FfiCode.ABI_SPECIFIC_INTEGER_MAPPING_UNSUPPORTED,
element.value,
[name]);
[name],
);
}
}
}
}
@ -689,13 +697,16 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
return;
}
for (final nativeType in mappingValues.values) {
final nativeTypeName = nativeType?.type?.element?.name;
if (nativeTypeName != null &&
!_primitiveIntegerNativeTypesFixedSize.contains(nativeTypeName)) {
_errorReporter.reportErrorForNode(
final type = nativeType?.type;
if (type is InterfaceType) {
final nativeTypeName = type.element2.name;
if (!_primitiveIntegerNativeTypesFixedSize.contains(nativeTypeName)) {
_errorReporter.reportErrorForNode(
FfiCode.ABI_SPECIFIC_INTEGER_MAPPING_UNSUPPORTED,
arguments.first,
[nativeTypeName]);
[nativeTypeName],
);
}
}
}
}
@ -875,7 +886,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
final nativeReturnType = _primitiveNativeType(nativeType);
if (nativeReturnType == _PrimitiveDartType.int ||
(nativeType is InterfaceType &&
nativeType.superclass?.element.name ==
nativeType.superclass?.element2.name ==
_abiSpecificIntegerClassName)) {
return dartType.isDartCoreInt;
} else if (nativeReturnType == _PrimitiveDartType.double) {
@ -1001,8 +1012,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
final arrayDimensions = declaredType.arrayDimensions;
_validateSizeOfAnnotation(fieldType, annotations, arrayDimensions);
} else if (declaredType.isCompoundSubtype) {
final clazz = (declaredType as InterfaceType).element;
if (clazz.isEmptyStruct) {
final clazz = (declaredType as InterfaceType).element2;
if (clazz is ClassElement && clazz.isEmptyStruct) {
_errorReporter.reportErrorForNode(FfiCode.EMPTY_STRUCT, node, [
clazz.name,
clazz.supertype!.getDisplayString(withNullability: false)
@ -1487,7 +1498,7 @@ extension on Element? {
}
}
extension on ClassElement {
extension on InterfaceElement {
bool get isEmptyStruct {
for (final field in fields) {
final declaredType = field.type;
@ -1522,17 +1533,17 @@ extension on ExtensionElement {
extension on DartType? {
bool get isAbiSpecificInteger {
final self = this;
return self is InterfaceType && self.element.isAbiSpecificInteger;
return self is InterfaceType && self.element2.isAbiSpecificInteger;
}
bool get isStruct {
final self = this;
return self is InterfaceType && self.element.isStruct;
return self is InterfaceType && self.element2.isStruct;
}
bool get isUnion {
final self = this;
return self is InterfaceType && self.element.isUnion;
return self is InterfaceType && self.element2.isUnion;
}
}
@ -1541,8 +1552,8 @@ extension on DartType {
DartType iterator = this;
int dimensions = 0;
while (iterator is InterfaceType &&
iterator.element.name == FfiVerifier._arrayClassName &&
iterator.element.isFfiClass) {
iterator.element2.name == FfiVerifier._arrayClassName &&
iterator.element2.isFfiClass) {
dimensions++;
iterator = iterator.typeArguments.single;
}
@ -1552,7 +1563,7 @@ extension on DartType {
bool get isAbiSpecificInteger {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
final name = element.name;
return name == FfiVerifier._abiSpecificIntegerClassName &&
element.isFfiClass;
@ -1565,9 +1576,9 @@ extension on DartType {
bool get isAbiSpecificIntegerSubtype {
final self = this;
if (self is InterfaceType) {
final superType = self.element.supertype;
final superType = self.element2.supertype;
if (superType != null) {
final superClassElement = superType.element;
final superClassElement = superType.element2;
return superClassElement.name ==
FfiVerifier._abiSpecificIntegerClassName &&
superClassElement.isFfiClass;
@ -1580,7 +1591,7 @@ extension on DartType {
bool get isArray {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
return element.name == FfiVerifier._arrayClassName && element.isFfiClass;
}
return false;
@ -1589,7 +1600,7 @@ extension on DartType {
bool get isCompound {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
final name = element.name;
return (name == FfiVerifier._structClassName ||
name == FfiVerifier._unionClassName) &&
@ -1602,7 +1613,7 @@ extension on DartType {
bool get isCompoundSubtype {
final self = this;
if (self is InterfaceType) {
final superType = self.element.supertype;
final superType = self.element2.supertype;
if (superType != null) {
return superType.isCompound;
}
@ -1613,7 +1624,7 @@ extension on DartType {
bool get isHandle {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
return element.name == 'Handle' && element.isFfiClass;
}
return false;
@ -1623,7 +1634,7 @@ extension on DartType {
bool get isNativeFunction {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
return element.name == 'NativeFunction' && element.isFfiClass;
}
return false;
@ -1633,7 +1644,7 @@ extension on DartType {
bool get isNativeType {
final self = this;
if (self is InterfaceType) {
final element = self.element;
final element = self.element2;
return element.name == 'NativeType' && element.isFfiClass;
}
return false;
@ -1643,9 +1654,9 @@ extension on DartType {
bool get isOpaqueSubtype {
final self = this;
if (self is InterfaceType) {
final superType = self.element.supertype;
final superType = self.element2.supertype;
if (superType != null) {
final superClassElement = superType.element;
final superClassElement = superType.element2;
return superClassElement.name == FfiVerifier._opaqueClassName &&
superClassElement.isFfiClass;
}
@ -1655,7 +1666,7 @@ extension on DartType {
bool get isPointer {
final self = this;
return self is InterfaceType && self.element.isPointer;
return self is InterfaceType && self.element2.isPointer;
}
}

Some files were not shown because too many files have changed in this diff Show more