java.lang.Object
org.jhotdraw8.css.ast.AbstractSyntaxTree
org.jhotdraw8.css.ast.Selector
org.jhotdraw8.css.ast.SimpleSelector
org.jhotdraw8.css.ast.TypeSelector
A "type selector" matches an element if the element has a specific type.
- Author:
- Werner Randelshofer
-
Field Summary
FieldsModifier and TypeFieldDescriptionSpecial namespace value which means 'any namespace'.Special namespace value which means 'without a namespace'. -
Constructor Summary
ConstructorsConstructorDescriptionTypeSelector(@Nullable SourceLocator sourceLocator, @Nullable String namespacePattern, @NonNull String type) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionbooleanintReturns the specificity of this selector.getType()inthashCode()<T> @Nullable Tmatch(@NonNull SelectorModel<T> model, @Nullable T element) Returns the matching element.Returns a qualified name, if this selector only matches on elements with a specific type name.voidproduceTokens(@NonNull Consumer<CssToken> consumer) Produces tokens for the subtree starting at this tree node.toString()Methods inherited from class org.jhotdraw8.css.ast.AbstractSyntaxTree
getSourceLocator
-
Field Details
-
ANY_NAMESPACE
Special namespace value which means 'any namespace'.Value: "*"
- See Also:
-
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 debuggingnamespacePattern- an optional namespace ("*" means any namespace, null means no namespace)type- the type name
-
-
Method Details
-
toString
-
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
-
equals
-
hashCode
public int hashCode() -
getNamespacePattern
-
getType
-
matchesOnlyOnASpecificType
Description copied from class:SelectorReturns a qualified name, if this selector only matches on elements with a specific type name.This implementation returns null.
- Overrides:
matchesOnlyOnASpecificTypein classSelector- Returns:
- a type name or null
-