22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // ignore_for_file: analyzer_use_new_elements
6-
75import 'dart:collection' ;
86
97import 'package:_fe_analyzer_shared/src/flow_analysis/flow_analysis.dart' ;
@@ -16,7 +14,6 @@ import 'package:analyzer/dart/analysis/features.dart';
1614import 'package:analyzer/dart/ast/syntactic_entity.dart' ;
1715import 'package:analyzer/dart/ast/token.dart' ;
1816import 'package:analyzer/dart/ast/visitor.dart' ;
19- import 'package:analyzer/dart/element/element.dart' ;
2017import 'package:analyzer/dart/element/element2.dart' ;
2118import 'package:analyzer/dart/element/type.dart' ;
2219import 'package:analyzer/diagnostic/diagnostic.dart' ;
@@ -1825,21 +1822,21 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
18251822
18261823 // prepare element
18271824 var highlightedNode = expression;
1828- var element = expression.element? .asElement ;
1825+ var element = expression.element;
18291826 if (expression is PrefixedIdentifier ) {
18301827 var prefixedIdentifier = expression as PrefixedIdentifier ;
18311828 highlightedNode = prefixedIdentifier.identifier;
18321829 }
18331830 // check if element is assignable
1834- if (element is VariableElement ) {
1831+ if (element is VariableElement2 ) {
18351832 if (element.isConst) {
18361833 errorReporter.atNode (
18371834 expression,
18381835 CompileTimeErrorCode .ASSIGNMENT_TO_CONST ,
18391836 );
18401837 }
1841- } else if (element is PropertyAccessorElement && element.isGetter ) {
1842- var variable = element.variable2 ;
1838+ } else if (element is GetterElement ) {
1839+ var variable = element.variable3 ;
18431840 if (variable == null ) {
18441841 return ;
18451842 }
@@ -1848,32 +1845,33 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
18481845 expression,
18491846 CompileTimeErrorCode .ASSIGNMENT_TO_CONST ,
18501847 );
1851- } else if (variable is FieldElement && variable.isSynthetic) {
1848+ } else if (variable is FieldElement2 && variable.isSynthetic) {
18521849 errorReporter.atNode (
18531850 highlightedNode,
18541851 CompileTimeErrorCode .ASSIGNMENT_TO_FINAL_NO_SETTER ,
1855- arguments: [variable.name , variable.enclosingElement3 .displayName],
1852+ arguments: [variable.name3 ! , variable.enclosingElement2 .displayName],
18561853 );
18571854 } else {
18581855 errorReporter.atNode (
18591856 highlightedNode,
18601857 CompileTimeErrorCode .ASSIGNMENT_TO_FINAL ,
1861- arguments: [variable.name ],
1858+ arguments: [variable.name3 ! ],
18621859 );
18631860 }
1864- } else if (element is FunctionElement ) {
1861+ } else if (element is LocalFunctionElement ||
1862+ element is TopLevelFunctionElement ) {
18651863 errorReporter.atNode (
18661864 expression,
18671865 CompileTimeErrorCode .ASSIGNMENT_TO_FUNCTION ,
18681866 );
1869- } else if (element is MethodElement ) {
1867+ } else if (element is MethodElement2 ) {
18701868 errorReporter.atNode (
18711869 expression,
18721870 CompileTimeErrorCode .ASSIGNMENT_TO_METHOD ,
18731871 );
1874- } else if (element is InterfaceElement ||
1875- element is DynamicElementImpl ||
1876- element is TypeParameterElement ) {
1872+ } else if (element is InterfaceElement2 ||
1873+ element is DynamicElementImpl2 ||
1874+ element is TypeParameterElement2 ) {
18771875 errorReporter.atNode (
18781876 expression,
18791877 CompileTimeErrorCode .ASSIGNMENT_TO_TYPE ,
@@ -2042,8 +2040,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
20422040 /// See [CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE] ,
20432041 /// [CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD] , and
20442042 /// [CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD] .
2045- void _checkForConflictingClassMembers (InterfaceElement fragment) {
2046- var enclosingClass = _enclosingClass.asElement as InterfaceElementImpl ? ;
2043+ void _checkForConflictingClassMembers (InterfaceElementImpl fragment) {
2044+ var enclosingClass = _enclosingClass;
20472045 if (enclosingClass == null ) {
20482046 return ;
20492047 }
@@ -2052,7 +2050,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
20522050 var conflictingDeclaredNames = < String > {};
20532051
20542052 // method declared in the enclosing class vs. inherited getter/setter
2055- for (MethodElement method in fragment.methods) {
2053+ for (var method in fragment.methods) {
20562054 if (method.source != _currentUnit.source) {
20572055 continue ;
20582056 }
@@ -2061,21 +2059,21 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
20612059
20622060 // find inherited property accessors
20632061 var getter = _inheritanceManager
2064- .getInherited4 (enclosingClass.asElement2 , Name (libraryUri, name))
2062+ .getInherited4 (enclosingClass, Name (libraryUri, name))
20652063 ? .asElement;
20662064 var setter = _inheritanceManager
2067- .getInherited4 (enclosingClass.asElement2 , Name (libraryUri, '$name =' ))
2065+ .getInherited4 (enclosingClass, Name (libraryUri, '$name =' ))
20682066 ? .asElement;
20692067
20702068 if (method.isStatic) {
2071- void reportStaticConflict (ExecutableElement inherited) {
2069+ void reportStaticConflict (ExecutableElementOrMember inherited) {
20722070 errorReporter.atElement2 (
20732071 method.asElement2,
20742072 CompileTimeErrorCode .CONFLICTING_STATIC_AND_INSTANCE ,
20752073 arguments: [
20762074 enclosingClass.displayName,
20772075 name,
2078- inherited.enclosingElement3 .displayName,
2076+ inherited.asElement2.enclosingElement2 ! .displayName,
20792077 ],
20802078 );
20812079 }
@@ -2092,18 +2090,18 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
20922090 }
20932091
20942092 // Extension type methods preclude accessors.
2095- if (enclosingClass is ExtensionTypeElement ) {
2093+ if (enclosingClass is ExtensionTypeElementImpl2 ) {
20962094 continue ;
20972095 }
20982096
2099- void reportFieldConflict (PropertyAccessorElement inherited) {
2097+ void reportFieldConflict (PropertyAccessorElementOrMember inherited) {
21002098 errorReporter.atElement2 (
21012099 method.asElement2,
21022100 CompileTimeErrorCode .CONFLICTING_METHOD_AND_FIELD ,
21032101 arguments: [
21042102 enclosingClass.displayName,
21052103 name,
2106- inherited.enclosingElement3 .displayName
2104+ inherited.asElement2.enclosingElement2 .displayName
21072105 ],
21082106 );
21092107 }
@@ -2120,15 +2118,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21202118 }
21212119
21222120 // getter declared in the enclosing class vs. inherited method
2123- for (PropertyAccessorElement accessor in fragment.accessors) {
2121+ for (var accessor in fragment.accessors) {
21242122 String name = accessor.displayName;
21252123
21262124 // find inherited method or property accessor
21272125 var inherited = _inheritanceManager
2128- .getInherited4 (enclosingClass.asElement2 , Name (libraryUri, name))
2126+ .getInherited4 (enclosingClass, Name (libraryUri, name))
21292127 ? .asElement;
21302128 inherited ?? = _inheritanceManager
2131- .getInherited4 (enclosingClass.asElement2 , Name (libraryUri, '$name =' ))
2129+ .getInherited4 (enclosingClass, Name (libraryUri, '$name =' ))
21322130 ? .asElement;
21332131
21342132 if (accessor.isStatic && inherited != null ) {
@@ -2138,13 +2136,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21382136 arguments: [
21392137 enclosingClass.displayName,
21402138 name,
2141- inherited.enclosingElement3 .displayName,
2139+ inherited.asElement2.enclosingElement2 ! .displayName,
21422140 ],
21432141 );
21442142 conflictingDeclaredNames.add (name);
21452143 } else if (inherited is MethodElementOrMember ) {
21462144 // Extension type accessors preclude inherited accessors/methods.
2147- if (enclosingClass is ExtensionTypeElement ) {
2145+ if (enclosingClass is ExtensionTypeElementImpl2 ) {
21482146 continue ;
21492147 }
21502148 errorReporter.atElement2 (
@@ -2153,18 +2151,19 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21532151 arguments: [
21542152 enclosingClass.displayName,
21552153 name,
2156- inherited.enclosingElement3 .displayName
2154+ inherited.asElement2.enclosingElement2 ! .displayName
21572155 ],
21582156 );
21592157 conflictingDeclaredNames.add (name);
21602158 }
21612159 }
21622160
21632161 // Inherited method and setter with the same name.
2164- var inherited = _inheritanceManager.getInheritedMap2 (enclosingClass);
2162+ var inherited =
2163+ _inheritanceManager.getInheritedMap2 (enclosingClass.asElement);
21652164 for (var entry in inherited.entries) {
21662165 var method = entry.value;
2167- if (method is MethodElement ) {
2166+ if (method is MethodElementOrMember ) {
21682167 var methodName = entry.key;
21692168 if (conflictingDeclaredNames.contains (methodName.name)) {
21702169 continue ;
@@ -2173,7 +2172,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21732172 var setter = inherited[setterName];
21742173 if (setter is PropertyAccessorElementOrMember ) {
21752174 errorReporter.atElement2 (
2176- enclosingClass.asElement2 ,
2175+ enclosingClass,
21772176 CompileTimeErrorCode .CONFLICTING_INHERITED_METHOD_AND_SETTER ,
21782177 arguments: [
21792178 enclosingClass.kind.displayName,
@@ -2186,8 +2185,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21862185 message: formatList (
21872186 "The method is inherited from the {0} '{1}'." ,
21882187 [
2189- method.enclosingElement3 .kind.displayName,
2190- method.enclosingElement3.name ,
2188+ method.asElement2.enclosingElement2 ! .kind.displayName,
2189+ method.asElement2.enclosingElement2 ! .name3 ,
21912190 ],
21922191 ),
21932192 offset: method.nameOffset,
@@ -2199,8 +2198,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21992198 message: formatList (
22002199 "The setter is inherited from the {0} '{1}'." ,
22012200 [
2202- setter.enclosingElement3 .kind.displayName,
2203- setter.enclosingElement3.name ,
2201+ setter.asElement2.enclosingElement2 .kind.displayName,
2202+ setter.asElement2.enclosingElement2.name3 ,
22042203 ],
22052204 ),
22062205 offset: setter.nameOffset,
@@ -2764,15 +2763,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
27642763 NodeList <Directive > directives = unit.directives;
27652764 int count = directives.length;
27662765 if (count > 0 ) {
2767- Map <PrefixElement , List <ImportDirective >> prefixToDirectivesMap =
2768- HashMap <PrefixElement , List <ImportDirective >>();
2766+ var prefixToDirectivesMap = < PrefixElement2 , List <ImportDirective >> {};
27692767 for (int i = 0 ; i < count; i++ ) {
27702768 Directive directive = directives[i];
27712769 if (directive is ImportDirective ) {
27722770 var prefix = directive.prefix;
27732771 if (prefix != null ) {
2774- var element = prefix.element? .asElement ;
2775- if (element is PrefixElement ) {
2772+ var element = prefix.element;
2773+ if (element is PrefixElement2 ) {
27762774 var elements = prefixToDirectivesMap[element];
27772775 if (elements == null ) {
27782776 elements = < ImportDirective > [];
@@ -3151,15 +3149,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
31513149 required ExtensionTypeDeclaration node,
31523150 required ExtensionTypeElementImpl element,
31533151 }) {
3154- void report (String memberName, List <ExecutableElement > candidates) {
3152+ void report (String memberName, List <ExecutableElement2 > candidates) {
31553153 var contextMessages = candidates.map <DiagnosticMessage >((executable) {
3156- var nonSynthetic = executable.nonSynthetic ;
3157- var container = executable.enclosingElement3 as InterfaceElement ;
3154+ var nonSynthetic = executable.nonSynthetic2 ;
3155+ var container = executable.enclosingElement2 as InterfaceElement2 ;
31583156 return DiagnosticMessageImpl (
3159- filePath: executable.source.fullName,
3160- offset: nonSynthetic.nameOffset ,
3161- length: nonSynthetic.nameLength ,
3162- message: "Inherited from '${container .name }'" ,
3157+ filePath: executable.firstFragment.libraryFragment. source.fullName,
3158+ offset: nonSynthetic.firstFragment.nameOffset2 ! ,
3159+ length: nonSynthetic.firstFragment.name2 ! .length ,
3160+ message: "Inherited from '${container .name3 }'" ,
31633161 url: null ,
31643162 );
31653163 }).toList ();
@@ -3175,14 +3173,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
31753173 for (var conflict in interface .conflicts) {
31763174 switch (conflict) {
31773175 case CandidatesConflict _:
3178- report (conflict.name.name, conflict.candidates );
3176+ report (conflict.name.name, conflict.candidates2 );
31793177 case HasNonExtensionAndExtensionMemberConflict _:
31803178 report (conflict.name.name, [
3181- ...conflict.nonExtension ,
3182- ...conflict.extension ,
3179+ ...conflict.nonExtension2 ,
3180+ ...conflict.extension2 ,
31833181 ]);
31843182 case NotUniqueExtensionMemberConflict _:
3185- report (conflict.name.name, conflict.candidates );
3183+ report (conflict.name.name, conflict.candidates2 );
31863184 }
31873185 }
31883186 }
@@ -3492,7 +3490,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
34923490
34933491 /// Check that if the visiting library is not system, then any given library
34943492 /// should not be SDK internal library. The [importElement] is the
3495- /// [LibraryImportElement ] retrieved from the node, if the element in the node
3493+ /// [LibraryImport ] retrieved from the node, if the element in the node
34963494 /// was `null` , then this method is not called.
34973495 void _checkForImportInternalLibrary (
34983496 ImportDirective directive, LibraryImport importElement) {
@@ -3822,17 +3820,17 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
38223820 }
38233821 }
38243822
3825- void _checkForMainFunction1 (Token nameToken, Element declaredElement ) {
3823+ void _checkForMainFunction1 (Token nameToken, Fragment declaredFragment ) {
38263824 // We should only check exported declarations, i.e. top-level.
3827- if (declaredElement.enclosingElement3 is ! CompilationUnitElement ) {
3825+ if (declaredFragment.enclosingFragment is ! LibraryFragment ) {
38283826 return ;
38293827 }
38303828
3831- if (declaredElement.displayName != 'main' ) {
3829+ if (declaredFragment.name2 != 'main' ) {
38323830 return ;
38333831 }
38343832
3835- if (declaredElement is ! FunctionElement ) {
3833+ if (declaredFragment is ! TopLevelFunctionFragment ) {
38363834 errorReporter.atToken (
38373835 nameToken,
38383836 CompileTimeErrorCode .MAIN_IS_NOT_FUNCTION ,
@@ -4459,14 +4457,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
44594457
44604458 void _checkForNonCovariantTypeParameterPositionInRepresentationType (
44614459 ExtensionTypeDeclaration node,
4462- ExtensionTypeElement element ,
4460+ ExtensionTypeElementImpl fragment ,
44634461 ) {
44644462 var typeParameters = node.typeParameters? .typeParameters;
44654463 if (typeParameters == null ) {
44664464 return ;
44674465 }
44684466
4469- var representationType = element .representation.type;
4467+ var representationType = fragment .representation.type;
44704468
44714469 for (var typeParameterNode in typeParameters) {
44724470 var typeParameterElement = typeParameterNode.declaredFragment! .element;
@@ -5687,8 +5685,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
56875685 _enclosingClass! .interfaces.forEach (checkOne);
56885686 _enclosingClass! .mixins.forEach (checkOne);
56895687
5690- var enclosingClass = _enclosingClass.asElement ;
5691- if (enclosingClass is MixinElement ) {
5688+ var enclosingClass = _enclosingClass;
5689+ if (enclosingClass is MixinElementImpl2 ) {
56925690 enclosingClass.superclassConstraints.forEach (checkOne);
56935691 }
56945692 }
@@ -5707,16 +5705,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
57075705 /// Errors should only be reported in classes and mixins since those are the
57085706 /// only components that allow explicit variance modifiers.
57095707 void _checkForWrongVariancePosition (Variance variance,
5710- TypeParameterElement typeParameter, SyntacticEntity errorTarget) {
5711- TypeParameterElementImpl typeParameterImpl =
5712- typeParameter as TypeParameterElementImpl ;
5713- if (! variance.greaterThanOrEqual (typeParameterImpl.variance)) {
5708+ TypeParameterElementImpl typeParameter, SyntacticEntity errorTarget) {
5709+ if (! variance.greaterThanOrEqual (typeParameter.variance)) {
57145710 errorReporter.atEntity (
57155711 errorTarget,
57165712 CompileTimeErrorCode .WRONG_TYPE_PARAMETER_VARIANCE_POSITION ,
57175713 arguments: [
5718- typeParameterImpl .variance.keyword,
5719- typeParameterImpl .name,
5714+ typeParameter .variance.keyword,
5715+ typeParameter .name,
57205716 variance.keyword
57215717 ],
57225718 );
0 commit comments