public final class PropertyValue extends AbstractSyntax
Declaration
.
This contains a list of Term
s, for example numbers, keywords, functions, hex colors, etc...
You can add new members to this via append(PropertyValueMember)
, or by utilizing the SyntaxCollection
returned
by the members()
method.
In the CSS 2.1 spec this is called "expr", which is obviously shorthand for "expression", however "expression" is name now given to multiple syntax units within different CSS3 modules! So that's why this is not called expression.
Term
,
PropertyValueParser
,
PropertyValueMember
Constructor and Description |
---|
PropertyValue()
Creates a new instance with no line or number specified (used for dynamically created
Syntax units). |
PropertyValue(int line,
int column)
Constructs a new
PropertyValue instance. |
Modifier and Type | Method and Description |
---|---|
PropertyValue |
append(OperatorType type)
Adds a new
Operator with the given OperatorType . |
PropertyValue |
append(PropertyValueMember member)
Adds a new
PropertyValueMember to this PropertyValue . |
PropertyValue |
copy()
For implementations: do not copy comments or orphaned comments, instead be sure to call
AbstractSyntax.copiedFrom(Syntax) on the
new copy. |
long |
countTerms()
Does a quick count of the number of
Term s (does not include operators) within this PropertyValue . |
Declaration |
declaration()
Gets the parent
Declaration that owns this property. |
void |
declaration(Declaration parent)
Sets the parent
Declaration . |
PropertyValue |
important(boolean important)
Sets whether this
PropertyValue is marked as "!important". |
boolean |
isImportant()
Gets whether this
PropertyValue is marked as "!important". |
boolean |
isWritable()
Returns whether this unit should actually be written.
|
SyntaxCollection<PropertyValue,PropertyValueMember> |
members()
Gets the
SyntaxCollection of PropertyValueMember s. |
static PropertyValue |
of(OperatorType separator,
Term term,
Term... terms)
Creates a new
PropertyValue with multiple terms separated by the given OperatorType . |
static PropertyValue |
of(Term term)
Creates a new
PropertyValue with the given Term as the only member. |
static PropertyValue |
of(Term term,
PropertyValueMember... members)
Creates a new
PropertyValue with one or more terms and operators. |
static PropertyValue |
of(Term term,
Term... terms)
Creates a new
PropertyValue with multiple terms. |
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Broadcasts or rebroadcasts all child units using the given
Broadcaster . |
Optional<String> |
singleTextualValue()
Gets the textual content of the only
Term within this PropertyValue . |
com.google.common.collect.ImmutableList<Term> |
terms()
Gets the list of
Term s currently in this PropertyValue (as opposed to members() which returns both
terms and operators). |
void |
write(StyleWriter writer,
StyleAppendable appendable)
Outputs this
Writable 's string representation. |
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, copiedFrom, equals, hasAnnotation, hasAnnotation, hashCode, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, shouldBreakBroadcast, status, status, toString, toString, writesOwnComments, writesOwnOrphanedComments
public PropertyValue()
Syntax
units).public PropertyValue(int line, int column)
PropertyValue
instance.line
- The line number.column
- The column number.public PropertyValue append(PropertyValueMember member)
PropertyValueMember
to this PropertyValue
.member
- The member to add.public PropertyValue append(OperatorType type)
Operator
with the given OperatorType
.type
- The OperatorType
.public SyntaxCollection<PropertyValue,PropertyValueMember> members()
SyntaxCollection
of PropertyValueMember
s. Use this to append, prepend or otherwise reorganize the
terms and operators in this PropertyValue
.SyntaxCollection
instance.public com.google.common.collect.ImmutableList<Term> terms()
Term
s currently in this PropertyValue
(as opposed to members()
which returns both
terms and operators).Term
s.public long countTerms()
Term
s (does not include operators) within this PropertyValue
.Term
s.public Optional<String> singleTextualValue()
Term
within this PropertyValue
. The returned Optional
will only be present if this PropertyValue
contains exactly one Term
!
This method may be useful as a generic way of getting the value of unknown or potentially varying term types.
Important: this is not a substitute or a replica of how the term or this property value will actually be written to
a stylesheet. The textual content returned may not include certain tokens and outer symbols such as hashes, quotes,
parenthesis, etc... . To get the textual content as it would be written to a stylesheet see (Writable)
instead. However note that you should rarely have need for doing that outside of actually creating stylesheet
output.
KeywordValue
s will simply return the keyword, StringValue
s will return the contents of the string not
including quotes, functions will return the content of the function not including the parenthesis, HexColorValue
will return the hex value without the leading '#' , and so on... See each specific Term
implementation for more details.
Important: if this property value has more than one term then this method will return an empty Optional
. It
will not concatenate term values.
Optional
if there is more than one or no terms present.Term.textualValue()
public boolean isImportant()
PropertyValue
is marked as "!important".public PropertyValue important(boolean important)
PropertyValue
is marked as "!important".important
- Whether the value is "!important".public void declaration(Declaration parent)
Declaration
. Generally this is handled automatically when this property value is set on the Declaration
, so it is not recommended to call this method manually. If you do, results may be unexpected.parent
- The Declaration
that contains this property.public Declaration declaration()
Declaration
that owns this property. This will not be set for dynamically created property values
not yet added to a Declaration
instance.Declaration
. If working with this term before it has been properly linked then this may return
null. This is not the case for normal subscription methods.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 AbstractSyntax
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.
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 PropertyValue copy()
AbstractSyntax
AbstractSyntax.copiedFrom(Syntax)
on the
new copy.copy
in interface Syntax
copy
in class AbstractSyntax
public static PropertyValue of(Term term)
PropertyValue
with the given Term
as the only member.
Example:
PropertyValue.of(NumericalValue.of(10, "px"));
term
- The term.PropertyValue
instance.public static PropertyValue of(Term term, Term... terms)
PropertyValue
with multiple terms. No operators will be placed between the terms.
Example:
NumericalValue px10 = NumericalValue.of(10, "px");
NumericalValue em5 = NumericalValue.of(5, "em");
PropertyValue value = PropertyValue.of(px10, em5);
term
- The first term.terms
- Additional terms.PropertyValue
instance.public static PropertyValue of(OperatorType separator, Term term, Term... terms)
PropertyValue
with multiple terms separated by the given OperatorType
.
Example:
NumericalValue px10 = NumericalValue.of(10, "px");
NumericalValue em5 = NumericalValue.of(5, "em");
PropertyValue value = PropertyValue.of(OperatorType.SLASH, px10, em5);
separator
- The OperatorType
to place in between each Term
.term
- The first term.terms
- Additional terms.PropertyValue
instance.public static PropertyValue of(Term term, PropertyValueMember... members)
Creates a new PropertyValue
with one or more terms and operators.
Example:
NumericalValue px10 = NumericalValue.of(10, "px");
NumericalValue em5 = NumericalValue.of(5, "em");
PropertyValue value = PropertyValue.of(px10, OperatorType.SLASH, em5);
term
- The first term.members
- The additional terms and operators.PropertyValue
instance.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.