55import 'package:analysis_server/src/collections.dart' ;
66import 'package:analysis_server/src/utilities/extensions/flutter.dart' ;
77import 'package:analyzer/dart/analysis/results.dart' ;
8- import 'package:analyzer/dart/ast/ast.dart' ;
98import 'package:analyzer/dart/ast/token.dart' ;
109import 'package:analyzer/dart/ast/visitor.dart' ;
11- import 'package:analyzer/dart/element/element.dart' as engine;
10+ import 'package:analyzer/dart/element/element2.dart' as engine;
11+ import 'package:analyzer/src/dart/ast/ast.dart' ;
1212import 'package:analyzer_plugin/protocol/protocol_common.dart' ;
1313
1414/// A computer for [CompilationUnit] outline.
@@ -106,7 +106,7 @@ class DartUnitOutlineComputer {
106106 name,
107107 Element .makeFlags (
108108 isPrivate: Identifier .isPrivateName (name),
109- isDeprecated: _isDeprecated (node),
109+ isDeprecated: _hasDeprecated (node.metadata ),
110110 isAbstract: node.abstractKeyword != null ),
111111 location: _getLocationToken (nameToken),
112112 typeParameters: _getTypeParametersStr (node.typeParameters));
@@ -121,7 +121,7 @@ class DartUnitOutlineComputer {
121121 name,
122122 Element .makeFlags (
123123 isPrivate: Identifier .isPrivateName (name),
124- isDeprecated: _isDeprecated (node),
124+ isDeprecated: _hasDeprecated (node.metadata ),
125125 isAbstract: node.abstractKeyword != null ),
126126 location: _getLocationToken (nameToken),
127127 typeParameters: _getTypeParametersStr (node.typeParameters));
@@ -148,7 +148,8 @@ class DartUnitOutlineComputer {
148148 ElementKind .CONSTRUCTOR ,
149149 name,
150150 Element .makeFlags (
151- isPrivate: isPrivate, isDeprecated: _isDeprecated (constructor)),
151+ isPrivate: isPrivate,
152+ isDeprecated: _hasDeprecated (constructor.metadata)),
152153 location: _getLocationOffsetLength (offset, length),
153154 parameters: parametersStr);
154155 var contents = _addFunctionBodyOutlines (constructor.body);
@@ -163,7 +164,7 @@ class DartUnitOutlineComputer {
163164 name,
164165 Element .makeFlags (
165166 isPrivate: Identifier .isPrivateName (name),
166- isDeprecated: _isDeprecated (node)),
167+ isDeprecated: _hasDeprecated (node.metadata )),
167168 location: _getLocationToken (nameToken));
168169 return _nodeOutline (node, element);
169170 }
@@ -176,7 +177,7 @@ class DartUnitOutlineComputer {
176177 name,
177178 Element .makeFlags (
178179 isPrivate: Identifier .isPrivateName (name),
179- isDeprecated: _isDeprecated (node)),
180+ isDeprecated: _hasDeprecated (node.metadata )),
180181 location: _getLocationToken (nameToken));
181182 return _nodeOutline (node, element, children);
182183 }
@@ -198,7 +199,7 @@ class DartUnitOutlineComputer {
198199 name,
199200 Element .makeFlags (
200201 isPrivate: Identifier .isPrivateName (name),
201- isDeprecated: _isDeprecated (node)),
202+ isDeprecated: _hasDeprecated (node.metadata )),
202203 location: location,
203204 typeParameters: _getTypeParametersStr (node.typeParameters));
204205 return _nodeOutline (node, element, extensionContents);
@@ -213,7 +214,7 @@ class DartUnitOutlineComputer {
213214 name,
214215 Element .makeFlags (
215216 isPrivate: Identifier .isPrivateName (name),
216- isDeprecated: _isDeprecated (node)),
217+ isDeprecated: _hasDeprecated (node.metadata )),
217218 location: _getLocationToken (nameToken),
218219 typeParameters: _getTypeParametersStr (node.typeParameters));
219220 return _nodeOutline (node, element, extensionContents);
@@ -240,7 +241,7 @@ class DartUnitOutlineComputer {
240241 name,
241242 Element .makeFlags (
242243 isPrivate: Identifier .isPrivateName (name),
243- isDeprecated: _isDeprecated (function),
244+ isDeprecated: _hasDeprecated (function.metadata ),
244245 isStatic: isStatic),
245246 location: _getLocationToken (nameToken),
246247 parameters: parametersStr,
@@ -263,7 +264,7 @@ class DartUnitOutlineComputer {
263264 name,
264265 Element .makeFlags (
265266 isPrivate: Identifier .isPrivateName (name),
266- isDeprecated: _isDeprecated (node)),
267+ isDeprecated: _hasDeprecated (node.metadata )),
267268 location: _getLocationToken (nameToken),
268269 parameters: parametersStr,
269270 returnType: returnTypeStr,
@@ -286,7 +287,7 @@ class DartUnitOutlineComputer {
286287 name,
287288 Element .makeFlags (
288289 isPrivate: Identifier .isPrivateName (name),
289- isDeprecated: _isDeprecated (node),
290+ isDeprecated: _hasDeprecated (node.metadata ),
290291 ),
291292 aliasedType: _safeToSource (aliasedType),
292293 location: _getLocationToken (nameToken),
@@ -322,7 +323,7 @@ class DartUnitOutlineComputer {
322323 name,
323324 Element .makeFlags (
324325 isPrivate: Identifier .isPrivateName (name),
325- isDeprecated: _isDeprecated (method),
326+ isDeprecated: _hasDeprecated (method.metadata ),
326327 isAbstract: method.isAbstract,
327328 isStatic: method.isStatic),
328329 location: _getLocationToken (nameToken),
@@ -342,7 +343,7 @@ class DartUnitOutlineComputer {
342343 name,
343344 Element .makeFlags (
344345 isPrivate: Identifier .isPrivateName (name),
345- isDeprecated: _isDeprecated (node)),
346+ isDeprecated: _hasDeprecated (node.metadata )),
346347 location: _getLocationToken (nameToken),
347348 typeParameters: _getTypeParametersStr (node.typeParameters));
348349 return _nodeOutline (node, element, mixinContents);
@@ -365,7 +366,7 @@ class DartUnitOutlineComputer {
365366 name,
366367 Element .makeFlags (
367368 isPrivate: Identifier .isPrivateName (name),
368- isDeprecated: _isDeprecated (variable),
369+ isDeprecated: _hasDeprecated (variable.metadata ),
369370 isStatic: isStatic,
370371 isConst: variable.isConst,
371372 isFinal: variable.isFinal),
@@ -436,10 +437,14 @@ class DartUnitOutlineComputer {
436437 return parameters.toSource ();
437438 }
438439
439- /// Returns `true` if the given [element] is not `null` and deprecated.
440- static bool _isDeprecated (Declaration declaration) {
441- var element = declaration.declaredElement;
442- return element != null && element.hasDeprecated;
440+ /// Whether the list of [annotations] includes a `deprecated` annotation.
441+ static bool _hasDeprecated (List <Annotation > annotations) {
442+ for (var annotation in annotations) {
443+ if (annotation.elementAnnotation? .isDeprecated ?? false ) {
444+ return true ;
445+ }
446+ }
447+ return false ;
443448 }
444449
445450 static String _safeToSource (AstNode ? node) =>
@@ -455,22 +460,22 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor<void> {
455460
456461 /// Return `true` if the given [element] is the method 'group' defined in the
457462 /// test package.
458- bool isGroup (engine.ExecutableElement ? element) {
463+ bool isGroup (engine.ExecutableElement2 ? element) {
459464 if (element != null && element.hasIsTestGroup) {
460465 return true ;
461466 }
462- return element is engine.FunctionElement &&
467+ return element is engine.TopLevelFunctionElement &&
463468 element.name == 'group' &&
464469 _isInsideTestPackage (element);
465470 }
466471
467472 /// Return `true` if the given [element] is the method 'test' defined in the
468473 /// test package.
469- bool isTest (engine.ExecutableElement ? element) {
474+ bool isTest (engine.ExecutableElement2 ? element) {
470475 if (element != null && element.hasIsTest) {
471476 return true ;
472477 }
473- return element is engine.FunctionElement &&
478+ return element is engine.TopLevelFunctionElement &&
474479 element.name == 'test' &&
475480 _isInsideTestPackage (element);
476481 }
@@ -505,8 +510,8 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor<void> {
505510 void visitMethodInvocation (MethodInvocation node) {
506511 var nameNode = node.methodName;
507512
508- var nameElement = nameNode.staticElement ;
509- if (nameElement is ! engine.ExecutableElement ) {
513+ var nameElement = nameNode.element ;
514+ if (nameElement is ! engine.ExecutableElement2 ) {
510515 return ;
511516 }
512517
@@ -549,9 +554,8 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor<void> {
549554
550555 /// Return `true` if the given [element] is a top-level member of the test
551556 /// package.
552- bool _isInsideTestPackage (engine.FunctionElement element) {
553- var parent = element.enclosingElement3;
554- return parent is engine.CompilationUnitElement &&
555- parent.source.fullName.endsWith ('test.dart' );
557+ bool _isInsideTestPackage (engine.TopLevelFunctionElement element) {
558+ var parent = element.library2! ;
559+ return parent.firstFragment.source.fullName.endsWith ('test.dart' );
556560 }
557561}
0 commit comments