public final class Selector extends AbstractGroupable<Rule,Selector> implements Refinable
Selector
s are lists of SelectorPart
s. Individual Selector
s are separated by commas. For example, in
.class, .class #id
There are two selectors:
1:See the notes on.class
2:.class #id
Refinable
regarding unrefined selectors.
When dynamically creating selectors, you usually pass in the various SelectorPart
s to the constructor. Example:
Selector selector = new Selector(new ClassSelector("myClass"), Combinator.descendant(), new IdSelector("myId"));
You can also append or prepend parts directly on the SyntaxCollection
returned from the parts()
method.ComplexSelectorParser
Constructor and Description |
---|
Selector(int line,
int column,
Iterable<SelectorPart> parts)
Creates a new instance with the given line, number, and parts.
|
Selector(int line,
int column,
SelectorPart... parts)
Creates a new instance with the given line, number, and parts.
|
Selector(Iterable<SelectorPart> parts)
Creates a new instance with no line or number specified (used for dynamically created
Syntax units). |
Selector(RawSyntax raw)
Creates a new instance of a
Selector with the given raw content. |
Selector(SelectorPart... parts)
Creates a new instance with no line or number specified (used for dynamically created
Syntax units). |
Modifier and Type | Method and Description |
---|---|
Selector |
append(SelectorPart newPart)
Appends the given part to this
Selector . |
Selector |
appendAll(Iterable<SelectorPart> newParts)
Appends all of the given parts to this
Selector . |
Selector |
copy()
For implementations: do not copy comments or orphaned comments, instead be sure to call
AbstractSyntax.copiedFrom(Syntax) on the
new copy. |
void |
destroy()
Removes this unit from its collection.
|
boolean |
isKeyframe()
Gets whether this selector is used for @keyframes.
|
boolean |
isRefined()
Gets whether this unit is refined.
|
boolean |
isWritable()
Returns whether this unit should actually be written.
|
SyntaxCollection<Selector,SelectorPart> |
parts()
Gets the individual parts of the selector.
|
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Broadcasts or rebroadcasts all child units using the given
Broadcaster . |
Optional<RawSyntax> |
raw()
Gets the original, raw, non-validated selector content.
|
protected Selector |
self()
Should return "this".
|
boolean |
shouldBreakBroadcast(SubscriptionPhase phase)
Gets whether an in-progress broadcast should be stopped.
|
void |
write(StyleWriter writer,
StyleAppendable appendable)
Outputs this
Writable 's string representation. |
boolean |
writesOwnComments()
Specifies whether this object will handle writing its own comments, instead of the automatic behavior of the
StyleWriter . |
append, 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, writesOwnOrphanedComments
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, hasAnnotation, hasAnnotation, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, toString, writesOwnOrphanedComments
status, status
public Selector(RawSyntax raw)
Selector
with the given raw content.
If dynamically creating a new instance then use Selector(SelectorPart...)
or Selector(Iterable)
instead.
raw
- The selector content.public Selector(SelectorPart... parts)
Syntax
units).parts
- The parts within the selector.public Selector(Iterable<SelectorPart> parts)
Syntax
units).parts
- The parts within the selector.public Selector(int line, int column, SelectorPart... parts)
If dynamically creating a new instance then use Selector(SelectorPart...)
or Selector(Iterable)
instead.
line
- The line number.column
- The column number.parts
- The selector parts to add.public Selector(int line, int column, Iterable<SelectorPart> parts)
If dynamically creating a new instance then use Selector(SelectorPart...)
or Selector(Iterable)
instead.
line
- The line number.column
- The column number.parts
- The selector parts to add.public Optional<RawSyntax> raw()
Optional
if the raw content is not set (e.g., a dynamically created
unit).public SyntaxCollection<Selector,SelectorPart> parts()
Important: this may not contain any selector parts if this selector is unrefined! See the main readme file for more information on refinement.
For basic use cases, to ensure this is always refined and properly set use AutoRefine
or StandardValidation
during parsing. For reasons why you would not want to do that see the main readme file.
SelectorPart
members.public Selector append(SelectorPart newPart)
Selector
.newPart
- The part to append.public Selector appendAll(Iterable<SelectorPart> newParts)
Selector
.newParts
- The parts to append.public boolean isKeyframe()
XXX consider making keyframe selectors disjoint from regular selectors.
public boolean isRefined()
Refinable
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
.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.protected Selector self()
AbstractGroupable
AbstractGroupable
class.self
in class AbstractGroupable<Rule,Selector>
public boolean writesOwnComments()
Syntax
StyleWriter
.
If returning true, be sure to check StyleWriter#shouldWriteAllComments()
to determine if comments should actually
be written out or not. The StyleWriter#appendComments(Iterable, StyleAppendable)
utility method contains this logic
and is the preferable way to handle it.
writesOwnComments
in interface Syntax
writesOwnComments
in class AbstractSyntax
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<Rule,Selector>
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 Selector copy()
AbstractSyntax
AbstractSyntax.copiedFrom(Syntax)
on the
new copy.copy
in interface Syntax
copy
in class AbstractSyntax
public void destroy()
Groupable
Once removed, the unit cannot be re-added to any collection, however it can still be copied. Destroyed units will no longer be broadcasted to any subsequent plugins.
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.