Class Selector

Direct Known Subclasses:
Combinator, SelectorGroup, SimpleSelector

public abstract class Selector extends AbstractSyntaxTree
A "selector" is a tree of "combinator"s.
Author:
Werner Randelshofer
  • Constructor Details

    • Selector

      public Selector(@Nullable SourceLocator sourceLocator)
  • Method Details

    • getSpecificity

      public abstract int getSpecificity()
      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
      Returns:
      the specificity
    • matches

      public <T> boolean matches(SelectorModel<T> model, T element)
      Returns true if the selector matches the element.
      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 abstract <T> @Nullable T match(SelectorModel<T> model, T element)
      Returns the matching element.
      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
    • matchesOnlyOnASpecificType

      public @Nullable TypeSelector matchesOnlyOnASpecificType()
      Returns a qualified name, if this selector only matches on elements with a specific type name.

      This implementation returns null.

      Returns:
      a type name or null