Skip to content

Commit

Permalink
[Migrate] unused_local_elements_verifier.dart
Browse files Browse the repository at this point in the history
Change-Id: I1d68dda93d6282118827826ea6ee8e5fe13b78fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403907
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
  • Loading branch information
bwilkerson authored and Commit Queue committed Jan 16, 2025
1 parent f72576a commit 9f465e5
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 229 deletions.
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ extension IdentifierExtension on Identifier {
return _readElement(this);
}

Element2? get readElement2 {
return _readElement(this).asElement2;
}

SimpleIdentifier get simpleName {
var self = this;
if (self is SimpleIdentifier) {
Expand All @@ -233,6 +237,10 @@ extension IdentifierExtension on Identifier {
return _writeElement(this);
}

Element2? get writeElement2 {
return _writeElement(this).asElement2;
}

Element? get writeOrReadElement {
return _writeElement(this) ?? staticElement;
}
Expand Down
25 changes: 23 additions & 2 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ class BindPatternVariableElementImpl2 extends PatternVariableElementImpl2
];
}

/// This flag is set to `true` if this variable clashes with another
/// pattern variable with the same name within the same pattern.
/// Whether this variable clashes with another pattern variable with the same
/// name within the same pattern.
bool get isDuplicate => _wrappedElement.isDuplicate;

/// Set whether this variable clashes with another pattern variable with the
/// same name within the same pattern.
set isDuplicate(bool value) => _wrappedElement.isDuplicate = value;

DeclaredVariablePatternImpl get node => _wrappedElement.node;
Expand Down Expand Up @@ -6793,6 +6797,23 @@ class JoinPatternVariableElementImpl2 extends PatternVariableElementImpl2
/// The identifiers that reference this element.
List<SimpleIdentifier> get references => _wrappedElement.references;

/// Returns this variable, and variables that join into it.
List<PatternVariableElementImpl2> get transitiveVariables {
var result = <PatternVariableElementImpl2>[];

void append(PatternVariableElementImpl2 variable) {
result.add(variable);
if (variable is JoinPatternVariableElementImpl2) {
for (var variable in variable.variables2) {
append(variable as PatternVariableElementImpl2);
}
}
}

append(this);
return result;
}

/// The variables that join into this variable.
List<PatternVariableElementImpl> get variables => _wrappedElement.variables;

Expand Down
Loading

0 comments on commit 9f465e5

Please sign in to comment.