Class GeneralSiblingCombinator


public class GeneralSiblingCombinator extends Combinator
An "general sibling combinator" matches an element if its first selector matches the sibling of the element and if its second selector matches the element.
Author:
Werner Randelshofer
  • Constructor Details

  • Method Details

    • toString

      public @NonNull String toString()
      Overrides:
      toString in class Combinator
    • match

      public <T> @Nullable T match(@NonNull SelectorModel<T> model, T element)
      Description copied from class: Selector
      Returns the matching element.
      Specified by:
      match in class Selector
      Type Parameters:
      T - element type
      Parameters:
      model - The helper is used to access properties of the element and parent or sibling elements in the document.
      element - the element
      Returns:
      the matching element or null
    • getSpecificity

      public final int getSpecificity()
      Description copied from class: Selector
      Returns 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:
      getSpecificity in class Selector
      Returns:
      the specificity
    • produceTokens

      public void produceTokens(@NonNull Consumer<CssToken> consumer)
      Description copied from class: AbstractSyntaxTree
      Produces tokens for the subtree starting at this tree node.
      Overrides:
      produceTokens in class AbstractSyntaxTree
      Parameters:
      consumer - a consumer for the tokens
    • matchesOnlyOnASpecificType

      public @Nullable TypeSelector matchesOnlyOnASpecificType()
      This selector matches only on a specific type, if its second selector matches only on a specific type.
      Overrides:
      matchesOnlyOnASpecificType in class Selector
      Returns:
      second.matchesOnlyOnASpecificType()