55import 'package:analyzer/dart/analysis/features.dart' ;
66import 'package:analyzer/dart/ast/ast.dart' ;
77import 'package:analyzer/dart/ast/visitor.dart' ;
8- import 'package:analyzer/dart/element/element .dart' ;
8+ import 'package:analyzer/dart/element/element2 .dart' ;
99
1010import '../analyzer.dart' ;
1111import '../ast.dart' ;
@@ -36,17 +36,17 @@ class UseEnums extends LintRule {
3636/// A superclass for the [_EnumVisitor] and [_NonEnumVisitor] .
3737class _BaseVisitor extends RecursiveAstVisitor <void > {
3838 /// The element representing the enum declaration that's being visited.
39- final ClassElement classElement;
39+ final ClassElement2 classElement;
4040
4141 _BaseVisitor (this .classElement);
4242
4343 /// Return `true` if the given [node] is an invocation of a generative
4444 /// constructor from the class being converted.
4545 bool invokesGenerativeConstructor (InstanceCreationExpression node) {
46- var constructorElement = node.constructorName.staticElement ;
46+ var constructorElement = node.constructorName.element ;
4747 return constructorElement != null &&
4848 ! constructorElement.isFactory &&
49- constructorElement.enclosingElement3 == classElement;
49+ constructorElement.enclosingElement2 == classElement;
5050 }
5151}
5252
@@ -101,18 +101,18 @@ class _NonEnumVisitor extends _BaseVisitor {
101101
102102 @override
103103 void visitClassDeclaration (ClassDeclaration node) {
104- var element = node.declaredElement ;
104+ var element = node.declaredFragment ? .element ;
105105 if (element == null ) {
106106 throw _InvalidEnumException ();
107107 }
108108 if (element != classElement) {
109- if (element.supertype? .element == classElement) {
109+ if (element.supertype? .element3 == classElement) {
110110 throw _InvalidEnumException ();
111111 } else if (element.interfaces
112- .map ((e) => e.element )
112+ .map ((e) => e.element3 )
113113 .contains (classElement)) {
114114 throw _InvalidEnumException ();
115- } else if (element.mixins.map ((e) => e.element ).contains (classElement)) {
115+ } else if (element.mixins.map ((e) => e.element3 ).contains (classElement)) {
116116 // This case won't occur unless there's an error in the source code, but
117117 // it's easier to check for the condition than it is to check for the
118118 // diagnostic.
@@ -143,7 +143,7 @@ class _Visitor extends SimpleAstVisitor<void> {
143143 if (node.isAugmentation) return ;
144144
145145 if (node.abstractKeyword != null ) return ;
146- var classElement = node.declaredElement ;
146+ var classElement = node.declaredFragment ? .element ;
147147 if (classElement == null ) return ;
148148
149149 // Enums can only extend Object.
@@ -162,23 +162,23 @@ class _Visitor extends SimpleAstVisitor<void> {
162162 if (member is FieldDeclaration ) {
163163 if (! member.isStatic) continue ;
164164 for (var field in member.fields.variables) {
165- var fieldElement = field.declaredElement ;
166- if (fieldElement is ! FieldElement ) continue ;
165+ var fieldElement = field.declaredFragment ? .element ;
166+ if (fieldElement is ! FieldElement2 ) continue ;
167167 if (field.isSynthetic || ! field.isConst) continue ;
168168 var initializer = field.initializer;
169169 if (initializer is ! InstanceCreationExpression ) continue ;
170170
171- var constructorElement = initializer.constructorName.staticElement ;
171+ var constructorElement = initializer.constructorName.element ;
172172 if (constructorElement == null ) continue ;
173173 if (constructorElement.isFactory) continue ;
174- if (constructorElement.enclosingElement3 != classElement) continue ;
174+ if (constructorElement.enclosingElement2 != classElement) continue ;
175175 if (fieldElement.computeConstantValue () == null ) continue ;
176176
177177 candidateConstants.add (field);
178178 }
179179 }
180180 if (member is ConstructorDeclaration ) {
181- var constructor = member.declaredElement ;
181+ var constructor = member.declaredFragment ? .element ;
182182 if (constructor == null ) return ;
183183 if (! constructor.isFactory && ! constructor.isConst) return ;
184184 var name = member.name? .lexeme;
0 commit comments