This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1771 PiperOrigin-RevId: 242039436
- Loading branch information
1 parent
c04514c
commit 49e733d
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
angular_analyzer_plugin/lib/src/selector/attribute_selector.dart
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:angular_analyzer_plugin/src/selector/attribute_selector_base.dart'; | ||
import 'package:angular_analyzer_plugin/src/selector/element_view.dart'; | ||
import 'package:angular_analyzer_plugin/src/selector/html_tag_for_selector.dart'; | ||
import 'package:angular_analyzer_plugin/src/selector/selector.dart'; | ||
import 'package:angular_analyzer_plugin/src/selector/match.dart'; | ||
import 'package:angular_analyzer_plugin/src/selector/name.dart'; | ||
|
||
/// The [Selector] that matches elements that have an attribute with the | ||
/// given name, and (optionally) with the given value; | ||
class AttributeSelector extends AttributeSelectorBase { | ||
@override | ||
final SelectorName nameElement; | ||
final String value; | ||
|
||
AttributeSelector(this.nameElement, this.value); | ||
|
||
@override | ||
List<SelectorName> getAttributes(ElementView element) => | ||
match(element, null) == SelectorMatch.NonTagMatch ? [] : [nameElement]; | ||
|
||
@override | ||
bool matchValue(String attributeValue) => | ||
value == null || attributeValue == value; | ||
|
||
@override | ||
List<HtmlTagForSelector> refineTagSuggestions( | ||
List<HtmlTagForSelector> context) { | ||
for (final tag in context) { | ||
tag.setAttribute(nameElement.string, value: value); | ||
} | ||
return context; | ||
} | ||
|
||
@override | ||
String toString() { | ||
final name = nameElement.string; | ||
if (value != null) { | ||
return '[$name=$value]'; | ||
} | ||
return '[$name]'; | ||
} | ||
} |