use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class UastLintUtils method toAndroidReference.
@Nullable
private static AndroidReference toAndroidReference(UQualifiedReferenceExpression expression) {
List<String> path = UastUtils.asQualifiedPath(expression);
String packageNameFromResolved = null;
PsiClass containingClass = UastUtils.getContainingClass(expression.resolve());
if (containingClass != null) {
String containingClassFqName = containingClass.getQualifiedName();
if (containingClassFqName != null) {
int i = containingClassFqName.lastIndexOf(".R.");
if (i >= 0) {
packageNameFromResolved = containingClassFqName.substring(0, i);
}
}
}
if (path == null) {
return null;
}
int size = path.size();
if (size < 3) {
return null;
}
String r = path.get(size - 3);
if (!r.equals(SdkConstants.R_CLASS)) {
return null;
}
String packageName = packageNameFromResolved != null ? packageNameFromResolved : Joiner.on('.').join(path.subList(0, size - 3));
String type = path.get(size - 2);
String name = path.get(size - 1);
ResourceType resourceType = null;
for (ResourceType value : ResourceType.values()) {
if (value.getName().equals(type)) {
resourceType = value;
break;
}
}
if (resourceType == null) {
return null;
}
return new AndroidReference(expression, packageName, resourceType, name);
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class ViewTypeDetector method getViewTags.
@Nullable
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
// Check view tag in this file. Can I do it cheaply? Try with
// an XML pull parser. Or DOM if we have multiple resources looked
// up?
ResourceFile source = item.getSource();
if (source != null) {
File file = source.getFile();
Multimap<String, String> map = getIdToTagsIn(context, file);
if (map != null) {
return map.get(item.getName());
}
}
return null;
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class IntellijLintUtils method getPsiFile.
/**
* Returns the {@link PsiFile} associated with a given lint {@link Context}
*
* @param context the context to look up the file for
* @return the corresponding {@link PsiFile}, or null
*/
@Nullable
public static PsiFile getPsiFile(@NonNull Context context) {
VirtualFile file = VfsUtil.findFileByIoFile(context.file, false);
if (file == null) {
return null;
}
LintRequest request = context.getDriver().getRequest();
Project project = ((IntellijLintRequest) request).getProject();
if (project.isDisposed()) {
return null;
}
return AndroidPsiUtils.getPsiFileSafely(project, file);
}
use of com.android.annotations.Nullable in project kotlin by JetBrains.
the class IntellijViewTypeDetector 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 kotlin by JetBrains.
the class TypoLookup method get.
/**
* Returns an instance of the typo database
*
* @param client the client to associate with this database - used only for
* logging
* @param xmlFile the XML file containing configuration data to use for this
* database
* @return a (possibly shared) instance of the typo database, or null
* if its data can't be found
*/
@Nullable
private static TypoLookup get(LintClient client, File xmlFile) {
if (!xmlFile.exists()) {
client.log(null, "The typo database file %1$s does not exist", xmlFile);
return null;
}
String name = xmlFile.getName();
if (LintUtils.endsWith(name, DOT_XML)) {
name = name.substring(0, name.length() - DOT_XML.length());
}
File cacheDir = client.getCacheDir(true);
if (cacheDir == null) {
cacheDir = xmlFile.getParentFile();
}
File binaryData = new File(cacheDir, name + // conflicts on Windows (such as issue #26663)
'-' + BINARY_FORMAT_VERSION + //$NON-NLS-1$
".bin");
if (DEBUG_FORCE_REGENERATE_BINARY) {
System.err.println("\nTemporarily regenerating binary data unconditionally \nfrom " + xmlFile + "\nto " + binaryData);
if (!createCache(client, xmlFile, binaryData)) {
return null;
}
} else if (!binaryData.exists() || binaryData.lastModified() < xmlFile.lastModified()) {
if (!createCache(client, xmlFile, binaryData)) {
return null;
}
}
if (!binaryData.exists()) {
client.log(null, "The typo database file %1$s does not exist", binaryData);
return null;
}
return new TypoLookup(client, xmlFile, binaryData);
}
Aggregations