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- import 'package:analyzer/dart/element/element .dart' ;
5+ import 'package:analyzer/dart/element/element2 .dart' ;
66import 'package:analyzer/dart/element/type.dart' ;
77import 'package:analyzer/error/listener.dart' ;
88import 'package:analyzer/src/dart/ast/ast.dart' ;
99import 'package:analyzer/src/dart/element/extensions.dart' ;
1010import 'package:analyzer/src/error/codes.dart' ;
11+ import 'package:analyzer/src/utilities/extensions/ast.dart' ;
12+ import 'package:analyzer/src/utilities/extensions/object.dart' ;
1113import 'package:analyzer/src/utilities/extensions/string.dart' ;
1214import 'package:analyzer/src/workspace/workspace.dart' ;
1315import 'package:meta/meta_meta.dart' ;
@@ -17,14 +19,15 @@ class AnnotationVerifier {
1719 final ErrorReporter _errorReporter;
1820
1921 /// The current library.
20- final LibraryElement _currentLibrary;
22+ final LibraryElement2 _currentLibrary;
2123
2224 /// The [WorkspacePackage] in which [_currentLibrary] is declared.
2325 final WorkspacePackage ? _workspacePackage;
2426
2527 /// Whether [_currentLibrary] is part of its containing package's public API.
2628 late final bool _inPackagePublicApi = _workspacePackage != null &&
27- _workspacePackage.sourceIsInPublicApi (_currentLibrary.source);
29+ _workspacePackage
30+ .sourceIsInPublicApi (_currentLibrary.firstFragment.source);
2831
2932 AnnotationVerifier (
3033 this ._errorReporter,
@@ -115,12 +118,13 @@ class AnnotationVerifier {
115118 /// `@internal` annotation.
116119 void _checkInternal (Annotation node) {
117120 var parent = node.parent;
118- var parentElement = parent is Declaration ? parent.declaredElement : null ;
121+ var parentElement =
122+ parent.ifTypeOrNull <Declaration >()? .declaredFragment? .element;
119123 var parentElementIsPrivate = parentElement? .isPrivate ?? false ;
120124 if (parent is TopLevelVariableDeclaration ) {
121125 for (var variable in parent.variables.variables) {
122- var element = variable.declaredElement as TopLevelVariableElement ;
123- if (Identifier . isPrivateName ( element.name) ) {
126+ var element = variable.declaredTopLevelVariableElement ;
127+ if (element.isPrivate ) {
124128 _errorReporter.atNode (
125129 variable,
126130 WarningCode .INVALID_INTERNAL_ANNOTATION ,
@@ -129,16 +133,17 @@ class AnnotationVerifier {
129133 }
130134 } else if (parent is FieldDeclaration ) {
131135 for (var variable in parent.fields.variables) {
132- var element = variable.declaredElement as FieldElement ;
133- if (Identifier . isPrivateName ( element.name) ) {
136+ var element = variable.declaredFieldElement ;
137+ if (element.isPrivate ) {
134138 _errorReporter.atNode (
135139 variable,
136140 WarningCode .INVALID_INTERNAL_ANNOTATION ,
137141 );
138142 }
139143 }
140144 } else if (parent is ConstructorDeclaration ) {
141- var class_ = parent.declaredElement! .enclosingElement3;
145+ var element = parent.declaredFragment! .element;
146+ var class_ = element.enclosingElement2;
142147 if (class_.isPrivate || parentElementIsPrivate) {
143148 _errorReporter.atNode (
144149 node.name,
@@ -162,10 +167,10 @@ class AnnotationVerifier {
162167 var kinds = element.targetKinds;
163168 if (kinds.isNotEmpty) {
164169 if (! _isValidTarget (parent, kinds)) {
165- var invokedElement = element.element ! ;
166- var name = invokedElement.name ;
167- if (invokedElement is ConstructorElement ) {
168- var className = invokedElement.enclosingElement3.name ;
170+ var invokedElement = element.element2 ! ;
171+ var name = invokedElement.name3 ;
172+ if (invokedElement is ConstructorElement2 ) {
173+ var className = invokedElement.enclosingElement2.name3 ;
169174 if (name! .isEmpty) {
170175 name = className;
171176 } else {
@@ -243,16 +248,16 @@ class AnnotationVerifier {
243248 /// Reports a warning at [node] if its parent is not a valid target for a
244249 /// `@reopen` annotation.
245250 void _checkReopen (Annotation node) {
246- ClassElement ? classElement;
247- InterfaceElement ? superElement;
251+ ClassElement2 ? classElement;
252+ InterfaceElement2 ? superElement;
248253
249254 var parent = node.parent;
250255 if (parent is ClassDeclaration ) {
251- classElement = parent.declaredElement ;
252- superElement = classElement? .supertype? .element ;
256+ classElement = parent.declaredFragment ? .element ;
257+ superElement = classElement? .supertype? .element3 ;
253258 } else if (parent is ClassTypeAlias ) {
254- classElement = parent.declaredElement ;
255- superElement = classElement? .supertype? .element ;
259+ classElement = parent.declaredFragment ? .element ;
260+ superElement = classElement? .supertype? .element3 ;
256261 } else {
257262 // If `parent` is neither of the above types, then `_checkKinds` will
258263 // report a warning.
@@ -262,7 +267,7 @@ class AnnotationVerifier {
262267 if (classElement == null ) {
263268 return ;
264269 }
265- if (superElement is ! ClassElement ) {
270+ if (superElement is ! ClassElement2 ) {
266271 return ;
267272 }
268273 if (classElement.isFinal ||
@@ -274,7 +279,7 @@ class AnnotationVerifier {
274279 );
275280 return ;
276281 }
277- if (classElement.library != superElement.library ) {
282+ if (classElement.library2 != superElement.library2 ) {
278283 _errorReporter.atNode (
279284 node.name,
280285 WarningCode .INVALID_REOPEN_ANNOTATION ,
@@ -319,7 +324,7 @@ class AnnotationVerifier {
319324 if (name != null ) {
320325 var parameterName = undefinedParameter is SimpleStringLiteral
321326 ? undefinedParameter.value
322- : undefinedParameter.staticParameterElement ? .name ;
327+ : undefinedParameter.correspondingParameter ? .name3 ;
323328 _errorReporter.atNode (
324329 undefinedParameter,
325330 WarningCode .UNDEFINED_REFERENCED_PARAMETER ,
@@ -354,11 +359,10 @@ class AnnotationVerifier {
354359
355360 if (parent is TopLevelVariableDeclaration ) {
356361 for (VariableDeclaration variable in parent.variables.variables) {
357- var variableElement =
358- variable.declaredElement as TopLevelVariableElement ;
362+ var variableElement = variable.declaredTopLevelVariableElement;
359363
360- var variableName = variableElement.name ;
361- if (Identifier .isPrivateName (variableName)) {
364+ var variableName = variableElement.name3 ;
365+ if (variableName != null && Identifier .isPrivateName (variableName)) {
362366 reportInvalidAnnotation (variableName);
363367 }
364368
@@ -369,25 +373,24 @@ class AnnotationVerifier {
369373 }
370374 } else if (parent is FieldDeclaration ) {
371375 for (VariableDeclaration variable in parent.fields.variables) {
372- var fieldElement = variable.declaredElement as FieldElement ;
376+ var fieldElement = variable.declaredFieldElement ;
373377 if (parent.isStatic && element.isVisibleForOverriding) {
374378 reportInvalidVisibleForOverriding ();
375379 }
376380
377- var fieldName = fieldElement.name ;
378- if (Identifier .isPrivateName (fieldName)) {
381+ var fieldName = fieldElement.name3 ;
382+ if (fieldName != null && Identifier .isPrivateName (fieldName)) {
379383 reportInvalidAnnotation (fieldName);
380384 }
381385 }
382- } else if (parent.declaredElement != null ) {
383- var declaredElement = parent.declaredElement! ;
386+ } else if (parent.declaredFragment? .element case var declaredElement? ) {
384387 if (element.isVisibleForOverriding &&
385388 (! declaredElement.isInstanceMember ||
386- declaredElement.enclosingElement3 is ExtensionTypeElement )) {
389+ declaredElement.enclosingElement2 is ExtensionTypeElement2 )) {
387390 reportInvalidVisibleForOverriding ();
388391 }
389392
390- var name = declaredElement.name ;
393+ var name = declaredElement.name3 ;
391394 if (name != null && Identifier .isPrivateName (name)) {
392395 reportInvalidAnnotation (name);
393396 }
@@ -425,14 +428,14 @@ class AnnotationVerifier {
425428 return ;
426429 }
427430
428- InterfaceElement ? declaredElement;
431+ InterfaceElement2 ? declaredElement;
429432 switch (containedDeclaration.parent) {
430433 case ClassDeclaration classDeclaration:
431- declaredElement = classDeclaration.declaredElement ;
434+ declaredElement = classDeclaration.declaredFragment ? .element ;
432435 case EnumDeclaration enumDeclaration:
433- declaredElement = enumDeclaration.declaredElement ;
436+ declaredElement = enumDeclaration.declaredFragment ? .element ;
434437 case MixinDeclaration mixinDeclaration:
435- declaredElement = mixinDeclaration.declaredElement ;
438+ declaredElement = mixinDeclaration.declaredFragment ? .element ;
436439 default :
437440 reportError ();
438441 return ;
@@ -443,7 +446,7 @@ class AnnotationVerifier {
443446 return ;
444447 }
445448
446- for (var annotation in declaredElement.metadata ) {
449+ for (var annotation in declaredElement.metadata2.annotations ) {
447450 if (annotation.isVisibleForTemplate) {
448451 return ;
449452 }
0 commit comments