public final class AtRule extends AbstractGroupable<StatementIterable,Statement> implements Statement, Refinable, Named
@media
, @charset
, @keyframes
, etc...
See the notes on Refinable
.
AtRuleParser
Constructor and Description |
---|
AtRule(int line,
int column,
String name,
RawSyntax rawExpression,
RawSyntax rawBlock)
Constructs a new
AtRule instance. |
AtRule(String name,
AtRuleExpression expression,
AtRuleBlock block)
Creates a new instance with no line or column specified (used for dynamically created
Syntax units). |
Modifier and Type | Method and Description |
---|---|
Optional<AtRuleBlock> |
block()
Gets the at-rule block, if present.
|
AtRule |
block(AtRuleBlock block)
Sets the
AtRuleBlock . |
AtRule |
copy()
For implementations: do not copy comments or orphaned comments, instead be sure to call
AbstractSyntax.copiedFrom(Syntax) on the
new copy. |
Optional<AtRuleExpression> |
expression()
Gets the at-rule expression, if present.
|
AtRule |
expression(AtRuleExpression expression)
Sets the
AtRuleExpression . |
boolean |
isConditional()
Determines if this rule is conditional (
@if ) or not. |
boolean |
isRefined()
Gets whether this unit is refined.
|
boolean |
isWritable()
Returns whether this unit should actually be written.
|
AtRule |
markAsMetadataRule()
Used to indicate this at-rule is for metadata purposes only and should not be written out in the output CSS.
|
String |
name()
Gets the name of this object.
|
AtRule |
name(String name)
Sets the at-rule name.
|
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Broadcasts or rebroadcasts all child units using the given
Broadcaster . |
Optional<RawSyntax> |
rawBlock()
Gets the original, raw, non-validated at-rule block, if present.
|
Optional<RawSyntax> |
rawExpression()
Gets the original, raw, non-validated expression if present (e.g., "utf-8", or "all and (min-width: 800px)".
|
protected AtRule |
self()
Should return "this".
|
void |
setConditional(boolean isConditional)
Setter to indicate this at rule is a conditional rule (
@if ). |
boolean |
shouldBreakBroadcast(SubscriptionPhase phase)
Gets whether an in-progress broadcast should be stopped.
|
boolean |
shouldWriteName()
Gets whether the name of the atRule should be written out.
|
AtRule |
shouldWriteName(boolean shouldWriteName)
Specifies whether the name should be written out.
|
void |
write(StyleWriter writer,
StyleAppendable appendable)
Outputs this
Writable 's string representation. |
append, destroy, group, group, isDestroyed, isFirst, isLast, next, parent, prepend, previous, replaceWith, unlink
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, copiedFrom, equals, hasAnnotation, hasAnnotation, hashCode, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, status, status, toString, toString, writesOwnComments, writesOwnOrphanedComments
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
append, destroy, group, group, isDestroyed, isFirst, isLast, next, parent, prepend, previous, replaceWith, unlink
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, hasAnnotation, hasAnnotation, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, toString, writesOwnComments, writesOwnOrphanedComments
status, status
public AtRule(int line, int column, String name, RawSyntax rawExpression, RawSyntax rawBlock)
AtRule
instance.line
- The line number.column
- The column number.name
- Name of the at-rule.rawExpression
- The raw at-rule expression. If no expression is present pass in null.rawBlock
- The raw at-rule block. If no block is present pass in null.public AtRule(String name, AtRuleExpression expression, AtRuleBlock block)
Syntax
units).name
- Name of the at-rule.expression
- The at-rule's expression, or null if not present.block
- The at-rule's block, or null if not present.public AtRule name(String name)
name
- The new name.public AtRule shouldWriteName(boolean shouldWriteName)
shouldWriteName
- Whether the at-rule name (and @ symbol) should be written out.markAsMetadataRule()
public boolean shouldWriteName()
shouldWriteName(boolean)
.public Optional<RawSyntax> rawExpression()
Optional
if not present.public Optional<RawSyntax> rawBlock()
Optional
if not present.public AtRule expression(AtRuleExpression expression)
AtRuleExpression
.expression
- The expression.public Optional<AtRuleExpression> expression()
Important: this may be Optional.empty()
if this at-rule is unrefined.
Optional
if not present.public AtRule block(AtRuleBlock block)
AtRuleBlock
.block
- The block.public Optional<AtRuleBlock> block()
Important: this may be Optional.empty()
if this at-rule is unrefined.
Optional
if not present.public AtRule markAsMetadataRule()
This is mainly used for custom syntax.
public boolean isRefined()
Refinable
public void setConditional(boolean isConditional)
@if
).isConditional
- True if this rule is conditional.isConditional()
public boolean isConditional()
@if
) or not.
For more information on conditional at rules, see
ConditionalAtRuleBlock
.
setConditional(boolean)
public boolean shouldBreakBroadcast(SubscriptionPhase phase)
Broadcastable
This might be true if a change of state or conditions of the unit result in the broadcast no longer being necessary during
the given SubscriptionPhase
.
shouldBreakBroadcast
in interface Broadcastable
shouldBreakBroadcast
in class AbstractSyntax
phase
- The current SubscriptionPhase
.protected AtRule self()
AbstractGroupable
AbstractGroupable
class.self
in class AbstractGroupable<StatementIterable,Statement>
public void propagateBroadcast(Broadcaster broadcaster, Status status)
Broadcastable
Broadcaster
.
The broadcast will only occur for a unit if its Status
matches the given Status
.
Implementers should call this on child units and SyntaxCollection
s first, then use the broadcaster to broadcast
itself. All of this should be wrapped in a check to ensure the Status
matches.
propagateBroadcast
in interface Broadcastable
propagateBroadcast
in class AbstractSyntax
broadcaster
- Use this Broadcaster
to broadcast all unbroadcasted child units.status
- Broadcast units that have this status.public boolean isWritable()
Writable
Usually this should just return true, however some units that are detachable or otherwise potentially invalid should first check their state and respond appropriately.
isWritable
in interface Writable
isWritable
in class AbstractGroupable<StatementIterable,Statement>
public void write(StyleWriter writer, StyleAppendable appendable) throws IOException
Writable
Writable
's string representation.
Important notes for implementation:
Do not use the StyleWriter
in an attempt to write direct content (Strings, chars, etc...). Use the StyleAppendable
.
The StyleWriter
should be used to make decisions based on writer settings (e.g., compressed vs. verbose output
mode), as well as for writing inner or child Writable
s. Do not call the this method method directly on inner
or child Writable
s! That would bypass any overrides that are set on the StyleWriter
. Use StyleWriter.writeInner(Writable, StyleAppendable)
instead.
write
in interface Writable
writer
- Writer to use for output settings and for writing inner Writable
s.appendable
- Append direct content to this StyleAppendable
.IOException
- If an I/O error occurs.public AtRule copy()
AbstractSyntax
AbstractSyntax.copiedFrom(Syntax)
on the
new copy.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.