use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class PermissionRequirement method getAnnotationStringValues.
@Nullable
public static String[] getAnnotationStringValues(@Nullable UAnnotation annotation, @NonNull String name) {
if (annotation != null) {
UExpression attributeValue = annotation.findDeclaredAttributeValue(name);
if (attributeValue == null && ATTR_VALUE.equals(name)) {
attributeValue = annotation.findDeclaredAttributeValue(null);
}
if (attributeValue == null) {
return null;
}
if (UastExpressionUtils.isArrayInitializer(attributeValue)) {
List<UExpression> initializers = ((UCallExpression) attributeValue).getValueArguments();
List<String> result = Lists.newArrayListWithCapacity(initializers.size());
ConstantEvaluator constantEvaluator = new ConstantEvaluator(null);
for (UExpression element : initializers) {
Object o = constantEvaluator.evaluate(element);
if (o instanceof String) {
result.add((String) o);
}
}
if (result.isEmpty()) {
return null;
} else {
return result.toArray(new String[0]);
}
} else {
// Use constant evaluator since we want to resolve field references as well
Object o = ConstantEvaluator.evaluate(null, attributeValue);
if (o instanceof String) {
return new String[] { (String) o };
} else if (o instanceof String[]) {
return (String[]) o;
} else if (o instanceof Object[]) {
Object[] array = (Object[]) o;
List<String> strings = Lists.newArrayListWithCapacity(array.length);
for (Object element : array) {
if (element instanceof String) {
strings.add((String) element);
}
}
return strings.toArray(new String[0]);
}
}
}
return null;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class PrivateResourceDetector method getLibraryName.
/** Pick a suitable name to describe the library defining the private resource */
@Nullable
private static String getLibraryName(@NonNull Context context, @NonNull ResourceType type, @NonNull String name) {
ResourceVisibilityLookup lookup = context.getProject().getResourceVisibility();
AndroidLibrary library = lookup.getPrivateIn(type, name);
if (library != null) {
String libraryName = library.getProject();
if (libraryName != null) {
return libraryName;
}
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates != null) {
return coordinates.getGroupId() + ':' + coordinates.getArtifactId();
}
}
return "the library";
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class ApiLookup method get.
/**
* Returns an instance of the API database
*
* @param client the client to associate with this database - used only for
* logging. The database object may be shared among repeated invocations,
* and in that case client used will be the one originally passed in.
* In other words, this parameter may be ignored if the client created
* is not new.
* @return a (possibly shared) instance of the API database, or null
* if its data can't be found
*/
@Nullable
public static ApiLookup get(@NonNull LintClient client) {
synchronized (ApiLookup.class) {
ApiLookup db = sInstance.get();
if (db == null) {
File file = client.findResource(XML_FILE_PATH);
if (file == null) {
// AOSP build environment?
//$NON-NLS-1$
String build = System.getenv("ANDROID_BUILD_TOP");
if (build != null) {
file = new File(build, //$NON-NLS-1$
"development/sdk/api-versions.xml".replace('/', File.separatorChar));
}
}
if (file == null || !file.exists()) {
return null;
} else {
db = get(client, file);
}
sInstance = new WeakReference<ApiLookup>(db);
}
return db;
}
}
use of com.android.annotations.Nullable in project android by JetBrains.
the class LintIdeViewTypeDetector method getViewTags.
@Nullable
@Override
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
AbstractResourceRepository projectResources = context.getClient().getProjectResources(context.getMainProject(), true);
assert projectResources instanceof LocalResourceRepository : projectResources;
LocalResourceRepository repository = (LocalResourceRepository) projectResources;
String viewTag = repository.getViewTag(item);
if (viewTag != null) {
return Collections.singleton(viewTag);
}
return super.getViewTags(context, item);
}
use of com.android.annotations.Nullable in project android by JetBrains.
the class LintIdeJavaParser method getType.
@Nullable
@Override
public TypeDescriptor getType(@NonNull JavaContext context, @NonNull Node node) {
final PsiElement element = getPsiElement(node);
if (element == null) {
return null;
}
Application application = ApplicationManager.getApplication();
if (application.isReadAccessAllowed()) {
return getTypeDescriptor(element);
}
return application.runReadAction(new Computable<TypeDescriptor>() {
@Nullable
@Override
public TypeDescriptor compute() {
return getTypeDescriptor(element);
}
});
}
Aggregations