Package dev.amp.validator.utils
Class SelectorUtils
- java.lang.Object
-
- dev.amp.validator.utils.SelectorUtils
-
public final class SelectorUtils extends Object
Methods to handle selector validation.- Author:
- nhant01, GeorgeLuo
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Combinator.CombinatorTypecombinatorTypeForToken(com.steadystate.css.parser.Token token)The CombinatorType for a given token; helper function used when constructing a Combinator instance.static List<com.steadystate.css.parser.Token>extractAFunction(TokenStream tokenStream, List<ErrorToken> errors)Returns a function's contents in tokenList, including the leading FunctionToken, but excluding the trailing CloseParen token and appended with an EOFToken instead.static booleanisDelim(com.steadystate.css.parser.Token token, String delimChar)Helper function for determining whether the provided token is a specific delimiter.static booleanisSimpleSelectorSequenceStart(com.steadystate.css.parser.Token token)Whether or not the provided token could be the start of a simple selector sequence.static AttrSelectorparseAnAttrSelector(TokenStream tokenStream)tokenStream.current() must be the open square token.static SelectorparseASelector(TokenStream tokenStream)The selector production from http://www.w3.org/TR/css3-selectors/#grammar Returns an ErrorToken if no selector is found.static SimpleSelectorSequenceparseASimpleSelectorSequence(TokenStream tokenStream)tokenStream.current must be the first token of the sequence.static TypeSelectorparseATypeSelector(TokenStream tokenStream)tokenStream.current() is the first token of the type selector.
-
-
-
Method Detail
-
isSimpleSelectorSequenceStart
public static boolean isSimpleSelectorSequenceStart(@Nonnull com.steadystate.css.parser.Token token)Whether or not the provided token could be the start of a simple selector sequence. See the simple_selector_sequence production in http://www.w3.org/TR/css3-selectors/#grammar.- Parameters:
token- to analyze- Returns:
- is SimpleSelector Sequence Start
-
isDelim
public static boolean isDelim(@Nonnull com.steadystate.css.parser.Token token, @Nonnull String delimChar)Helper function for determining whether the provided token is a specific delimiter.- Parameters:
token- to analyzedelimChar- to check- Returns:
- if this is a delim char
-
parseASimpleSelectorSequence
public static SimpleSelectorSequence parseASimpleSelectorSequence(@Nonnull TokenStream tokenStream) throws SelectorException, CssValidationException
tokenStream.current must be the first token of the sequence. This function will return an error if no selector is found.- Parameters:
tokenStream- token stream- Returns:
- the SimpleSelectorSequence instance
- Throws:
CssValidationException- the CssValidationExceptionSelectorException- the SelectorException
-
parseASelector
public static Selector parseASelector(@Nonnull TokenStream tokenStream) throws CssValidationException, SelectorException
The selector production from http://www.w3.org/TR/css3-selectors/#grammar Returns an ErrorToken if no selector is found.- Parameters:
tokenStream- token stream- Returns:
- the selector
- Throws:
CssValidationException- the CssValidationExceptionSelectorException- the SelectorException
-
combinatorTypeForToken
public static Combinator.CombinatorType combinatorTypeForToken(@Nonnull com.steadystate.css.parser.Token token) throws CssValidationException
The CombinatorType for a given token; helper function used when constructing a Combinator instance.- Parameters:
token- the token- Returns:
- the combinator type
- Throws:
CssValidationException- the CssValidationException
-
parseATypeSelector
public static TypeSelector parseATypeSelector(@Nonnull TokenStream tokenStream)
tokenStream.current() is the first token of the type selector.- Parameters:
tokenStream- token stream- Returns:
- the type selector
-
parseAnAttrSelector
public static AttrSelector parseAnAttrSelector(@Nonnull TokenStream tokenStream) throws SelectorException, CssValidationException
tokenStream.current() must be the open square token.- Parameters:
tokenStream- token stream- Returns:
- attribute selector
- Throws:
CssValidationException- the CssValidationExceptionSelectorException- the SelectorException
-
extractAFunction
public static List<com.steadystate.css.parser.Token> extractAFunction(@Nonnull TokenStream tokenStream, @Nonnull List<ErrorToken> errors) throws CssValidationException
Returns a function's contents in tokenList, including the leading FunctionToken, but excluding the trailing CloseParen token and appended with an EOFToken instead.- Parameters:
tokenStream- token streamerrors- array of error tokens- Returns:
- the list of token
- Throws:
CssValidationException- the CssValidationException
-
-