java.lang.Object
org.jhotdraw8.css.ast.AbstractSyntaxTree
org.jhotdraw8.css.ast.Selector
org.jhotdraw8.css.ast.Combinator
org.jhotdraw8.css.ast.AdjacentSiblingCombinator
An "adjacent sibling combinator" matches an element if its first selector
matches on the adjacent sibling of the element and if its second selector
matches the element.
- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class org.jhotdraw8.css.ast.Combinator
first, second -
Constructor Summary
ConstructorsConstructorDescriptionAdjacentSiblingCombinator(@Nullable SourceLocator sourceLocator, SimpleSelector first, Selector second) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the specificity of this selector.<T> @Nullable Tmatch(SelectorModel<T> model, T element) Returns the matching element.@Nullable TypeSelectorThis selector matches only on a specific type, if its second selector matches only on a specific type.voidproduceTokens(Consumer<CssToken> consumer) Produces tokens for the subtree starting at this tree node.toString()Methods inherited from class org.jhotdraw8.css.ast.Combinator
equals, hashCodeMethods inherited from class org.jhotdraw8.css.ast.AbstractSyntaxTree
getSourceLocator
-
Constructor Details
-
AdjacentSiblingCombinator
public AdjacentSiblingCombinator(@Nullable SourceLocator sourceLocator, SimpleSelector first, Selector second) Creates a new instance.- Parameters:
sourceLocator-first- the first selectorsecond- the second selector
-
-
Method Details
-
toString
- Overrides:
toStringin classCombinator
-
match
Description copied from class:SelectorReturns the matching element. -
getSpecificity
public int getSpecificity()Description copied from class:SelectorReturns the specificity of this selector.A selector's specificity is calculated as follows:
- count the number of ID selectors in the selector (= a)
- count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
- count the number of type selectors and pseudo-elements in the selector (= c)
- ignore the universal selector
Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.
Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.
In this implementation we compute specificity with
specificity=100*a+10*b+c.References:
- CSS Syntax Selectors Level 3, Chapter 9. Calculating a selector's specificity
- w3.org
- Specified by:
getSpecificityin classSelector- Returns:
- the specificity
-
produceTokens
Description copied from class:AbstractSyntaxTreeProduces tokens for the subtree starting at this tree node.- Overrides:
produceTokensin classAbstractSyntaxTree- Parameters:
consumer- a consumer for the tokens
-
matchesOnlyOnASpecificType
This selector matches only on a specific type, if its second selector matches only on a specific type.- Overrides:
matchesOnlyOnASpecificTypein classSelector- Returns:
second.matchesOnlyOnASpecificType()
-