@@ -21,52 +21,65 @@ abstract class Node {
2121 Iterable <String > get variables;
2222
2323 /// Calls the appropriate [Visitor] method on [this] and returns the result.
24- accept (Visitor visitor);
24+ dynamic accept (Visitor visitor);
2525}
2626
2727/// A single variable.
2828class VariableNode implements Node {
29+ @override
2930 final FileSpan span;
3031
3132 /// The variable name.
3233 final String name;
3334
35+ @override
3436 Iterable <String > get variables => [name];
3537
3638 VariableNode (this .name, [this .span]);
3739
38- accept (Visitor visitor) => visitor.visitVariable (this );
40+ @override
41+ dynamic accept (Visitor visitor) => visitor.visitVariable (this );
3942
43+ @override
4044 String toString () => name;
4145
46+ @override
4247 bool operator == (other) => other is VariableNode && name == other.name;
4348
49+ @override
4450 int get hashCode => name.hashCode;
4551}
4652
4753/// A negation expression.
4854class NotNode implements Node {
55+ @override
4956 final FileSpan span;
5057
5158 /// The expression being negated.
5259 final Node child;
5360
61+ @override
5462 Iterable <String > get variables => child.variables;
5563
5664 NotNode (this .child, [this .span]);
5765
58- accept (Visitor visitor) => visitor.visitNot (this );
66+ @override
67+ dynamic accept (Visitor visitor) => visitor.visitNot (this );
5968
69+ @override
6070 String toString () =>
61- child is VariableNode || child is NotNode ? " !$child " : " !($child )" ;
71+ child is VariableNode || child is NotNode ? ' !$child ' : ' !($child )' ;
6272
73+ @override
6374 bool operator == (other) => other is NotNode && child == other.child;
6475
76+ @override
6577 int get hashCode => ~ child.hashCode;
6678}
6779
6880/// An or expression.
6981class OrNode implements Node {
82+ @override
7083 FileSpan get span => _expandSafe (left.span, right.span);
7184
7285 /// The left-hand branch of the expression.
@@ -75,31 +88,37 @@ class OrNode implements Node {
7588 /// The right-hand branch of the expression.
7689 final Node right;
7790
91+ @override
7892 Iterable <String > get variables sync * {
7993 yield * left.variables;
8094 yield * right.variables;
8195 }
8296
8397 OrNode (this .left, this .right);
8498
85- accept (Visitor visitor) => visitor.visitOr (this );
99+ @override
100+ dynamic accept (Visitor visitor) => visitor.visitOr (this );
86101
102+ @override
87103 String toString () {
88- var string1 = left is AndNode || left is ConditionalNode ? " ($left )" : left;
104+ var string1 = left is AndNode || left is ConditionalNode ? ' ($left )' : left;
89105 var string2 =
90- right is AndNode || right is ConditionalNode ? " ($right )" : right;
106+ right is AndNode || right is ConditionalNode ? ' ($right )' : right;
91107
92- return " $string1 || $string2 " ;
108+ return ' $string1 || $string2 ' ;
93109 }
94110
111+ @override
95112 bool operator == (other) =>
96113 other is OrNode && left == other.left && right == other.right;
97114
115+ @override
98116 int get hashCode => left.hashCode ^ right.hashCode;
99117}
100118
101119/// An and expression.
102120class AndNode implements Node {
121+ @override
103122 FileSpan get span => _expandSafe (left.span, right.span);
104123
105124 /// The left-hand branch of the expression.
@@ -108,31 +127,37 @@ class AndNode implements Node {
108127 /// The right-hand branch of the expression.
109128 final Node right;
110129
130+ @override
111131 Iterable <String > get variables sync * {
112132 yield * left.variables;
113133 yield * right.variables;
114134 }
115135
116136 AndNode (this .left, this .right);
117137
118- accept (Visitor visitor) => visitor.visitAnd (this );
138+ @override
139+ dynamic accept (Visitor visitor) => visitor.visitAnd (this );
119140
141+ @override
120142 String toString () {
121- var string1 = left is OrNode || left is ConditionalNode ? " ($left )" : left;
143+ var string1 = left is OrNode || left is ConditionalNode ? ' ($left )' : left;
122144 var string2 =
123- right is OrNode || right is ConditionalNode ? " ($right )" : right;
145+ right is OrNode || right is ConditionalNode ? ' ($right )' : right;
124146
125- return " $string1 && $string2 " ;
147+ return ' $string1 && $string2 ' ;
126148 }
127149
150+ @override
128151 bool operator == (other) =>
129152 other is AndNode && left == other.left && right == other.right;
130153
154+ @override
131155 int get hashCode => left.hashCode ^ right.hashCode;
132156}
133157
134158/// A ternary conditional expression.
135159class ConditionalNode implements Node {
160+ @override
136161 FileSpan get span => _expandSafe (condition.span, whenFalse.span);
137162
138163 /// The condition expression to check.
@@ -144,6 +169,7 @@ class ConditionalNode implements Node {
144169 /// The branch to run if the condition is false.
145170 final Node whenFalse;
146171
172+ @override
147173 Iterable <String > get variables sync * {
148174 yield * condition.variables;
149175 yield * whenTrue.variables;
@@ -152,21 +178,25 @@ class ConditionalNode implements Node {
152178
153179 ConditionalNode (this .condition, this .whenTrue, this .whenFalse);
154180
155- accept (Visitor visitor) => visitor.visitConditional (this );
181+ @override
182+ dynamic accept (Visitor visitor) => visitor.visitConditional (this );
156183
184+ @override
157185 String toString () {
158186 var conditionString =
159- condition is ConditionalNode ? " ($condition )" : condition;
160- var trueString = whenTrue is ConditionalNode ? " ($whenTrue )" : whenTrue;
161- return " $conditionString ? $trueString : $whenFalse " ;
187+ condition is ConditionalNode ? ' ($condition )' : condition;
188+ var trueString = whenTrue is ConditionalNode ? ' ($whenTrue )' : whenTrue;
189+ return ' $conditionString ? $trueString : $whenFalse ' ;
162190 }
163191
192+ @override
164193 bool operator == (other) =>
165194 other is ConditionalNode &&
166195 condition == other.condition &&
167196 whenTrue == other.whenTrue &&
168197 whenFalse == other.whenFalse;
169198
199+ @override
170200 int get hashCode =>
171201 condition.hashCode ^ whenTrue.hashCode ^ whenFalse.hashCode;
172202}
0 commit comments