Class SelectorGroup


public class SelectorGroup extends Selector
A "selector group" matches an element if one of its selectors matches the element.
Author:
Werner Randelshofer
  • Constructor Details

  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getSpecificity

      public 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
    • matches

      public <T> boolean matches(SelectorModel<T> model, T element)
      Returns true if the rule matches the element.
      Overrides:
      matches in class Selector
      Type Parameters:
      T - the 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:
      true on match
    • match

      protected <T> @Nullable T match(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
    • matchSelector

      public <T> @Nullable Selector matchSelector(SelectorModel<T> model, T element)
      Returns the last selector with highest specificity that matches the specified element or null.

      If multiple selectors match, then this method returns the selector with the highest specificity value.

      If multiple matching selectors have the highest specificity, then this method returns the last one.

      Type Parameters:
      T - the 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 last selector with highest specificity that matches the specified element, returns null if no selector matches
    • produceTokens

      public void produceTokens(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
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • matchesOnlyOnASpecificType

      public @Nullable TypeSelector matchesOnlyOnASpecificType()
      This selector matches only on a specific type, if all its selectors match on the same type.
      Overrides:
      matchesOnlyOnASpecificType in class Selector
      Returns:
      a type name or null