public abstract class Symbol
extends java.lang.Object
A resource type identifies the group or resource. Resources in Android can have various types:
drawables, strings, etc. The full list of supported resource types can be found in ResourceType.
The name of the symbol has to be a valid java identifier and is usually the file name of the
resource (without the extension) or the name of the resource if the resource is part of an XML
file. While names of resources declared in XML files can contain dots and colons, these should be
replaced by underscores before being passed to the constructor. To sanitize the resource name,
call SymbolUtils.canonicalizeValueResourceName(String) before passing the name to the
constructor.
For example, the resource drawable/foo.png has name foo. The string bar in file values/strings.xml with name bar has resource name bar.
The java type is the java data type that contains the resource value. This is generally int, but other values (such as int[]) are allowed. Type should not contain any
whitespaces, be null or empty.
The value is a java expression that conforms to the resource type and contains the value of
the resource. This may be just an integer like 3, if the resource has type int.
But may be a more complex expression. For example, if the resource has type int[], the
value may be something such as {1, 2, 3}.
In practice, symbols do not exist by themselves. They are usually part of a symbol table, but this class is independent of any use.
| Constructor and Description |
|---|
Symbol() |
| Modifier and Type | Method and Description |
|---|---|
static Symbol |
createSymbol(com.android.resources.ResourceType resourceType,
java.lang.String name,
SymbolJavaType javaType,
java.lang.String value)
Creates a new symbol.
|
abstract SymbolJavaType |
getJavaType()
Obtains the java type of the symbol.
|
abstract java.lang.String |
getName()
Obtains the name of the symbol.
|
abstract com.android.resources.ResourceType |
getResourceType()
Obtains the resource type.
|
abstract java.lang.String |
getValue()
Obtains the value of the symbol.
|
public static Symbol createSymbol(@NonNull com.android.resources.ResourceType resourceType, @NonNull java.lang.String name, @NonNull SymbolJavaType javaType, @NonNull java.lang.String value)
name of the symbol needs to be a valid sanitized resource
name. See SymbolUtils.canonicalizeValueResourceName(java.lang.String) method and apply it beforehand
when necessary.resourceType - the resource type of the symbolname - the sanitized name of the symboljavaType - the java type of the symbolvalue - the value of the symbol@NonNull public abstract com.android.resources.ResourceType getResourceType()
@NonNull public abstract java.lang.String getValue()
@NonNull public abstract java.lang.String getName()
@NonNull public abstract SymbolJavaType getJavaType()