This lexical unit may be followed by a number of subsequent units, accessible
via the getNextLexicalUnit() method. May also be preceded by other
units that can be accessed by the getPreviousLexicalUnit().
It is recommended that implementations of this interface override the
equals() and hashCode() methods, but in doing that do not
take into account subsequent lexical units in the chain.
Based on SAC's LexicalUnit interface by Philippe Le Hegaret.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a deep copy of this lexical unit and the next ones, unlinked to any previous lexical unit.intcountReplaceBy(LexicalUnit replacementUnit) Replace this unit in the chain of lexical units (by the unit or sequence of units in the argument) and return the count of replacement units.default intGives the index of this unit in its processing context.Get a parsable representation of this unit.shortAn integer indicating the type of CSS unit that this lexical value represents.If this unit is aDIMENSION, returns the string representation of the CSS unit returned bygetCssUnit().floatReturns the float value represented by this unit.Returns the name of the function.intReturns the integer value represented by this unit.Gives the type ofLexicalUnit.Gives the ID of this unit as a mathematical function, according toCSSMathFunctionValue.MathFunction.default intGives the index of this unit as a mathematical function.The next lexical unit.The function parameters including operators (like the comma).Get the list of preceding comments.The previous lexical unit.Returns the string value.Returns a sequence of units inside the sub-expression or unicode range.default CSSValueSyntaxGet the syntax specified by this unit.Get the list of trailing comments.default TransformFunctionsGives the ID of this unit as a transform function, according toTransformFunctions.voidinsertNextLexicalUnit(LexicalUnit nextUnit) Insert the given unit as the next lexical unit.booleanCheck if this lexical unit is a parameter that was made available through its parent'sgetParameters()method.matches(CSSValueSyntax syntax) Verify whether this value matches the given grammar.remove()Remove this unit from the chain of lexical units and replace it by the next one, if any.replaceBy(LexicalUnit replacementUnit) Replace this unit in the chain of lexical units.Creates a shallow copy of this lexical unit, ignoring the next ones, and unlinked to any previous lexical unit.shallowMatch(CSSValueSyntax syntax) Verify whether this lexical unit matches the given grammar, ignoring further units in the lexical chain.
-
Method Details
-
getLexicalUnitType
LexicalUnit.LexicalType getLexicalUnitType()Gives the type ofLexicalUnit.- Returns:
- the type of
LexicalUnit.
-
getCssUnit
short getCssUnit()An integer indicating the type of CSS unit that this lexical value represents.- Returns:
- an integer indicating the type of CSS unit. If this value does not represent a dimension, must return an invalid unit identifier.
-
getNextLexicalUnit
LexicalUnit getNextLexicalUnit()The next lexical unit.Lexical units can form chains of units which can be traversed with
getNextLexicalUnit()andgetPreviousLexicalUnit().- Returns:
- the next lexical unit, or
nullif none.
-
getPreviousLexicalUnit
LexicalUnit getPreviousLexicalUnit()The previous lexical unit.See also
getNextLexicalUnit().- Returns:
- the previous lexical unit, or
nullif none.
-
insertNextLexicalUnit
Insert the given unit as the next lexical unit.After the insertion,
nextUnitshall be the next lexical unit, and the former next lexical unit will be the next one after the last unit in thenextUnitunit chain.- Parameters:
nextUnit- the lexical unit to be set as the next one.- Throws:
IllegalArgumentException- if the argument is a parameter or has a previous unit.
-
remove
LexicalUnit remove()Remove this unit from the chain of lexical units and replace it by the next one, if any.- Returns:
- the next lexical unit, or
nullif there is no next lexical unit.
-
countReplaceBy
Replace this unit in the chain of lexical units (by the unit or sequence of units in the argument) and return the count of replacement units.The replaced unit always returns
nullforgetNextLexicalUnit()andgetPreviousLexicalUnit(),falseforisParameter().- Parameters:
replacementUnit- the lexical unit that replaces this one. Ifnull, this unit is replaced by the next one. IfEMPTY, this unit is replaced by the next non-empty unit in the parameter's lexical chain or, if there is none, by the next unit in this chain (same as if parameter wasnull).- Returns:
- the number of units that replace this one (i.e. the
argument, or
0if the argument isnull). - Throws:
IllegalArgumentException- if the replacement unit is a parameter or has a previous unit.CSSBudgetException- if the replacement unit has too many chained units (to avoid potential DoS).
-
replaceBy
Replace this unit in the chain of lexical units.The replaced unit always returns
nullforgetNextLexicalUnit()andgetPreviousLexicalUnit(),falseforisParameter().This method is very similar to
countReplaceBy(LexicalUnit)which gives important information when you need to replace this unit by an arbitrary (and potentially large) chunk of values.- Parameters:
replacementUnit- the lexical unit that replaces this one. Ifnull, this unit is replaced by the next one.- Returns:
- the unit that replaces this one (i.e. the argument, or the
next lexical unit if the argument is
null). - Throws:
IllegalArgumentException- if the replacement unit is a parameter or has a previous unit.CSSBudgetException- if the replacement unit has too many chained units (to avoid potential DoS).- See Also:
-
getIntegerValue
int getIntegerValue()Returns the integer value represented by this unit.- Returns:
- the integer value, or zero if this is not an integer unit.
- See Also:
-
getFloatValue
float getFloatValue()Returns the float value represented by this unit.- Returns:
- the float value, or
NaNif this value is not a float.
-
getDimensionUnitText
String getDimensionUnitText()If this unit is aDIMENSION, returns the string representation of the CSS unit returned bygetCssUnit().- Returns:
- the string representation of the CSS unit, or the empty string if
this lexical unit does not represent a
DIMENSION.
-
getStringValue
String getStringValue()Returns the string value.If the type is
URI, the return value doesn't containuri(....)or quotes.If the type is
UNICODE_WILDCARD, the return value is the wildcard without the preceding "U+".- Returns:
- the string value, or
nullif this unit does not have a string to return. - See Also:
-
getFunctionName
String getFunctionName()Returns the name of the function.- Returns:
- the function name, or
nullif this unit is not a function. - See Also:
-
getMathFunction
Gives the ID of this unit as a mathematical function, according toCSSMathFunctionValue.MathFunction.- Returns:
- the function enum, or
nullif this lexical unit is not a mathematical function (MATH_FUNCTION). - See Also:
-
getMathFunctionIndex
default int getMathFunctionIndex()Gives the index of this unit as a mathematical function.- Returns:
- the zero-based function index, or
-1if this lexical unit is not a mathematical function (MATH_FUNCTION). - See Also:
-
getContextIndex
default int getContextIndex()Gives the index of this unit in its processing context.This helps to speed processing in some contexts, like math or transform functions.
For example, if this unit represents a
MATH_FUNCTION, this method would return the same result asgetMathFunctionIndex().- Returns:
- the zero-based function index, or
-1if this lexical unit does not belong to any processing context.
-
getTransformFunction
Gives the ID of this unit as a transform function, according toTransformFunctions.- Returns:
- the function enum, or
nullif this lexical unit is not a transform function (TRANSFORM_FUNCTION). - See Also:
-
getParameters
LexicalUnit getParameters()The function parameters including operators (like the comma).A RGB color like
#000is converted torgb(0, 0, 0).May return
nullif type isFUNCTION.Since version 5, also returns the sub-values if this is an expression or a unicode range. Therefore, can be used as a more streamlined version of
getSubValues().- Returns:
- the parameters of this function, or
nullif this unit is not a function, or an emptyFUNCTION. - See Also:
-
isParameter
boolean isParameter()Check if this lexical unit is a parameter that was made available through its parent'sgetParameters()method.- Returns:
trueif this lexical unit is a parameter.
-
getSubValues
LexicalUnit getSubValues()Returns a sequence of units inside the sub-expression or unicode range.- Returns:
- the values in the sub-expression, or
nullif this unit is not a sub-expression nor a unicode range. - See Also:
-
getSyntax
Get the syntax specified by this unit.- Returns:
- the CSS syntax.
- Throws:
IllegalStateException- if this is not a syntax unit.- See Also:
-
getCssText
String getCssText()Get a parsable representation of this unit.The serialization must only include this lexical unit, ignoring the next units if they exist.
The text should be close to how the value was specified (for example, preserving hex or functional notation in rgb colors) but must parse without errors (except for compatibility values like
COMPAT_IDENT).- Returns:
- the parsable serialization of this unit.
-
getPrecedingComments
StringList getPrecedingComments()Get the list of preceding comments.- Returns:
- the list of preceding comments, or
nullif none.
-
getTrailingComments
StringList getTrailingComments()Get the list of trailing comments.- Returns:
- the list of trailing comments, or
nullif none.
-
matches
Verify whether this value matches the given grammar.This method is intended to be used for generic sanity checks and, consequently, some corner cases may not be taken into account. For example, when matching
var(), the implementations are allowed to assume that the property substitution shall not be empty, otherwise values likevar(--data) 1pxwould give a non-FALSEmatch simultaneously on syntaxes with and without a multiplier (+or#), which would probably not be what that use case wants.In the case of
calc(), if implementations do not perform a full dimensional analysis it is more acceptable to return a bogusTRUEthan aFALSE.This method takes into account the next units in the lexical chain, if you do not want that please use
shallowMatch(CSSValueSyntax)instead.Here are some examples of matching:
Value Syntax Match attr(data-width type(<length>), 8%)<percentage> | <length>TRUE<length>PENDING<percentage>PENDING<length>#PENDING<length-percentage>TRUE<resolution>FALSE*TRUE6pt var(--custom) 12.3px<length>+PENDING<length>#PENDING1<length>FALSE<number>+FALSE*TRUE- Despite the value containing no commas, the syntax with a
#multiplier matches asPENDINGbecause the custom property could have commas and start and end with one.
See also:
SyntaxParser,shallowMatch(CSSValueSyntax).- Parameters:
syntax- the syntax.- Returns:
- the matching for the syntax.
- Despite the value containing no commas, the syntax with a
-
shallowMatch
Verify whether this lexical unit matches the given grammar, ignoring further units in the lexical chain.This method is intended for use during shorthand decompositions, gradient processing, etc.
See also:
SyntaxParser,matches(CSSValueSyntax).- Parameters:
syntax- the syntax.- Returns:
- the matching for the syntax.
-
clone
LexicalUnit clone()Creates a deep copy of this lexical unit and the next ones, unlinked to any previous lexical unit.The clone's
getPreviousLexicalUnit()returnsnull(andisParameter()false) regardless of what the the original object returned.- Returns:
- a copy of this unit.
-
shallowClone
LexicalUnit shallowClone()Creates a shallow copy of this lexical unit, ignoring the next ones, and unlinked to any previous lexical unit.The shallow clone's
getPreviousLexicalUnit()andgetNextLexicalUnit()both returnnull(andisParameter()false) regardless of what the the original object returned.- Returns:
- a shallow copy of this unit.
-