-
Notifications
You must be signed in to change notification settings - Fork 130
Elements. Migrate to Element2 #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,79 +2,88 @@ | |
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| // ignore_for_file: analyzer_use_new_elements | ||
|
|
||
| import 'package:analyzer/dart/element/element.dart'; | ||
| import 'package:analyzer/dart/element/element2.dart'; | ||
| // ignore: implementation_imports | ||
| import 'package:analyzer/src/dart/element/member.dart' show ParameterMember; | ||
| // ignore: implementation_imports | ||
| import 'package:analyzer/src/utilities/extensions/element.dart'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| import 'package:dartdoc/src/element_type.dart'; | ||
| import 'package:dartdoc/src/model/comment_referable.dart'; | ||
| import 'package:dartdoc/src/model/kind.dart'; | ||
| import 'package:dartdoc/src/model/model.dart'; | ||
|
|
||
| class Parameter extends ModelElement with HasNoPage { | ||
| @override | ||
| final ParameterElement element; | ||
| // ignore: analyzer_use_new_elements | ||
| ParameterElement get element => element2.asElement; | ||
|
|
||
| Parameter(this.element, super.library, super.packageGraph, | ||
| @override | ||
| final FormalParameterElement element2; | ||
|
|
||
| Parameter(this.element2, super.library, super.packageGraph, | ||
| {ParameterMember? super.originalMember}); | ||
|
|
||
| String? get defaultValue => hasDefaultValue ? element.defaultValueCode : null; | ||
| String? get defaultValue => | ||
| hasDefaultValue ? element2.defaultValueCode : null; | ||
|
|
||
| @override | ||
| ModelElement? get enclosingElement { | ||
| final enclosingElement = element.enclosingElement3; | ||
| final enclosingElement = element2.enclosingElement2; | ||
| return enclosingElement == null | ||
| ? null | ||
| : getModelFor(enclosingElement, library); | ||
| : getModelFor2(enclosingElement, library); | ||
| } | ||
|
|
||
| bool get hasDefaultValue { | ||
| return element.defaultValueCode != null && | ||
| element.defaultValueCode!.isNotEmpty; | ||
| return element2.defaultValueCode != null && | ||
| element2.defaultValueCode!.isNotEmpty; | ||
| } | ||
|
|
||
| @override | ||
| String? get href => null; | ||
|
|
||
| @override | ||
| String get htmlId { | ||
| final enclosingElement = element.enclosingElement3; | ||
| final enclosingElement = element2.enclosingElement2; | ||
| if (enclosingElement == null) { | ||
| return 'param-$name'; | ||
| } | ||
| var enclosingName = enclosingElement.name; | ||
| if (enclosingElement is GenericFunctionTypeElement) { | ||
| var enclosingName = enclosingElement.lookupName; | ||
| if (enclosingName == 'new') { | ||
| enclosingName = ''; | ||
| } | ||
| if (enclosingElement is GenericFunctionTypeElement2) { | ||
| // TODO(jcollins-g): Drop when GenericFunctionTypeElement populates | ||
| // name. Also, allowing null here is allowed as a workaround for | ||
| // dart-lang/sdk#32005. | ||
| for (Element e = enclosingElement; | ||
| e.enclosingElement3 != null; | ||
| e = e.enclosingElement3!) { | ||
| enclosingName = e.name; | ||
| for (Element2 e = enclosingElement; | ||
| e.enclosingElement2 != null; | ||
| e = e.enclosingElement2!) { | ||
| enclosingName = e.lookupName; | ||
| if (enclosingName != null && enclosingName.isNotEmpty) break; | ||
| } | ||
| } | ||
| return '$enclosingName-param-$name'; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => element.hashCode; | ||
| int get hashCode => element2.hashCode; | ||
|
|
||
| @override | ||
| bool operator ==(Object other) => | ||
| other is Parameter && (element.type == other.element.type); | ||
| other is Parameter && (element2.type == other.element2.type); | ||
|
|
||
| bool get isCovariant => element.isCovariant; | ||
| bool get isCovariant => element2.isCovariant; | ||
|
|
||
| bool get isRequiredPositional => element.isRequiredPositional; | ||
| bool get isRequiredPositional => element2.isRequiredPositional; | ||
|
|
||
| bool get isNamed => element.isNamed; | ||
| bool get isNamed => element2.isNamed; | ||
|
|
||
| bool get isOptionalPositional => element.isOptionalPositional; | ||
| bool get isOptionalPositional => element2.isOptionalPositional; | ||
|
|
||
| /// Only true if this is a required named parameter. | ||
| bool get isRequiredNamed => element.isRequiredNamed; | ||
| bool get isRequiredNamed => element2.isRequiredNamed; | ||
|
|
||
| @override | ||
| Kind get kind => Kind.parameter; | ||
|
|
@@ -102,5 +111,5 @@ class Parameter extends ModelElement with HasNoPage { | |
| super.originalMember as ParameterMember?; | ||
|
|
||
| late final ElementType modelType = | ||
| getTypeFor((originalMember ?? element).type, library); | ||
| getTypeFor((originalMember ?? element2).type, library); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to remember to search for imports of these extensions before we declare the package fully converted.
Alternatively, you could remove
elementand use.element2.asElementin any unconverted files. That might be less error prone.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Will use that moving forward and change these in a follow up CL.