diff --git a/lib/src/ast/css/at_rule.dart b/lib/src/ast/css/at_rule.dart index 2564c8ca..864d8751 100644 --- a/lib/src/ast/css/at_rule.dart +++ b/lib/src/ast/css/at_rule.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'node.dart'; import 'value.dart'; @@ -18,4 +19,6 @@ abstract class CssAtRule extends CssParentNode { /// This implies `children.isEmpty`, but the reverse is not true—for a rule /// like `@foo {}`, [children] is empty but [isChildless] is `false`. bool get isChildless; + + T accept(CssVisitor visitor) => visitor.visitCssAtRule(this); } diff --git a/lib/src/ast/css/comment.dart b/lib/src/ast/css/comment.dart index 6c8b8017..4724a83b 100644 --- a/lib/src/ast/css/comment.dart +++ b/lib/src/ast/css/comment.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'node.dart'; /// A plain CSS comment. @@ -14,4 +15,6 @@ abstract class CssComment extends CssNode { /// Whether this comment starts with `/*!` and so should be preserved even in /// compressed mode. bool get isPreserved; + + T accept(CssVisitor visitor) => visitor.visitCssComment(this); } diff --git a/lib/src/ast/css/declaration.dart b/lib/src/ast/css/declaration.dart index 51558cb3..01b26c3a 100644 --- a/lib/src/ast/css/declaration.dart +++ b/lib/src/ast/css/declaration.dart @@ -5,6 +5,7 @@ import 'package:source_span/source_span.dart'; import '../../value.dart'; +import '../../visitor/interface/css.dart'; import 'node.dart'; import 'value.dart'; @@ -22,4 +23,6 @@ abstract class CssDeclaration extends CssNode { /// where that variable was declared whereas [value.span] is the span where /// the variable was used. Otherwise, this is identical to [value.span]. FileSpan get valueSpanForMap; + + T accept(CssVisitor visitor) => visitor.visitCssDeclaration(this); } diff --git a/lib/src/ast/css/import.dart b/lib/src/ast/css/import.dart index fcefc003..065ef076 100644 --- a/lib/src/ast/css/import.dart +++ b/lib/src/ast/css/import.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'media_query.dart'; import 'node.dart'; import 'value.dart'; @@ -18,4 +19,6 @@ abstract class CssImport extends CssNode { /// The media query attached to this import. List get media; + + T accept(CssVisitor visitor) => visitor.visitCssImport(this); } diff --git a/lib/src/ast/css/keyframe_block.dart b/lib/src/ast/css/keyframe_block.dart index e85e3e08..0b52cd82 100644 --- a/lib/src/ast/css/keyframe_block.dart +++ b/lib/src/ast/css/keyframe_block.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'node.dart'; import 'value.dart'; @@ -11,4 +12,6 @@ import 'value.dart'; abstract class CssKeyframeBlock extends CssParentNode { /// The selector for this block. CssValue> get selector; + + T accept(CssVisitor visitor) => visitor.visitCssKeyframeBlock(this); } diff --git a/lib/src/ast/css/media_rule.dart b/lib/src/ast/css/media_rule.dart index affcca8b..d44859fb 100644 --- a/lib/src/ast/css/media_rule.dart +++ b/lib/src/ast/css/media_rule.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'media_query.dart'; import 'node.dart'; @@ -11,4 +12,6 @@ abstract class CssMediaRule extends CssParentNode { /// /// This is never empty. List get queries; + + T accept(CssVisitor visitor) => visitor.visitCssMediaRule(this); } diff --git a/lib/src/ast/css/modifiable/at_rule.dart b/lib/src/ast/css/modifiable/at_rule.dart index 990ef840..4a4f3ce6 100644 --- a/lib/src/ast/css/modifiable/at_rule.dart +++ b/lib/src/ast/css/modifiable/at_rule.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../at_rule.dart'; import '../value.dart'; import 'node.dart'; @@ -20,7 +20,7 @@ class ModifiableCssAtRule extends ModifiableCssParentNode implements CssAtRule { {bool childless = false, this.value}) : isChildless = childless; - T accept(CssVisitor visitor) => visitor.visitCssAtRule(this); + T accept(ModifiableCssVisitor visitor) => visitor.visitCssAtRule(this); ModifiableCssAtRule copyWithoutChildren() => ModifiableCssAtRule(name, span, childless: isChildless, value: value); diff --git a/lib/src/ast/css/modifiable/comment.dart b/lib/src/ast/css/modifiable/comment.dart index 3ea3d151..40e7838c 100644 --- a/lib/src/ast/css/modifiable/comment.dart +++ b/lib/src/ast/css/modifiable/comment.dart @@ -5,7 +5,7 @@ import 'package:charcode/charcode.dart'; import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../comment.dart'; import 'node.dart'; @@ -18,5 +18,5 @@ class ModifiableCssComment extends ModifiableCssNode implements CssComment { ModifiableCssComment(this.text, this.span); - T accept(CssVisitor visitor) => visitor.visitCssComment(this); + T accept(ModifiableCssVisitor visitor) => visitor.visitCssComment(this); } diff --git a/lib/src/ast/css/modifiable/declaration.dart b/lib/src/ast/css/modifiable/declaration.dart index b9910848..fb7dc2b3 100644 --- a/lib/src/ast/css/modifiable/declaration.dart +++ b/lib/src/ast/css/modifiable/declaration.dart @@ -5,7 +5,7 @@ import 'package:source_span/source_span.dart'; import '../../../value.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../declaration.dart'; import '../value.dart'; import 'node.dart'; @@ -22,5 +22,6 @@ class ModifiableCssDeclaration extends ModifiableCssNode {FileSpan valueSpanForMap}) : valueSpanForMap = valueSpanForMap ?? span; - T accept(CssVisitor visitor) => visitor.visitCssDeclaration(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssDeclaration(this); } diff --git a/lib/src/ast/css/modifiable/import.dart b/lib/src/ast/css/modifiable/import.dart index 0e5d9eb4..cf8127ff 100644 --- a/lib/src/ast/css/modifiable/import.dart +++ b/lib/src/ast/css/modifiable/import.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../import.dart'; import '../media_query.dart'; import '../value.dart'; @@ -29,5 +29,5 @@ class ModifiableCssImport extends ModifiableCssNode implements CssImport { {this.supports, Iterable media}) : media = media == null ? null : List.unmodifiable(media); - T accept(CssVisitor visitor) => visitor.visitCssImport(this); + T accept(ModifiableCssVisitor visitor) => visitor.visitCssImport(this); } diff --git a/lib/src/ast/css/modifiable/keyframe_block.dart b/lib/src/ast/css/modifiable/keyframe_block.dart index 96383bbb..69233f35 100644 --- a/lib/src/ast/css/modifiable/keyframe_block.dart +++ b/lib/src/ast/css/modifiable/keyframe_block.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../keyframe_block.dart'; import '../value.dart'; import 'node.dart'; @@ -17,7 +17,8 @@ class ModifiableCssKeyframeBlock extends ModifiableCssParentNode ModifiableCssKeyframeBlock(this.selector, this.span); - T accept(CssVisitor visitor) => visitor.visitCssKeyframeBlock(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssKeyframeBlock(this); ModifiableCssKeyframeBlock copyWithoutChildren() => ModifiableCssKeyframeBlock(selector, span); diff --git a/lib/src/ast/css/modifiable/media_rule.dart b/lib/src/ast/css/modifiable/media_rule.dart index 385fb5c3..f1dcf25e 100644 --- a/lib/src/ast/css/modifiable/media_rule.dart +++ b/lib/src/ast/css/modifiable/media_rule.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../media_query.dart'; import '../media_rule.dart'; import 'node.dart'; @@ -22,7 +22,8 @@ class ModifiableCssMediaRule extends ModifiableCssParentNode } } - T accept(CssVisitor visitor) => visitor.visitCssMediaRule(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssMediaRule(this); ModifiableCssMediaRule copyWithoutChildren() => ModifiableCssMediaRule(queries, span); diff --git a/lib/src/ast/css/modifiable/node.dart b/lib/src/ast/css/modifiable/node.dart index 5cd33c1a..61e11883 100644 --- a/lib/src/ast/css/modifiable/node.dart +++ b/lib/src/ast/css/modifiable/node.dart @@ -4,7 +4,7 @@ import 'dart:collection'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../at_rule.dart'; import '../node.dart'; import '../style_rule.dart'; @@ -57,7 +57,7 @@ abstract class ModifiableCssNode extends CssNode { } } - T accept(CssVisitor visitor); + T accept(ModifiableCssVisitor visitor); /// Removes [this] from [parent]'s child list. /// diff --git a/lib/src/ast/css/modifiable/style_rule.dart b/lib/src/ast/css/modifiable/style_rule.dart index 78ef3a10..a342abee 100644 --- a/lib/src/ast/css/modifiable/style_rule.dart +++ b/lib/src/ast/css/modifiable/style_rule.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../../selector.dart'; import '../style_rule.dart'; import 'node.dart'; @@ -28,7 +28,8 @@ class ModifiableCssStyleRule extends ModifiableCssParentNode : selector = selector, originalSelector = originalSelector ?? selector.value; - T accept(CssVisitor visitor) => visitor.visitCssStyleRule(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssStyleRule(this); ModifiableCssStyleRule copyWithoutChildren() => ModifiableCssStyleRule(selector, span, diff --git a/lib/src/ast/css/modifiable/stylesheet.dart b/lib/src/ast/css/modifiable/stylesheet.dart index 25f2505a..46610a94 100644 --- a/lib/src/ast/css/modifiable/stylesheet.dart +++ b/lib/src/ast/css/modifiable/stylesheet.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../stylesheet.dart'; import 'node.dart'; @@ -15,7 +15,8 @@ class ModifiableCssStylesheet extends ModifiableCssParentNode ModifiableCssStylesheet(this.span); - T accept(CssVisitor visitor) => visitor.visitCssStylesheet(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssStylesheet(this); ModifiableCssStylesheet copyWithoutChildren() => ModifiableCssStylesheet(span); diff --git a/lib/src/ast/css/modifiable/supports_rule.dart b/lib/src/ast/css/modifiable/supports_rule.dart index f344d5fa..ef921b51 100644 --- a/lib/src/ast/css/modifiable/supports_rule.dart +++ b/lib/src/ast/css/modifiable/supports_rule.dart @@ -4,7 +4,7 @@ import 'package:source_span/source_span.dart'; -import '../../../visitor/interface/css.dart'; +import '../../../visitor/interface/modifiable_css.dart'; import '../supports_rule.dart'; import '../value.dart'; import 'node.dart'; @@ -17,7 +17,8 @@ class ModifiableCssSupportsRule extends ModifiableCssParentNode ModifiableCssSupportsRule(this.condition, this.span); - T accept(CssVisitor visitor) => visitor.visitCssSupportsRule(this); + T accept(ModifiableCssVisitor visitor) => + visitor.visitCssSupportsRule(this); ModifiableCssSupportsRule copyWithoutChildren() => ModifiableCssSupportsRule(condition, span); diff --git a/lib/src/ast/css/style_rule.dart b/lib/src/ast/css/style_rule.dart index 53b134f5..063a9e28 100644 --- a/lib/src/ast/css/style_rule.dart +++ b/lib/src/ast/css/style_rule.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import '../selector.dart'; import 'node.dart'; import 'value.dart'; @@ -14,4 +15,6 @@ import 'value.dart'; abstract class CssStyleRule extends CssParentNode { /// The selector for this rule. CssValue get selector; + + T accept(CssVisitor visitor) => visitor.visitCssStyleRule(this); } diff --git a/lib/src/ast/css/supports_rule.dart b/lib/src/ast/css/supports_rule.dart index 0c63cbb8..091ba1da 100644 --- a/lib/src/ast/css/supports_rule.dart +++ b/lib/src/ast/css/supports_rule.dart @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import '../../visitor/interface/css.dart'; import 'node.dart'; import 'value.dart'; @@ -9,4 +10,6 @@ import 'value.dart'; abstract class CssSupportsRule extends CssParentNode { /// The supports condition. CssValue get condition; + + T accept(CssVisitor visitor) => visitor.visitCssSupportsRule(this); } diff --git a/lib/src/visitor/interface/css.dart b/lib/src/visitor/interface/css.dart index 4f609546..06485582 100644 --- a/lib/src/visitor/interface/css.dart +++ b/lib/src/visitor/interface/css.dart @@ -3,11 +3,12 @@ // https://opensource.org/licenses/MIT. import '../../ast/css.dart'; +import 'modifiable_css.dart'; /// An interface for [visitors][] that traverse CSS statements. /// /// [visitors]: https://en.wikipedia.org/wiki/Visitor_pattern -abstract class CssVisitor { +abstract class CssVisitor implements ModifiableCssVisitor { T visitCssAtRule(CssAtRule node); T visitCssComment(CssComment node); T visitCssDeclaration(CssDeclaration node); diff --git a/lib/src/visitor/interface/modifiable_css.dart b/lib/src/visitor/interface/modifiable_css.dart new file mode 100644 index 00000000..643dc9b0 --- /dev/null +++ b/lib/src/visitor/interface/modifiable_css.dart @@ -0,0 +1,20 @@ +// Copyright 2019 Google Inc. Use of this source code is governed by an +// MIT-style license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +import '../../ast/css/modifiable.dart'; + +/// An interface for [visitors][] that traverse CSS statements. +/// +/// [visitors]: https://en.wikipedia.org/wiki/Visitor_pattern +abstract class ModifiableCssVisitor { + T visitCssAtRule(ModifiableCssAtRule node); + T visitCssComment(ModifiableCssComment node); + T visitCssDeclaration(ModifiableCssDeclaration node); + T visitCssImport(ModifiableCssImport node); + T visitCssKeyframeBlock(ModifiableCssKeyframeBlock node); + T visitCssMediaRule(ModifiableCssMediaRule node); + T visitCssStyleRule(ModifiableCssStyleRule node); + T visitCssStylesheet(ModifiableCssStylesheet node); + T visitCssSupportsRule(ModifiableCssSupportsRule node); +}