|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -// ignore_for_file: analyzer_use_new_elements |
6 | | - |
7 | 5 | import 'package:analyzer/dart/element/element.dart'; |
| 6 | +import 'package:analyzer/dart/element/element2.dart'; |
8 | 7 | // ignore: implementation_imports |
9 | 8 | import 'package:analyzer/src/dart/element/member.dart' show ParameterMember; |
| 9 | +// ignore: implementation_imports |
| 10 | +import 'package:analyzer/src/utilities/extensions/element.dart'; |
10 | 11 | import 'package:dartdoc/src/element_type.dart'; |
11 | 12 | import 'package:dartdoc/src/model/comment_referable.dart'; |
12 | 13 | import 'package:dartdoc/src/model/kind.dart'; |
13 | 14 | import 'package:dartdoc/src/model/model.dart'; |
14 | 15 |
|
15 | 16 | class Parameter extends ModelElement with HasNoPage { |
16 | 17 | @override |
17 | | - final ParameterElement element; |
| 18 | + // ignore: analyzer_use_new_elements |
| 19 | + ParameterElement get element => element2.asElement; |
18 | 20 |
|
19 | | - Parameter(this.element, super.library, super.packageGraph, |
| 21 | + @override |
| 22 | + final FormalParameterElement element2; |
| 23 | + |
| 24 | + Parameter(this.element2, super.library, super.packageGraph, |
20 | 25 | {ParameterMember? super.originalMember}); |
21 | 26 |
|
22 | | - String? get defaultValue => hasDefaultValue ? element.defaultValueCode : null; |
| 27 | + String? get defaultValue => |
| 28 | + hasDefaultValue ? element2.defaultValueCode : null; |
23 | 29 |
|
24 | 30 | @override |
25 | 31 | ModelElement? get enclosingElement { |
26 | | - final enclosingElement = element.enclosingElement3; |
| 32 | + final enclosingElement = element2.enclosingElement2; |
27 | 33 | return enclosingElement == null |
28 | 34 | ? null |
29 | | - : getModelFor(enclosingElement, library); |
| 35 | + : getModelFor2(enclosingElement, library); |
30 | 36 | } |
31 | 37 |
|
32 | 38 | bool get hasDefaultValue { |
33 | | - return element.defaultValueCode != null && |
34 | | - element.defaultValueCode!.isNotEmpty; |
| 39 | + return element2.defaultValueCode != null && |
| 40 | + element2.defaultValueCode!.isNotEmpty; |
35 | 41 | } |
36 | 42 |
|
37 | 43 | @override |
38 | 44 | String? get href => null; |
39 | 45 |
|
40 | 46 | @override |
41 | 47 | String get htmlId { |
42 | | - final enclosingElement = element.enclosingElement3; |
| 48 | + final enclosingElement = element2.enclosingElement2; |
43 | 49 | if (enclosingElement == null) { |
44 | 50 | return 'param-$name'; |
45 | 51 | } |
46 | | - var enclosingName = enclosingElement.name; |
47 | | - if (enclosingElement is GenericFunctionTypeElement) { |
| 52 | + var enclosingName = enclosingElement.lookupName; |
| 53 | + if (enclosingName == 'new') { |
| 54 | + enclosingName = ''; |
| 55 | + } |
| 56 | + if (enclosingElement is GenericFunctionTypeElement2) { |
48 | 57 | // TODO(jcollins-g): Drop when GenericFunctionTypeElement populates |
49 | 58 | // name. Also, allowing null here is allowed as a workaround for |
50 | 59 | // dart-lang/sdk#32005. |
51 | | - for (Element e = enclosingElement; |
52 | | - e.enclosingElement3 != null; |
53 | | - e = e.enclosingElement3!) { |
54 | | - enclosingName = e.name; |
| 60 | + for (Element2 e = enclosingElement; |
| 61 | + e.enclosingElement2 != null; |
| 62 | + e = e.enclosingElement2!) { |
| 63 | + enclosingName = e.lookupName; |
55 | 64 | if (enclosingName != null && enclosingName.isNotEmpty) break; |
56 | 65 | } |
57 | 66 | } |
58 | 67 | return '$enclosingName-param-$name'; |
59 | 68 | } |
60 | 69 |
|
61 | 70 | @override |
62 | | - int get hashCode => element.hashCode; |
| 71 | + int get hashCode => element2.hashCode; |
63 | 72 |
|
64 | 73 | @override |
65 | 74 | bool operator ==(Object other) => |
66 | | - other is Parameter && (element.type == other.element.type); |
| 75 | + other is Parameter && (element2.type == other.element2.type); |
67 | 76 |
|
68 | | - bool get isCovariant => element.isCovariant; |
| 77 | + bool get isCovariant => element2.isCovariant; |
69 | 78 |
|
70 | | - bool get isRequiredPositional => element.isRequiredPositional; |
| 79 | + bool get isRequiredPositional => element2.isRequiredPositional; |
71 | 80 |
|
72 | | - bool get isNamed => element.isNamed; |
| 81 | + bool get isNamed => element2.isNamed; |
73 | 82 |
|
74 | | - bool get isOptionalPositional => element.isOptionalPositional; |
| 83 | + bool get isOptionalPositional => element2.isOptionalPositional; |
75 | 84 |
|
76 | 85 | /// Only true if this is a required named parameter. |
77 | | - bool get isRequiredNamed => element.isRequiredNamed; |
| 86 | + bool get isRequiredNamed => element2.isRequiredNamed; |
78 | 87 |
|
79 | 88 | @override |
80 | 89 | Kind get kind => Kind.parameter; |
@@ -102,5 +111,5 @@ class Parameter extends ModelElement with HasNoPage { |
102 | 111 | super.originalMember as ParameterMember?; |
103 | 112 |
|
104 | 113 | late final ElementType modelType = |
105 | | - getTypeFor((originalMember ?? element).type, library); |
| 114 | + getTypeFor((originalMember ?? element2).type, library); |
106 | 115 | } |
0 commit comments