public final class CssAnnotation extends Object
CSS comment annotations are CSS comments that contain an annotation in the format of "@annotationName [optionalArgs]", for example "@noparse", "@browser ie7", "@something arg1 arg2 arg3", etc...
There are methods to support various types of arg formats, including space-separated, comma-separated and enum-based. More
complex, custom formats can manually be parsed via the rawArgs()
method.
Syntax units are associated with the CSS comments that directly precede them. More than one CSS annotation comment is allowed. See the main readme for more information on comments.
Constructor and Description |
---|
CssAnnotation(String name)
Creates a new
CssAnnotation with the given name. |
CssAnnotation(String name,
String args)
Creates a new
CssAnnotation instance with the given name and arguments. |
Modifier and Type | Method and Description |
---|---|
com.google.common.collect.ImmutableList<String> |
commaSeparatedArgs()
Parses the arguments using commas as the delimiter.
|
boolean |
equals(Object object) |
<E extends Enum<E>> |
fromEnum(Class<E> enumClass)
Same as
fromEnum(Class, CaseFormat, CaseFormat) , except this method only works with enums that use
TITLE_CASE, and annotations that either use TITLE_CASE or lowerCamel. |
<E extends Enum<E>> |
fromEnum(Class<E> enumClass,
com.google.common.base.CaseFormat enumFormat,
com.google.common.base.CaseFormat annotationFormat)
Parses the arguments with allowed values from the given enum.
|
int |
hashCode() |
com.google.common.collect.ImmutableMap<String,String> |
keyValueArgs(char keyValueSeparator)
Parsers the arguments for key value pairs.
|
String |
name()
Gets the name of the annotation.
|
Optional<String> |
rawArgs()
Returns the raw, unprocessed args.
|
com.google.common.collect.ImmutableList<String> |
spaceSeparatedArgs()
Parses the arguments using spaces as the delimiter.
|
Comment |
toComment(boolean useCached)
Creates a new
Comment instance using this annotation as the content. |
String |
toString() |
public CssAnnotation(String name)
CssAnnotation
with the given name.name
- The annotation name.public CssAnnotation(String name, String args)
CssAnnotation
instance with the given name and arguments.name
- The name of the annotation.args
- Optional arguments (automatically trimmed).public String name()
public Optional<String> rawArgs()
public com.google.common.collect.ImmutableList<String> spaceSeparatedArgs()
For example, given the following css annotation:
@foo one two three four
The arguments returned will be a list with values "one", "two", "three", and "four".public com.google.common.collect.ImmutableList<String> commaSeparatedArgs()
For example, given the following css annotation:
@foo one, two, three, four
The arguments returned will be a list with values "one", "two", "three", and "four".public com.google.common.collect.ImmutableMap<String,String> keyValueArgs(char keyValueSeparator)
The key value pairs are separated by commas. For example, given any of the following css annotations:
@foo bar=baz, bim=bop, bip=beep
@foo bar = baz, bim = bop, bip = beep
@foo bar:baz, bim:bop, bip:beep
@foo bar baz, bim bop, bip beep
The arguments returned will be a map with values {"bar"="baz", "bim"="bop", "bip"="beep"}.
Optionally, the first arg may omit the key, and it will be placed in the map under "name". For example:
@foo bar, bim bop, bip beep
The arguments returned will be a map with values {"name"="bar", "bim"="bop", "bip"="boop"}keyValueSeparator
- The character separating key-value pairs, usually ' ', '=' or ':'. Spaces around this character are allowed.public <E extends Enum<E>> EnumSet<E> fromEnum(Class<E> enumClass)
fromEnum(Class, CaseFormat, CaseFormat)
, except this method only works with enums that use
TITLE_CASE, and annotations that either use TITLE_CASE or lowerCamel.E
- The enum type.enumClass
- The enum class.public <E extends Enum<E>> EnumSet<E> fromEnum(Class<E> enumClass, com.google.common.base.CaseFormat enumFormat, com.google.common.base.CaseFormat annotationFormat)
The values must be space-separated and any value not present in the enum will result in an error. For example, with the enum {ONE, TWO, THREE}, the following:
@foo one two
would return a map containing ONE and TWO.
The names must be an exact match, however they will be normalized using the given CaseFormats.
E
- The enum type.enumClass
- The enum class.enumFormat
- The format of the enum.annotationFormat
- The format used by the css annotations.IllegalArgumentException
- for annotation arguments without a matching enum entry.public Comment toComment(boolean useCached)
Comment
instance using this annotation as the content.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.