use of com.android.tools.lint.checks.ApiLookup in project android by JetBrains.
the class ResolutionUtils method getOriginalApiLevel.
/**
* Returns the Api level at which was defined the attribute or value with the name passed as argument.
* Returns -1 if the name argument is null or not the name of a framework attribute or resource,
* or if it is the name of a framework attribute or resource defined in API 1, or if no Lint client found.
*/
public static int getOriginalApiLevel(@Nullable String name, @NotNull Project project) {
if (name == null) {
return -1;
}
ApiLookup apiLookup = LintIdeClient.getApiLookup(project);
if (apiLookup == null) {
// There is no Lint API database for this project
LOG.warn("Could not find Lint client for project " + project.getName());
return -1;
}
ResourceUrl resUrl = ResourceUrl.parse(name);
if (resUrl == null) {
// It is an attribute
if (!name.startsWith(ANDROID_NS_NAME_PREFIX)) {
// not an android attribute
return -1;
}
return apiLookup.getFieldVersion("android/R$attr", name.substring(ANDROID_NS_NAME_PREFIX_LEN));
} else {
if (!resUrl.framework) {
// not an android value
return -1;
}
return apiLookup.getFieldVersion("android/R$" + resUrl.type, AndroidResourceUtil.getFieldNameByResourceName(resUrl.name));
}
}
Aggregations