public class ResourceDirectoryParser
extends java.lang.Object
SymbolTable
. The
parser expects a resource directory that contains sub-directories with a name in the format
X(-Y)*
where X
is a pseudo resource type (see below) and Y
are
optional qualifiers. Inside each directory, only resource files should exist.
The pseudo resource type is either the resource type or the value values
. If
the first segment of the directory name is values
, files in the directory are treated as
resource XML values, parsed using ResourceValuesXmlParser
and the generated symbol tables
are merged to form the resulting one.
The qualifiers are irrelevant as far as the directory parser is concerned and are ignored.
One symbol will be generated per resource file, with the exception of resource files in the
values
directory and resources declared inside other XML files (e.g. "@+string/my_string"
declared inside layout/activity_name.xml
would generate a new Symbol of type String
and name my_string
).
For files the symbol's name is the resource file name with optional extension removed. The only characters allowed in the symbol's name are lowercase letters, digits and the underscore character.
For values declared inside XML files the symbol's name is the element's name
XML tag
value. Dots and colons are allowed, but deprecated and therefore support for them will end soon.
Subdirectories in the resource directories are ignored.
For testing purposes, it is guaranteed that the resource directories are processed by name
with all the values
directories being processed last. Inside each directory, files are
processed in alphabetical order. All symbols are assigned an ID, even if they are duplicated.
Duplicated symbols are not present in the final symbol table. So, if for example, the following
resources are defined drawable/a.png
, drawable-hdpi/a.png
and layout/b.xml
, two symbols will exist, drawable/a
and layout/b
with IDs 1
and 3
, respectively. This behavior, that ensures ID assignment is deterministic, should
not be relied upon except for testing.
Modifier and Type | Method and Description |
---|---|
static com.android.builder.symbols.SymbolTable |
parseDirectory(java.io.File directory,
IdProvider idProvider,
com.android.builder.symbols.SymbolTable platformAttrSymbols)
Parses a resource directory.
|
@NonNull public static com.android.builder.symbols.SymbolTable parseDirectory(@NonNull java.io.File directory, @NonNull IdProvider idProvider, @NonNull com.android.builder.symbols.SymbolTable platformAttrSymbols) throws ResourceDirectoryParseException
directory
- the directory to parse, must be an existing directoryidProvider
- the provider of IDs for the resourcesResourceDirectoryParseException
- failed to parse the resource directory