This repository was archived by the owner on Sep 16, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
angular_analyzer_plugin/lib/src/selector Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:angular_analyzer_plugin/src/selector/attribute_selector_base.dart' ;
2+ import 'package:angular_analyzer_plugin/src/selector/element_view.dart' ;
3+ import 'package:angular_analyzer_plugin/src/selector/html_tag_for_selector.dart' ;
4+ import 'package:angular_analyzer_plugin/src/selector/selector.dart' ;
5+ import 'package:angular_analyzer_plugin/src/selector/match.dart' ;
6+ import 'package:angular_analyzer_plugin/src/selector/name.dart' ;
7+
8+ /// The [Selector] that matches elements that have an attribute with the
9+ /// given name, and (optionally) with the given value;
10+ class AttributeSelector extends AttributeSelectorBase {
11+ @override
12+ final SelectorName nameElement;
13+ final String value;
14+
15+ AttributeSelector (this .nameElement, this .value);
16+
17+ @override
18+ List <SelectorName > getAttributes (ElementView element) =>
19+ match (element, null ) == SelectorMatch .NonTagMatch ? [] : [nameElement];
20+
21+ @override
22+ bool matchValue (String attributeValue) =>
23+ value == null || attributeValue == value;
24+
25+ @override
26+ List <HtmlTagForSelector > refineTagSuggestions (
27+ List <HtmlTagForSelector > context) {
28+ for (final tag in context) {
29+ tag.setAttribute (nameElement.string, value: value);
30+ }
31+ return context;
32+ }
33+
34+ @override
35+ String toString () {
36+ final name = nameElement.string;
37+ if (value != null ) {
38+ return '[$name =$value ]' ;
39+ }
40+ return '[$name ]' ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments