public final class Declaration extends AbstractGroupable<Rule,Declaration> implements Refinable, Named
See the notes on Refinable
.
DeclarationParser
,
PropertyValueParser
Constructor and Description |
---|
Declaration(PropertyName propertyName,
PropertyValue propertyValue)
|
Declaration(PropertyName propertyName,
Term singleValue)
|
Declaration(Property propertyName,
PropertyValue propertyValue)
|
Declaration(Property propertyName,
Term singleValue)
|
Declaration(RawSyntax rawName,
RawSyntax rawValue)
Creates a new
Declaration with the given rawProperty (property name) and rawValue (property value). |
Modifier and Type | Method and Description |
---|---|
Declaration |
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 |
isPrefixed()
Gets whether the
PropertyName is prefixed. |
boolean |
isProperty(Property property)
Gets whether this
Declaration has the given Property name. |
boolean |
isProperty(PropertyName propertyName)
Gets whether this
Declaration has a PropertyName that matches the given one. |
boolean |
isProperty(String name)
Gets whether this
Declaration has the given property name. |
boolean |
isPropertyIgnorePrefix(Property property)
Same as
isProperty(Property) , except this ignores the prefix. |
boolean |
isPropertyIgnorePrefix(PropertyName propertyName)
Same as
isProperty(PropertyName) , except this ignores the prefix. |
boolean |
isPropertyIgnorePrefix(String name)
Same as
isProperty(String) , except this ignores the prefix. |
boolean |
isRefined()
Gets whether this unit is refined.
|
boolean |
isWritable()
Returns whether this unit should actually be written.
|
String |
name()
Gets the name of this object.
|
Optional<AtRule> |
parentAtRule()
Similar to
AbstractGroupable.parent() , except this will return the parent's containing AtRule . |
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Broadcasts or rebroadcasts all child units using the given
Broadcaster . |
PropertyName |
propertyName()
Gets the property name.
|
Declaration |
propertyName(Property property)
Sets a new property name.
|
Declaration |
propertyName(PropertyName propertyName)
Sets a new property name.
|
Declaration |
propertyName(String propertyName)
Sets a new property name.
|
PropertyValue |
propertyValue()
Gets the property value.
|
Declaration |
propertyValue(PropertyValue propertyValue)
Sets a new property value.
|
Declaration |
propertyValue(Term singleTerm)
Sets a new property value.
|
Optional<RawSyntax> |
rawPropertyName()
Gets the original, raw, non-validated property name.
|
Optional<RawSyntax> |
rawPropertyValue()
Gets the original, raw, non-validated property value.
|
protected Declaration |
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 Declaration(RawSyntax rawName, RawSyntax rawValue)
Declaration
with the given rawProperty (property name) and rawValue (property value).rawName
- The raw property name.rawValue
- The raw property value.public Declaration(Property propertyName, PropertyValue propertyValue)
Declaration
with the given PropertyName
and PropertyValue
.
This should be used for dynamically created declarations.
Example:
NumericalValue px10 = NumericalValue.of(10, "px");
NumericalValue em5 = NumericalValue.of(5, "em");
PropertyValue value = PropertyValue.ofTerms(OperatorType.SPACE, px10, em5);
new Declaration(Property.BORDER_RADIUS, value)
If there is only a single value then use Declaration(Property, Term)
instead.
propertyName
- The Property
.propertyValue
- The PropertyValue
.public Declaration(Property propertyName, Term singleValue)
Declaration
with the given Property
and single Term
value.
This should be used for dynamically created declarations.
Example:
new Declaration(Property.ZOOM, NumericalValue.of(1));
public Declaration(PropertyName propertyName, Term singleValue)
Declaration
with the given PropertyName
and single Term
value.
This should be used for dynamically created declarations.
Example:
PropertyName name = PropertyName.using("new-prop");
new Declaration(name, NumericalValue.of(1));
propertyName
- The property name.singleValue
- The single Term
.public Declaration(PropertyName propertyName, PropertyValue propertyValue)
Declaration
with the given PropertyName
and PropertyValue
.
This should be used for dynamically created declarations.
Example:
PropertyName prop = PropertyName.using(Property.BORDER_RADIUS).prefix(Prefix.WEBKIT);
Declaration newDeclaration = new Declaration(prop, declaration.propertyValue());
propertyName
- The PropertyName
.propertyValue
- The PropertyValue
.public Optional<RawSyntax> rawPropertyName()
Optional
if the raw property name is not set (e.g., a dynamically
created unit).public Optional<RawSyntax> rawPropertyValue()
Optional
if the raw property value is not set (e.g., a dynamically
created unit).public Declaration propertyName(Property property)
property
- The new property.public Declaration propertyName(PropertyName propertyName)
propertyName
- The new property name.public Declaration propertyName(String propertyName)
propertyName
- The new property name.public PropertyName propertyName()
public boolean isProperty(String name)
Declaration
has the given property name. Prefer to use isProperty(Property)
instead.
Example:
if (declaration.isProperty("border-radius") {...}
name
- Name of the property.Declaration
has the given property name.public boolean isProperty(Property property)
Declaration
has the given Property
name.
Example:
if (declaration.isProperty(Property.BORDER_RADIUS)) {...}
property
- The Property
.Declaration
has the given property name.public boolean isProperty(PropertyName propertyName)
Declaration
has a PropertyName
that matches the given one. For the definition of this,
see PropertyName.matches(PropertyName)
.propertyName
- The PropertyName
.Declaration
has a property name that matches the given one.PropertyName.matches(PropertyName)
public boolean isPropertyIgnorePrefix(Property property)
isProperty(Property)
, except this ignores the prefix.property
- The property.Declaration
has the given property, ignoring the prefix.PropertyName.matchesIgnorePrefix(Property)
public boolean isPropertyIgnorePrefix(PropertyName propertyName)
isProperty(PropertyName)
, except this ignores the prefix.propertyName
- The PropertyName
.Declaration
has the given property name, ignoring the prefix.PropertyName.matchesIgnorePrefix(PropertyName)
public boolean isPropertyIgnorePrefix(String name)
isProperty(String)
, except this ignores the prefix.name
- The property name.Declaration
has the given property name, ignoring the prefix.PropertyName.matchesIgnorePrefix(String)
public boolean isPrefixed()
PropertyName
is prefixed.PropertyName
is prefixed.public Declaration propertyValue(Term singleTerm)
singleTerm
- The single Term
.public Declaration propertyValue(PropertyValue propertyValue)
propertyValue
- The new property value.public PropertyValue propertyValue()
Important: this may be an empty property value if this declaration 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.
public Optional<AtRule> parentAtRule()
AbstractGroupable.parent()
, except this will return the parent's containing AtRule
.
This is only applicable for declarations directly within a Rule
, directly within an AtRuleBlock
, directly
within an AtRule
.
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 Declaration self()
AbstractGroupable
AbstractGroupable
class.self
in class AbstractGroupable<Rule,Declaration>
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,Declaration>
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 Declaration 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.
destroy
in interface Groupable<Rule,Declaration>
destroy
in class AbstractGroupable<Rule,Declaration>
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.