Class TypeSelector


public class TypeSelector extends SimpleSelector
A "type selector" matches an element if the element has a specific type.
Author:
Werner Randelshofer
  • Field Details

    • ANY_NAMESPACE

      public static final @NonNull String ANY_NAMESPACE
      Special namespace value which means 'any namespace'.

      Value: "*"

      See Also:
    • WITHOUT_NAMESPACE

      public static final @Nullable String WITHOUT_NAMESPACE
      Special namespace value which means 'without a namespace'.

      See XML Namespaces.

      Value: null

  • Constructor Details

    • TypeSelector

      public TypeSelector(@Nullable SourceLocator sourceLocator, @Nullable String namespacePattern, @NonNull String type)
      Creates a new instance
      Parameters:
      sourceLocator - source locator for debugging
      namespacePattern - an optional namespace ("*" means any namespace, null means no namespace)
      type - the type name
  • Method Details

    • toString

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

      public <T> @Nullable T match(@NonNull SelectorModel<T> model, @Nullable 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 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
    • equals

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

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

      public @Nullable String getNamespacePattern()
    • getType

      public @NonNull String getType()
    • matchesOnlyOnASpecificType

      public @Nullable TypeSelector matchesOnlyOnASpecificType()
      Description copied from class: Selector
      Returns a qualified name, if this selector only matches on elements with a specific type name.

      This implementation returns null.

      Overrides:
      matchesOnlyOnASpecificType in class Selector
      Returns:
      a type name or null